ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
BibTexTest.php
Go to the documentation of this file.
1 <?php
2 // Call Structures_BibTexTest::main() if this source file is executed directly.
3 if (! defined("PHPUnit_MAIN_METHOD")) {
4  define("PHPUnit_MAIN_METHOD", "BibTexTest::main");
5 }
6 
7 require_once "PHPUnit/Framework/TestCase.php";
8 require_once "PHPUnit/Framework/TestSuite.php";
9 
10 // You may remove the following line when all tests have been implemented.
11 require_once "PHPUnit/Framework/IncompleteTestError.php";
12 
13 require_once "Structures/BibTex.php";
14 require_once "PEAR.php";
15 
21 
22  var $obj;
23 
24 
31  public static function main() {
32  require_once "PHPUnit/TextUI/TestRunner.php";
33  $suite = new PHPUnit_Framework_TestSuite("Structures_BibTexTest");
34  $result = PHPUnit_TextUI_TestRunner::run($suite);
35  }
36 
37 
44  protected function setUp() {
45  $this->obj = new Structures_BibTex();
46  }
47 
48 
55  protected function tearDown() {
56  unset($this->obj);
57  }
58 
59 
60  public function testLoadFileFileExists() {
61  $ret = $this->obj->loadFile("BibTexTest.php");
62  $this->content = ''; //Erasing the loaded content again because it is senseless
63  $this->assertTrue($ret);
64  }
65 
66 
67  public function testLoadFileFileDoesNotExists() {
68  $ret = $this->obj->loadFile((string)time());
69  $this->assertTrue(PEAR::isError($ret));
70  }
71 
72 
76  public function test_parseEntry() {
77  //Remember here that there is no closing brace!
78  $test = "@foo{bar,john=doe";
79  $shouldbe = array();
80  $shouldbe['john'] = 'doe';
81  $shouldbe['cite'] = 'bar';
82  $shouldbe['entryType'] = 'foo';
83  $this->assertEquals($shouldbe, $this->obj->_parseEntry($test));
84  }
85 
86 
87  public function test_checkEqualSignTrue() {
88  $test = "={=}";
89  $this->assertTrue($this->obj->_checkEqualSign($test, 0));
90  }
91 
92 
93  public function test_checkEqualSignFalse() {
94  $test = "={=}";
95  $this->assertFalse($this->obj->_checkEqualSign($test, 2));
96  }
97 
98 
99  public function testClearWarnings() {
100  $this->obj->clearWarnings();
101  $this->obj->_generateWarning('type', 'entry');
102  $this->obj->clearWarnings();
103  $this->assertFalse($this->obj->hasWarning());
104  }
105 
106 
107  /*
108  * the next tests check for the generation of the following Warnings:
109  * - WARNING_AT_IN_BRACES
110  * - WARNING_ESCAPED_DOUBLE_QUOTE_INSIDE_DOUBLE_QUOTES
111  * - WARNING_UNBALANCED_AMOUNT_OF_BRACES
112  */
114  $this->obj->clearWarnings();
115  $test = '{john@doe}';
116  $this->obj->_validateValue($test, '');
117  $this->assertEquals('WARNING_AT_IN_BRACES', $this->obj->warnings[0]['warning']);
118  }
119 
120 
122  $this->obj->clearWarnings();
123  $test = '"john\"doe"';
124  $this->obj->_validateValue($test, '');
125  $this->assertEquals('WARNING_ESCAPED_DOUBLE_QUOTE_INSIDE_DOUBLE_QUOTES', $this->obj->warnings[0]['warning']);
126  }
127 
128 
130  $this->obj->clearWarnings();
131  $test = '{john{doe}';
132  $this->obj->_validateValue($test, '');
133  $this->assertEquals('WARNING_UNBALANCED_AMOUNT_OF_BRACES', $this->obj->warnings[0]['warning']);
134  }
135 
136 
138  $this->obj->clearWarnings();
139  $test = '{john}doe}';
140  $this->obj->_validateValue($test, '');
141  $this->assertEquals('WARNING_UNBALANCED_AMOUNT_OF_BRACES', $this->obj->warnings[0]['warning']);
142  }
143 
144 
145  public function test_generateWarning() {
146  $this->obj->clearWarnings();
147  $this->obj->_generateWarning('type', 'entry');
148  $ret = $this->obj->hasWarning();
149  $this->obj->clearWarnings();
150  $this->assertTrue($ret);
151  }
152 
153 
154  public function testHasWarning() {
155  $this->obj->clearWarnings();
156  $this->assertFalse($this->obj->hasWarning());
157  }
158 
159 
160  public function testAmount() {
161  $teststring = "@Article {art1,author = {John Doe and Jane Doe}}@Article { art2,author = {John Doe and Jane Doe}}";
162  $this->obj->content = $teststring;
163  $this->obj->parse();
164  $this->assertEquals(2, $this->obj->amount());
165  }
166 
167 
168  public function testGetStatistic() {
169  $teststring = "@Article {art1,author = {John Doe and Jane Doe}}@Article { art2,author = {John Doe and Jane Doe}}";
170  $this->obj->content = $teststring;
171  $this->obj->parse();
172  $shouldbe = array();
173  $shouldbe['article'] = 2;
174  $this->assertEquals($shouldbe, $this->obj->getStatistic());
175  }
176 
177 
178  function testSingleParse() {
179  $teststring = "@Article { ppm_jon:1991,
180 author = {John Doe and Jane Doe}
181 }";
182  $this->obj->content = $teststring;
183  $this->obj->parse();
184  $this->assertEquals(1, $this->obj->amount());
185  }
186 
187 
188  function testMultiParse() {
189  $teststring = "@Article { art1,
190 author = {John Doe and Jane Doe}
191 }
192 @Article { art2,
193 author = {John Doe and Jane Doe}
194 }";
195  $this->obj->content = $teststring;
196  $this->obj->parse();
197  $this->assertEquals(2, $this->obj->amount());
198  }
199 
200 
201  function testParse() {
202  $teststring = "@Article { art1,
203 title = {Titel1},
204 author = {John Doe and Jane Doe}
205 }";
206  $shouldbe = array();
207  $shouldbe[0]['entryType'] = 'article';
208  $shouldbe[0]['cite'] = 'art1';
209  $shouldbe[0]['title'] = 'Titel1';
210  $shouldbe[0]['author'][0]['first'] = 'John';
211  $shouldbe[0]['author'][0]['von'] = '';
212  $shouldbe[0]['author'][0]['last'] = 'Doe';
213  $shouldbe[0]['author'][0]['jr'] = '';
214  $shouldbe[0]['author'][1]['first'] = 'Jane';
215  $shouldbe[0]['author'][1]['von'] = '';
216  $shouldbe[0]['author'][1]['last'] = 'Doe';
217  $shouldbe[0]['author'][1]['jr'] = '';
218  $this->obj->content = $teststring;
219  $this->obj->parse();
220  $this->assertEquals($shouldbe, $this->obj->data);
221  }
222 
223 
224  function testBibTex() {
225  $testarray = array();
226  $testarray[0]['entryType'] = 'Article';
227  $testarray[0]['cite'] = 'art1';
228  $testarray[0]['title'] = 'Titel1';
229  $testarray[0]['author'][0]['first'] = 'John';
230  $testarray[0]['author'][0]['von'] = '';
231  $testarray[0]['author'][0]['last'] = 'Doe';
232  $testarray[0]['author'][0]['jr'] = '';
233  $testarray[0]['author'][1]['first'] = 'Jane';
234  $testarray[0]['author'][1]['von'] = '';
235  $testarray[0]['author'][1]['last'] = 'Doe';
236  $testarray[0]['author'][1]['jr'] = '';
237  $shouldbe = "@article { art1,\n\ttitle = {Titel1},\n\tauthor = {Doe, , John and Doe, , Jane}\n}";
238  $this->obj->data = $testarray;
239  $this->assertEquals(trim($shouldbe), trim($this->obj->bibTex()));
240  }
241 
242 
243  function testAddEntry() {
244  $addarray = array();
245  $addarray['type'] = 'Article';
246  $addarray['cite'] = 'art2';
247  $addarray['title'] = 'Titel2';
248  $addarray['author'][0] = 'John Doe';
249  $addarray['author'][1] = 'Jane Doe';
250  $teststring = "@Article { art1,
251 title = {Titel1},
252 author = {John Doe and Jane Doe}
253 }";
254  $this->obj->content = $teststring;
255  $this->obj->parse();
256  $this->obj->addEntry($addarray);
257  $this->assertEquals(2, $this->obj->amount());
258  }
259 
260 
262  //Entry found at http://en.wikipedia.org/wiki/BibTeX
263  $teststring = "@Book{abramowitz+stegun,
264  author = \"Milton Abramowitz and Irene A. Stegun\",
265  title = \"Handbook of Mathematical Functions with
266  Formulas, Graphs, and Mathematical Tables\",
267  publisher = \"Dover\",
268  year = 1964,
269  address = \"New York\",
270  edition = \"ninth Dover printing, tenth GPO printing\",
271  isbn = \"0-486-61272-4\"
272 }";
273  $shouldbe = array();
274  $shouldbe[0]['entryType'] = 'book';
275  $shouldbe[0]['cite'] = 'abramowitz+stegun';
276  $shouldbe[0]['title'] = "Handbook of Mathematical Functions with
277  Formulas, Graphs, and Mathematical Tables";
278  $shouldbe[0]['author'][0]['first'] = 'Milton';
279  $shouldbe[0]['author'][0]['von'] = '';
280  $shouldbe[0]['author'][0]['last'] = 'Abramowitz';
281  $shouldbe[0]['author'][0]['jr'] = '';
282  $shouldbe[0]['author'][1]['first'] = 'Irene A.';
283  $shouldbe[0]['author'][1]['von'] = '';
284  $shouldbe[0]['author'][1]['last'] = 'Stegun';
285  $shouldbe[0]['author'][1]['jr'] = '';
286  $shouldbe[0]['publisher'] = 'Dover';
287  $shouldbe[0]['year'] = '1964';
288  $shouldbe[0]['address'] = 'New York';
289  $shouldbe[0]['edition'] = 'ninth Dover printing, tenth GPO printing';
290  $shouldbe[0]['isbn'] = '0-486-61272-4';
291  $this->obj->content = $teststring;
292  $this->obj->parse();
293  $this->assertEquals($shouldbe, $this->obj->data);
294  }
295 
296 
297  function testParsingComment() {
298  $teststring = "@Article { art1,
299 title = {Titel1},
300 author = {John Doe and Jane Doe}
301 }
302 Here is a comment
303 @Article { art2,
304 title = {Titel2},
305 author = {John Doe and Jane Doe}
306 }";
307  $shouldbe = array();
308  $shouldbe[0]['entryType'] = 'article';
309  $shouldbe[0]['cite'] = 'art1';
310  $shouldbe[0]['title'] = 'Titel1';
311  $shouldbe[0]['author'][0]['first'] = 'John';
312  $shouldbe[0]['author'][0]['von'] = '';
313  $shouldbe[0]['author'][0]['last'] = 'Doe';
314  $shouldbe[0]['author'][0]['jr'] = '';
315  $shouldbe[0]['author'][1]['first'] = 'Jane';
316  $shouldbe[0]['author'][1]['von'] = '';
317  $shouldbe[0]['author'][1]['last'] = 'Doe';
318  $shouldbe[0]['author'][1]['jr'] = '';
319  $shouldbe[1]['entryType'] = 'article';
320  $shouldbe[1]['cite'] = 'art2';
321  $shouldbe[1]['title'] = 'Titel2';
322  $shouldbe[1]['author'][0]['first'] = 'John';
323  $shouldbe[1]['author'][0]['von'] = '';
324  $shouldbe[1]['author'][0]['last'] = 'Doe';
325  $shouldbe[1]['author'][0]['jr'] = '';
326  $shouldbe[1]['author'][1]['first'] = 'Jane';
327  $shouldbe[1]['author'][1]['von'] = '';
328  $shouldbe[1]['author'][1]['last'] = 'Doe';
329  $shouldbe[1]['author'][1]['jr'] = '';
330  $this->obj->content = $teststring;
331  $this->obj->parse();
332  $this->assertTrue($this->obj->data == $shouldbe);
333  }
334 
335 
336  /*
337  function testWrongBraces1() {
338  $teststring = "@Article { art1,
339  title = {Tit}el1},
340  author = {John Doe and Jane Doe}
341  }";
342  $this->obj->content = $teststring;
343  $this->assertTrue(PEAR::isError($this->obj->parse()));
344  }
345 
346  function testWrongBraces2() {
347  $teststring = "@Article { art1,
348  title = {Titel1},
349  author = {John Doe and }Jane }Doe}
350  }";
351  $this->obj->content = $teststring;
352  $this->assertTrue(PEAR::isError($this->obj->parse()));
353  }
354  */
355  function testWrongBraces3() {
356  $teststring = "@Article { art1,
357 title = {Titel1},
358 author = {John {Doe and {Jane Doe}
359 }";
360  $this->obj->content = $teststring;
361  $this->assertTrue(PEAR::isError($this->obj->parse()));
362  }
363 
364 
366  $teststring = "@Article { art1,
367 title = {Titel1},
368 author = {John Doe and @Jane Doe}
369 }";
370  $this->obj->content = $teststring;
371  $this->obj->parse();
372  $this->assertTrue('WARNING_AT_IN_BRACES' == $this->obj->warnings[0]['warning']);
373  }
374 
375 
377  $teststring = "@Article { art1,
378 title = {Titel1},
379 author = \"John Doe and \\\"Jane Doe\"
380 }";
381  $this->obj->content = $teststring;
382  $this->obj->parse();
383  $this->assertTrue('WARNING_ESCAPED_DOUBLE_QUOTE_INSIDE_DOUBLE_QUOTES' == $this->obj->warnings[0]['warning']);
384  }
385 
386 
387  /*
388  function testWarningAmountBraces() {
389  $teststring = "@Article { art1,
390  title = {Tit{el1},
391  author = {John Doe and }Jane Doe}
392  }";
393  $this->obj->content = $teststring;
394  $this->obj->parse();
395  $this->assertTrue('WARNING_UNBALANCED_AMOUNT_OF_BRACES'==$this->obj->warnings[0]['warning']);
396  }
397  */
399  $teststring = "@Article { art1,
400 title = {Titel1},
401 author = {John Doe and Jane Doe}
402 }
403 @Article { art2,
404 title = {Titel1},
405 author = {John Doe and Jane Doe}
406 }
407 @Article { art1,
408 title = {Titel1},
409 author = {John Doe and Jane Doe}
410 }
411 @Article { art2,
412 title = {Titel1},
413 author = {John Doe and Jane Doe}
414 }
415 @Article { art3,
416 title = {Titel1},
417 author = {John Doe and Jane Doe}
418 }";
419  $this->obj->content = $teststring;
420  $this->obj->parse();
421  $this->assertTrue('WARNING_MULTIPLE_ENTRIES' == $this->obj->warnings[0]['warning']);
422  }
423 
424 
425  /* This testing suite is needed to get the Authors correct.
426  for more information: http://artis.imag.fr/%7EXavier.Decoret/resources/xdkbibtex/bibtex_summary.html
427  The names of the functions are build as follows:
428  "test": Of course it is a unit test
429  "Author": Function testing the authors
430  "First": There are three different ways writing an author this is the first one
431  "Simple": Description of the tes
432  */
434  $test = "AA BB";
435  $shouldbe = array();
436  $shouldbe[0]['first'] = 'AA';
437  $shouldbe[0]['von'] = '';
438  $shouldbe[0]['last'] = 'BB';
439  $shouldbe[0]['jr'] = '';
440  $this->assertEquals($shouldbe, $this->obj->_extractAuthors($test));
441  }
442 
443 
445  $test = "AA";
446  $shouldbe = array();
447  $shouldbe[0]['first'] = '';
448  $shouldbe[0]['von'] = '';
449  $shouldbe[0]['last'] = 'AA';
450  $shouldbe[0]['jr'] = '';
451  $this->assertEquals($shouldbe, $this->obj->_extractAuthors($test));
452  }
453 
454 
456  $test = "AA bb";
457  $shouldbe = array();
458  $shouldbe[0]['first'] = 'AA';
459  $shouldbe[0]['von'] = '';
460  $shouldbe[0]['last'] = 'bb';
461  $shouldbe[0]['jr'] = '';
462  $this->assertEquals($shouldbe, $this->obj->_extractAuthors($test));
463  }
464 
465 
467  $test = "aa";
468  $shouldbe = array();
469  $shouldbe[0]['first'] = '';
470  $shouldbe[0]['von'] = '';
471  $shouldbe[0]['last'] = 'aa';
472  $shouldbe[0]['jr'] = '';
473  $this->assertEquals($shouldbe, $this->obj->_extractAuthors($test));
474  }
475 
476 
478  $test = "AA bb CC";
479  $shouldbe = array();
480  $shouldbe[0]['first'] = 'AA';
481  $shouldbe[0]['von'] = 'bb';
482  $shouldbe[0]['last'] = 'CC';
483  $shouldbe[0]['jr'] = '';
484  $this->assertEquals($shouldbe, $this->obj->_extractAuthors($test));
485  }
486 
487 
489  $test = "AA bb CC dd EE";
490  $shouldbe = array();
491  $shouldbe[0]['first'] = 'AA';
492  $shouldbe[0]['von'] = 'bb CC dd';
493  $shouldbe[0]['last'] = 'EE';
494  $shouldbe[0]['jr'] = '';
495  $this->assertEquals($shouldbe, $this->obj->_extractAuthors($test));
496  }
497 
498 
500  $test = "AA 1B cc dd";
501  $shouldbe = array();
502  $shouldbe[0]['first'] = 'AA 1B';
503  $shouldbe[0]['von'] = 'cc';
504  $shouldbe[0]['last'] = 'dd';
505  $shouldbe[0]['jr'] = '';
506  $this->assertEquals($shouldbe, $this->obj->_extractAuthors($test));
507  }
508 
509 
511  $test = "AA 1b cc dd";
512  $shouldbe = array();
513  $shouldbe[0]['first'] = 'AA';
514  $shouldbe[0]['von'] = '1b cc';
515  $shouldbe[0]['last'] = 'dd';
516  $shouldbe[0]['jr'] = '';
517  $this->assertEquals($shouldbe, $this->obj->_extractAuthors($test));
518  }
519 
520 
522  $test = "AA {b}B cc dd";
523  $shouldbe = array();
524  $shouldbe[0]['first'] = 'AA {b}B';
525  $shouldbe[0]['von'] = 'cc';
526  $shouldbe[0]['last'] = 'dd';
527  $shouldbe[0]['jr'] = '';
528  $this->assertEquals($shouldbe, $this->obj->_extractAuthors($test));
529  }
530 
531 
533  $test = "AA {b}b cc dd";
534  $shouldbe = array();
535  $shouldbe[0]['first'] = 'AA';
536  $shouldbe[0]['von'] = '{b}b cc';
537  $shouldbe[0]['last'] = 'dd';
538  $shouldbe[0]['jr'] = '';
539  $this->assertEquals($shouldbe, $this->obj->_extractAuthors($test));
540  }
541 
542 
544  $test = "AA {B}B cc dd";
545  $shouldbe = array();
546  $shouldbe[0]['first'] = 'AA {B}B';
547  $shouldbe[0]['von'] = 'cc';
548  $shouldbe[0]['last'] = 'dd';
549  $shouldbe[0]['jr'] = '';
550  $this->assertEquals($shouldbe, $this->obj->_extractAuthors($test));
551  }
552 
553 
555  $test = "AA {B}b cc dd";
556  $shouldbe = array();
557  $shouldbe[0]['first'] = 'AA';
558  $shouldbe[0]['von'] = '{B}b cc';
559  $shouldbe[0]['last'] = 'dd';
560  $shouldbe[0]['jr'] = '';
561  $this->assertEquals($shouldbe, $this->obj->_extractAuthors($test));
562  }
563 
564 
566  $test = "AA \BB{b} cc dd";
567  $shouldbe = array();
568  $shouldbe[0]['first'] = 'AA \BB{b}';
569  $shouldbe[0]['von'] = 'cc';
570  $shouldbe[0]['last'] = 'dd';
571  $shouldbe[0]['jr'] = '';
572  $this->assertEquals($shouldbe, $this->obj->_extractAuthors($test));
573  }
574 
575 
577  $test = "AA \bb{b} cc dd";
578  $shouldbe = array();
579  $shouldbe[0]['first'] = 'AA';
580  $shouldbe[0]['von'] = '\bb{b} cc';
581  $shouldbe[0]['last'] = 'dd';
582  $shouldbe[0]['jr'] = '';
583  $this->assertEquals($shouldbe, $this->obj->_extractAuthors($test));
584  }
585 
586 
588  $test = "AA {bb} cc DD";
589  $shouldbe = array();
590  $shouldbe[0]['first'] = 'AA {bb}';
591  $shouldbe[0]['von'] = 'cc';
592  $shouldbe[0]['last'] = 'DD';
593  $shouldbe[0]['jr'] = '';
594  $this->assertEquals($shouldbe, $this->obj->_extractAuthors($test));
595  }
596 
597 
599  $test = "AA bb {cc} DD";
600  $shouldbe = array();
601  $shouldbe[0]['first'] = 'AA';
602  $shouldbe[0]['von'] = 'bb';
603  $shouldbe[0]['last'] = '{cc} DD';
604  $shouldbe[0]['jr'] = '';
605  $this->assertEquals($shouldbe, $this->obj->_extractAuthors($test));
606  }
607 
608 
610  $test = "AA {bb} CC";
611  $shouldbe = array();
612  $shouldbe[0]['first'] = 'AA {bb}';
613  $shouldbe[0]['von'] = '';
614  $shouldbe[0]['last'] = 'CC';
615  $shouldbe[0]['jr'] = '';
616  $this->assertEquals($shouldbe, $this->obj->_extractAuthors($test));
617  }
618 
619 
621  $test = "bb CC, AA";
622  $shouldbe = array();
623  $shouldbe[0]['first'] = 'AA';
624  $shouldbe[0]['von'] = 'bb';
625  $shouldbe[0]['last'] = 'CC';
626  $shouldbe[0]['jr'] = '';
627  $this->assertEquals($shouldbe, $this->obj->_extractAuthors($test));
628  }
629 
630 
632  $test = "bb CC, aa";
633  $shouldbe = array();
634  $shouldbe[0]['first'] = 'aa';
635  $shouldbe[0]['von'] = 'bb';
636  $shouldbe[0]['last'] = 'CC';
637  $shouldbe[0]['jr'] = '';
638  $this->assertEquals($shouldbe, $this->obj->_extractAuthors($test));
639  }
640 
641 
643  $test = "bb CC dd EE, AA";
644  $shouldbe = array();
645  $shouldbe[0]['first'] = 'AA';
646  $shouldbe[0]['von'] = 'bb CC dd';
647  $shouldbe[0]['last'] = 'EE';
648  $shouldbe[0]['jr'] = '';
649  $this->assertEquals($shouldbe, $this->obj->_extractAuthors($test));
650  }
651 
652 
654  $test = "bb, AA";
655  $shouldbe = array();
656  $shouldbe[0]['first'] = 'AA';
657  $shouldbe[0]['von'] = '';
658  $shouldbe[0]['last'] = 'bb';
659  $shouldbe[0]['jr'] = '';
660  $this->assertEquals($shouldbe, $this->obj->_extractAuthors($test));
661  }
662 
663 
665  $test = "BB,";
666  $shouldbe = array();
667  $shouldbe[0]['first'] = '';
668  $shouldbe[0]['von'] = '';
669  $shouldbe[0]['last'] = 'BB';
670  $shouldbe[0]['jr'] = '';
671  $this->assertEquals($shouldbe, $this->obj->_extractAuthors($test));
672  }
673 
674 
676  $test = "bb CC,XX, AA";
677  $shouldbe = array();
678  $shouldbe[0]['first'] = 'AA';
679  $shouldbe[0]['von'] = 'bb';
680  $shouldbe[0]['last'] = 'CC';
681  $shouldbe[0]['jr'] = 'XX';
682  $this->assertEquals($shouldbe, $this->obj->_extractAuthors($test));
683  }
684 
685 
687  $test = "bb CC,xx, AA";
688  $shouldbe = array();
689  $shouldbe[0]['first'] = 'AA';
690  $shouldbe[0]['von'] = 'bb';
691  $shouldbe[0]['last'] = 'CC';
692  $shouldbe[0]['jr'] = 'xx';
693  $this->assertEquals($shouldbe, $this->obj->_extractAuthors($test));
694  }
695 
696 
698  $test = "BB,, AA";
699  $shouldbe = array();
700  $shouldbe[0]['first'] = 'AA';
701  $shouldbe[0]['von'] = '';
702  $shouldbe[0]['last'] = 'BB';
703  $shouldbe[0]['jr'] = '';
704  $this->assertEquals($shouldbe, $this->obj->_extractAuthors($test));
705  }
706 
707 
708  /*Testing the case determination needed for the authors*/
709  function testCaseUpperSimple() {
710  $test = 'AA';
711  $this->assertEquals(1, $this->obj->_determineCase($test));
712  }
713 
714 
715  function testCaseLowerSimple() {
716  $test = 'aa';
717  $this->assertEquals(0, $this->obj->_determineCase($test));
718  }
719 
720 
722  $test = '{a}';
723  $this->assertEquals(- 1, $this->obj->_determineCase($test));
724  }
725 
726 
728  $test = '{A}A';
729  $this->assertEquals(1, $this->obj->_determineCase($test));
730  }
731 
732 
734  $test = '{a}a';
735  $this->assertEquals(0, $this->obj->_determineCase($test));
736  }
737 
738 
740  $test = '1A';
741  $this->assertEquals(1, $this->obj->_determineCase($test));
742  }
743 
744 
746  $test = '1a';
747  $this->assertEquals(0, $this->obj->_determineCase($test));
748  }
749 
750 
752  $test = ' A';
753  $this->assertEquals(1, $this->obj->_determineCase($test));
754  }
755 
756 
758  $test = ' a';
759  $this->assertEquals(0, $this->obj->_determineCase($test));
760  }
761 
762 
764  $test = '';
765  $this->assertTrue(PEAR::isError($this->obj->_determineCase($test)));
766  }
767 
768 
770  $test = 2;
771  $this->assertTrue(PEAR::isError($this->obj->_determineCase($test)));
772  }
773 
774 
775  function testAllowedTypeTrue() {
776  $test = 'article';
777  $this->assertTrue($this->obj->_checkAllowedEntryType($test));
778  }
779 
780 
781  function testAllowedTypeFalse() {
782  $test = 'foo';
783  $this->assertFalse($this->obj->_checkAllowedEntryType($test));
784  }
785 
786 
787  public function testAllowedTypeWarning() {
788  $this->obj->clearWarnings();
789  $test = "@Foo { art1,
790 title = {Titel1},
791 author = {John Doe and Jane Doe}
792 }";
793  $this->obj->content = $test;
794  $this->obj->setOption('validate', true);
795  $this->obj->parse();
796  $this->assertEquals('WARNING_NOT_ALLOWED_ENTRY_TYPE', $this->obj->warnings[0]['warning']);
797  }
798 
799 
800  public function testMissingLastBraceParsing() {
801  $this->obj->clearWarnings();
802  $test = '
803 @phdthesis{foo1,
804 school = {school1},
805 title = {title1},
806 author = {author1},
807 year = {year1}
808 }
809 @phdthesis{foo2,
810 school = {school2},
811 title = {title2},
812 author = {author2},
813 year = {year2}
814 
815 @phdthesis{foo3,
816 school = {school3},
817 title = {title3},
818 author = {author3},
819 year = {year3}
820 }
821 @phdthesis{foo4,
822 school = {school4},
823 title = {title4},
824 author = {author4},
825 year = {year4}
826 }
827  ';
828  $this->obj->content = $test;
829  $this->obj->setOption('validate', true);
830  $this->obj->parse();
831  $this->assertEquals($this->obj->amount(), 4);
832  }
833 
834 
835  public function testMissingLastBraceParsing2() {
836  $this->obj->clearWarnings();
837  $test = '
838 @phdthesis{foo1,
839 school = {school1},
840 title = {title1},
841 author = {author1},
842 year = {year1}
843  ';
844  $this->obj->content = $test;
845  $this->obj->setOption('validate', true);
846  $this->obj->parse();
847  $this->assertEquals($this->obj->amount(), 1);
848  }
849 
850 
851  public function testMissingLastBraceWarning() {
852  $this->obj->clearWarnings();
853  $test = '
854 @phdthesis{foo1,
855 school = {school1},
856 title = {title1},
857 author = {author1},
858 year = {year1}
859 }
860 @phdthesis{foo2,
861 school = {school2},
862 title = {title2},
863 author = {author2},
864 year = {year2}
865 
866 @phdthesis{foo3,
867 school = {school3},
868 title = {title3},
869 author = {author3},
870 year = {year3}
871 }
872 @phdthesis{foo4,
873 school = {school4},
874 title = {title4},
875 author = {author4},
876 year = {year4}
877 }
878  ';
879  $this->obj->content = $test;
880  $this->obj->setOption('validate', true);
881  $this->obj->parse();
882  $this->assertEquals($this->obj->warnings[0]['warning'], 'WARNING_MISSING_END_BRACE');
883  }
884 
885 
886  public function testNewlineInAuthorField() {
887  $this->obj->clearWarnings();
888  $test = '
889 @phdthesis{foo1,
890 school = {school1},
891 title = {title1},
892 author = {author1 and
893 author2},
894 year = {year1}
895 }
896  ';
897  $shouldbe = array(
898  array( 'first' => '', 'von' => '', 'last' => 'author1', 'jr' => '' ),
899  array( 'first' => '', 'von' => '', 'last' => 'author2', 'jr' => '' )
900  );
901  $this->obj->content = $test;
902  $this->obj->setOption('unwrap', false);
903  $this->obj->parse();
904  $this->assertEquals($shouldbe, $this->obj->data[0]['author']);
905  }
906 
907 
908  public function testNotRemoveCurlyBraces() {
909  $this->obj->clearWarnings();
910  $test = '
911 @phdthesis{foo4,
912 school = {school4},
913 title = {Do {S}omething},
914 author = {author4},
915 year = {year4}
916 }
917  ';
918  $shouldbe = 'Do {S}omething';
919  $this->obj->content = $test;
920  $this->obj->setOption('removeCurlyBraces', false);
921  $this->obj->parse();
922  //print_r($this->obj->data[0]['author']);
923  $this->assertEquals($shouldbe, $this->obj->data[0]['title']);
924  }
925 
926 
927  public function testRemoveCurlyBraces() {
928  $this->obj->clearWarnings();
929  $test = '
930 @phdthesis{foo4,
931 school = {school4},
932 title = {Do {S}omething},
933 author = {author4},
934 year = {year4}
935 }
936  ';
937  $shouldbe = 'Do Something';
938  $this->obj->content = $test;
939  $this->obj->setOption('removeCurlyBraces', true);
940  $this->obj->parse();
941  //print_r($this->obj->data[0]['author']);
942  $this->assertEquals($shouldbe, $this->obj->data[0]['title']);
943  }
944 
945 
946  public function testRemoveCurlyBraces2() {
947  $this->obj->clearWarnings();
948  $test = '
949 @phdthesis{foo4,
950 school = {school4},
951 title = {Do {S}o{me\}th}ing},
952 author = {author4},
953 year = {year4}
954 }
955  ';
956  $shouldbe = 'Do Some\}thing';
957  $this->obj->content = $test;
958  $this->obj->setOption('removeCurlyBraces', true);
959  $this->obj->parse();
960  $this->assertEquals($shouldbe, $this->obj->data[0]['title']);
961  }
962 
963 
965  $this->obj->clearWarnings();
966  $test = '
967 @phdthesis{foo4,
968 school = {school4},
969 title = {Do Something},
970 author = {author4},
971 year = {year4}
972 }
973  ';
974  $shouldbe = 'Do Something';
975  $this->obj->content = $test;
976  $this->obj->setOption('removeCurlyBraces', true);
977  $this->obj->parse();
978  $this->assertEquals($shouldbe, $this->obj->data[0]['title']);
979  }
980 
981 
982  public function testRtfExport() {
983  $test = '
984 @phdthesis{foo4,
985 title = {title},
986 author = {author},
987 journal = {journal},
988 year = {year}
989 }
990  ';
991  $shouldbe = '{\rtf
992 author title journal year
993 \par
994 }';
995  $this->obj->content = $test;
996  /*Setting formating option and saving old state*/
997  $oldrtfstring = $this->obj->rtfstring;
998  $this->obj->rtfstring = 'AUTHORS TITLE JOURNAL YEAR';
999  $oldauthorstring = $this->obj->authorstring;
1000  $this->obj->authorstring = 'LAST';
1001  $this->obj->parse();
1002  $rtf = $this->obj->rtf();
1003  /*Resetting old state*/
1004  $this->obj->rtfstring = $oldrtfstring;
1005  $this->obj->authorstring = $oldauthorstring;
1006  $this->assertEquals($shouldbe, $rtf);
1007  }
1008 
1009 
1010  public function testHtmlExport() {
1011  $test = '
1012 @phdthesis{foo4,
1013 title = {title},
1014 author = {author},
1015 journal = {journal},
1016 year = {year}
1017 }
1018  ';
1019  $shouldbe = '<p>
1020 author title journal year
1021 </p>
1022 ';
1023  $this->obj->content = $test;
1024  /*Setting formating option and saving old state*/
1025  $oldhtmlstring = $this->obj->htmlstring;
1026  $this->obj->htmlstring = 'AUTHORS TITLE JOURNAL YEAR';
1027  $oldauthorstring = $this->obj->authorstring;
1028  $this->obj->authorstring = 'LAST';
1029  $this->obj->parse();
1030  $html = $this->obj->html();
1031  /*Resetting old state*/
1032  $this->obj->htmlstring = $oldhtmlstring;
1033  $this->obj->authorstring = $oldauthorstring;
1034  $this->assertEquals($shouldbe, $html);
1035  }
1036 
1037 
1038  public function testFormatAuthor() {
1039  $test = '
1040 @phdthesis{foo4,
1041 author = {von Last, Jr ,First}
1042 }
1043  ';
1044  $shouldbe = 'von Last Jr First';
1045  $this->obj->content = $test;
1046  /*Setting formating option and saving old state*/
1047  $oldhtmlstring = $this->obj->htmlstring;
1048  $this->obj->htmlstring = 'AUTHORS';
1049  $oldauthorstring = $this->obj->authorstring;
1050  $this->obj->authorstring = 'VON LAST JR FIRST';
1051  $this->obj->parse();
1052  $html = $this->obj->html();
1053  /*Dropping tags and trimming*/
1054  $html = trim(strip_tags($html));
1055  /*Resetting old state*/
1056  $this->obj->htmlstring = $oldhtmlstring;
1057  $this->obj->authorstring = $oldauthorstring;
1058  $this->assertEquals($shouldbe, $html);
1059  }
1060 
1061 
1062  public function testExtractAuthorWhitespace() {
1063  $test = 'John Doe';
1064  $shouldbe = array();
1065  $shouldbe[0]['first'] = 'John';
1066  $shouldbe[0]['von'] = '';
1067  $shouldbe[0]['last'] = 'Doe';
1068  $shouldbe[0]['jr'] = '';
1069  $this->assertEquals($shouldbe, $this->obj->_extractAuthors($test));
1070  }
1071 
1072 
1073  public function testExtractAuthorTilde() {
1074  $test = 'John~Doe';
1075  $shouldbe = array();
1076  $shouldbe[0]['first'] = 'John';
1077  $shouldbe[0]['von'] = '';
1078  $shouldbe[0]['last'] = 'Doe';
1079  $shouldbe[0]['jr'] = '';
1080  $this->assertEquals($shouldbe, $this->obj->_extractAuthors($test));
1081  }
1082 
1083 
1084  public function testNotExtractAuthors() {
1085  $this->obj->clearWarnings();
1086  $test = '
1087 @phdthesis{foo4,
1088 author = {John Doe},
1089 }
1090  ';
1091  $shouldbe = 'John Doe';
1092  $this->obj->content = $test;
1093  $this->obj->setOption('extractAuthors', false);
1094  $this->obj->parse();
1095  $this->assertEquals($shouldbe, $this->obj->data[0]['author']);
1096  }
1097 
1098 
1099  public function testExtractAuthors() {
1100  $this->obj->clearWarnings();
1101  $test = '
1102 @phdthesis{foo4,
1103 author = {John Doe},
1104 }
1105  ';
1106  $shouldbe = array();
1107  $shouldbe[0]['first'] = 'John';
1108  $shouldbe[0]['von'] = '';
1109  $shouldbe[0]['last'] = 'Doe';
1110  $shouldbe[0]['jr'] = '';
1111  $this->obj->content = $test;
1112  $this->obj->setOption('extractAuthors', true);
1113  $this->obj->parse();
1114  $this->assertEquals($shouldbe, $this->obj->data[0]['author']);
1115  }
1116 
1117 
1119  $this->obj->clearWarnings();
1120  $test = "@phdthesis { foo4,\n\tauthor = {John Doe}\n}\n\n";
1121  $this->obj->content = $test;
1122  $this->obj->setOption('extractAuthors', false);
1123  $this->obj->parse();
1124  $this->assertEquals($test, $this->obj->bibTex());
1125  }
1126 
1127 
1129  $this->obj->clearWarnings();
1130  $test = "@phdthesis { foo4,\n\tauthor = {John Doe}\n}\n\n";
1131  $shouldbe = '{\rtf
1132 John Doe, "{\b }", {\i },
1133 \par
1134 }';
1135  $this->obj->content = $test;
1136  $this->obj->setOption('extractAuthors', false);
1137  $this->obj->parse();
1138  $this->assertEquals($shouldbe, $this->obj->rtf());
1139  }
1140 
1141 
1143  $this->obj->clearWarnings();
1144  $test = "@phdthesis { foo4,\n\tauthor = {John Doe}\n}\n\n";
1145  $shouldbe = '<p>
1146 John Doe, "<strong></strong>", <em></em>, <br />
1147 </p>
1148 ';
1149  $this->obj->content = $test;
1150  $this->obj->setOption('extractAuthors', false);
1151  $this->obj->parse();
1152  $this->assertEquals($shouldbe, $this->obj->html());
1153  }
1154 }
1155 
1156 // Call Structures_BibTexTest::main() if this source file is executed directly.
1157 if (PHPUnit_MAIN_METHOD == "BibTexTest::main") {
1158  BibTexTest::main();
1159 }
1160 ?>