Open Journal Systems  3.3.0
SortTest.php
1 <?php
2 /*
3  * citeproc-php
4  *
5  * @link http://github.com/seboettg/citeproc-php for the source repository
6  * @copyright Copyright (c) 2016 Sebastian Böttger.
7  * @license https://opensource.org/licenses/MIT
8  */
9 
11 
12 use PHPUnit\Framework\TestCase;
15 
16 class SortTest extends TestCase
17 {
19 
20  public function testSortVariable()
21  {
22  $xml = "<style><bibliography><sort><key variable=\"author\"/></sort><layout><names variable=\"author\"><name/></names><text prefix=\", \" variable=\"title\"/></layout></bibliography></style>";
23 
24  $json = "[
25  {
26  \"title\": \"Book 1\",
27  \"author\": [
28  {
29  \"family\": \"Roe\",
30  \"given\": \"Jane\"
31  }
32  ],
33  \"id\": \"ITEM-1\",
34  \"type\": \"book\"
35  },
36  {
37  \"title\": \"Book 2\",
38  \"author\": [
39  {
40  \"family\": \"Doe\",
41  \"given\": \"John\"
42  }
43  ],
44  \"id\": \"ITEM-2\",
45  \"type\": \"book\"
46  },
47  {
48  \"title\": \"Book 3\",
49  \"author\": [
50  {
51  \"family\": \"Flinders\",
52  \"given\": \"Jacob\"
53  }
54  ],
55  \"id\": \"ITEM-3\",
56  \"type\": \"book\"
57  }
58  ]";
59  $jsonObject = json_decode($json);
60  $citeProc = new CiteProc($xml, "en-US");
61  $result = $citeProc->render($jsonObject);
62 
63  $expected = "<div class=\"csl-bib-body\">
64  <div class=\"csl-entry\">John Doe, Book 2</div>
65  <div class=\"csl-entry\">Jacob Flinders, Book 3</div>
66  <div class=\"csl-entry\">Jane Roe, Book 1</div>
67 </div>";
68 
69  $this->assertEquals($expected, $result);
70  }
71 
72 
73  public function testSortVariableWithTwoKeys()
74  {
75  $xml = "<style><bibliography><sort><key variable=\"issued\" sort=\"descending\"/><key variable=\"author\"/></sort><layout><names variable=\"author\"><name/></names><text prefix=\", \" variable=\"title\"/><date prefix=\" (\" suffix=\").\" variable=\"issued\" date-parts=\"year\" /></layout></bibliography></style>";
76 
77  $json = "[
78  {
79  \"title\": \"Book 3\",
80  \"author\": [
81  {
82  \"family\": \"Zeppelin\",
83  \"given\": \"Graf\"
84  }
85  ],
86  \"issued\": {\"date-parts\":[[\"2000\"]]},
87  \"id\": \"ITEM-3\",
88  \"type\": \"book\"
89  },
90  {
91  \"title\": \"Book 4\",
92  \"author\": [
93  {
94  \"family\": \"Anderson\",
95  \"given\": \"Jakob\"
96  }
97  ],
98  \"issued\": {\"date-parts\":[[\"2003\"]]},
99  \"id\": \"ITEM-4\",
100  \"type\": \"book\"
101  },
102  {
103  \"title\": \"Book 1\",
104  \"author\": [
105  {
106  \"family\": \"Roe\",
107  \"given\": \"Jane\"
108  }
109  ],
110  \"issued\": {\"date-parts\":[[\"2003\"]]},
111  \"id\": \"ITEM-1\",
112  \"type\": \"book\"
113 
114  },
115  {
116  \"title\": \"Book 2\",
117  \"author\": [
118  {
119  \"family\": \"Doe\",
120  \"given\": \"John\"
121  }
122  ],
123  \"issued\": {\"date-parts\":[[\"2003\"]]},
124  \"id\": \"ITEM-2\",
125  \"type\": \"book\"
126  }
127  ]";
128 
129  $jsonObject = json_decode($json);
130  $citeProc = new CiteProc($xml, "en-US");
131  $result = $citeProc->render($jsonObject);
132 
133  $expected = "<div class=\"csl-bib-body\">
134  <div class=\"csl-entry\">Jakob Anderson, Book 4 (2003).</div>
135  <div class=\"csl-entry\">John Doe, Book 2 (2003).</div>
136  <div class=\"csl-entry\">Jane Roe, Book 1 (2003).</div>
137  <div class=\"csl-entry\">Graf Zeppelin, Book 3 (2000).</div>
138 </div>";
139 
140  $this->assertEquals($expected, $result);
141  }
142 
143 
145  {
146  $this->_testRenderTestSuite("sort_CaseInsensitiveBibliography");
147  }
148 
150  {
151  $this->_testRenderTestSuite("sort_BibliographyCitationNumberDescending.json");
152  }
153 
155  {
156  $this->_testRenderTestSuite("sort_BibliographyCitationNumberDescendingViaMacro");
157  }
158 
160  {
161  $this->_testRenderTestSuite("sort_CaseInsensitiveCitation");
162  }
163 
164  public function testSortCitation()
165  {
166  $this->_testRenderTestSuite("sort_Citation.json");
167  }
168 
169  /*
170  public function testSortConditionalMacroDates()
171  {
172  $this->_testRenderTestSuite("sort_ConditionalMacroDates");
173  }
174  */
175 
176  public function testSortDateVariable()
177  {
178  $this->_testRenderTestSuite("sort_DateVariable.json");
179  }
180 
182  {
183  $this->_testRenderTestSuite("sort_DateVariableMixedElements");
184  }
185 
186  public function testSortDateVariableRange()
187  {
188  $this->_testRenderTestSuite("sort_DateVariableRange.json");
189  }
190 
191 
193  {
194  $this->_testRenderTestSuite("sort_DateVariableRangeMixed");
195  }
196 
197 
198  public function testSortEtAlUseLast()
199  {
200  $this->_testRenderTestSuite("sort_EtAlUseLast");
201  }
202 
203 
204  public function testSortStripMarkup()
205  {
206  $this->_testRenderTestSuite("sort_StripMarkup");
207  }
208 
209  public function testSortSubstituteTitle()
210  {
211  $this->_testRenderTestSuite("sort_SubstituteTitle");
212  }
213 
214  public function testSortVariousNameMacros1()
215  {
216  $this->_testRenderTestSuite("sort_VariousNameMacros1");
217  }
218 
219  public function testSortVariousNameMacros2()
220  {
221  $this->_testRenderTestSuite("sort_VariousNameMacros2");
222  }
223 
224  public function testSortVariousNameMacros3()
225  {
226  $this->_testRenderTestSuite("sort_VariousNameMacros3");
227  }
228 
230  {
231  $this->_testRenderTestSuite("sort_DateMacroSortWithSecondFieldAlign");
232  }
233 }
Seboettg\CiteProc\TestSuiteTestCaseTrait
trait TestSuiteTestCaseTrait
Definition: TestSuiteTestCaseTrait.php:17
Seboettg\CiteProc\Style\Sort\SortTest\testSortVariousNameMacros2
testSortVariousNameMacros2()
Definition: SortTest.php:219
Seboettg\CiteProc\Style\Sort\SortTest\testSortDateMacroSortWithSecondFieldAlign
testSortDateMacroSortWithSecondFieldAlign()
Definition: SortTest.php:229
Seboettg\CiteProc\Style\Sort\SortTest\testSortVariableWithTwoKeys
testSortVariableWithTwoKeys()
Definition: SortTest.php:73
Seboettg\CiteProc\Style\Sort\SortTest\testSortSubstituteTitle
testSortSubstituteTitle()
Definition: SortTest.php:209
Seboettg\CiteProc\Style\Sort\SortTest\testSortVariousNameMacros1
testSortVariousNameMacros1()
Definition: SortTest.php:214
Seboettg\CiteProc\Style\Sort\SortTest\testSortVariable
testSortVariable()
Definition: SortTest.php:20
Seboettg\CiteProc\Style\Sort\SortTest\testSortDateVariableMixedElements
testSortDateVariableMixedElements()
Definition: SortTest.php:181
Seboettg\CiteProc\Style\Sort\SortTest\testSortCaseInsensitiveCitation
testSortCaseInsensitiveCitation()
Definition: SortTest.php:159
Seboettg\CiteProc\Style\Sort\SortTest\testSortVariousNameMacros3
testSortVariousNameMacros3()
Definition: SortTest.php:224
Seboettg\CiteProc\Style\Sort\SortTest\testSortDateVariableRange
testSortDateVariableRange()
Definition: SortTest.php:186
Seboettg\CiteProc\_testRenderTestSuite
_testRenderTestSuite($filterTests, $ignore=null)
Definition: TestSuiteTestCaseTrait.php:27
Seboettg\CiteProc\Style\Sort\SortTest
Definition: SortTest.php:16
Seboettg\CiteProc\Style\Sort\SortTest\testSortDateVariable
testSortDateVariable()
Definition: SortTest.php:176
Seboettg\CiteProc\CiteProc
Definition: CiteProc.php:32
Seboettg\CiteProc\Style\Sort\SortTest\testSortDateVariableRangeMixed
testSortDateVariableRangeMixed()
Definition: SortTest.php:192
Seboettg\CiteProc\Style\Sort\SortTest\testSortCaseInsensitiveBibliography
testSortCaseInsensitiveBibliography()
Definition: SortTest.php:144
Seboettg\CiteProc\Style\Sort\SortTest\testSortEtAlUseLast
testSortEtAlUseLast()
Definition: SortTest.php:198
Seboettg\CiteProc\Style\Sort\SortTest\testSortBibliographyCitationNumberDescending
testSortBibliographyCitationNumberDescending()
Definition: SortTest.php:149
Seboettg\CiteProc\Style\Sort\SortTest\testSortStripMarkup
testSortStripMarkup()
Definition: SortTest.php:204
Seboettg\CiteProc\Style\Sort\SortTest\testSortBibliographyCitationNumberDescendingViaMacro
testSortBibliographyCitationNumberDescendingViaMacro()
Definition: SortTest.php:154
Seboettg\CiteProc\Style\Sort\SortTest\testSortCitation
testSortCitation()
Definition: SortTest.php:164
Seboettg\CiteProc\Style\Sort
Definition: Key.php:10