Structures_BibTex
[ class tree: Structures_BibTex ] [ index: Structures_BibTex ] [ all elements ]

Source for file BibTexTest.php

Documentation is available at BibTexTest.php

  1. <?php
  2. // Call Structures_BibTexTest::main() if this source file is executed directly.
  3. if (!defined("PHPUnit2_MAIN_METHOD")) {
  4.     define("PHPUnit2_MAIN_METHOD""BibTexTest::main");
  5. }
  6.  
  7. require_once "PHPUnit2/Framework/TestCase.php";
  8. require_once "PHPUnit2/Framework/TestSuite.php";
  9.  
  10. // You may remove the following line when all tests have been implemented.
  11. require_once "PHPUnit2/Framework/IncompleteTestError.php";
  12.  
  13. require_once "./BibTex.php";
  14. require_once "PEAR.php";
  15.  
  16. /**
  17.  * Test class for Structures_BibTex.
  18.  * Generated by PHPUnit2_Util_Skeleton on 2006-06-06 at 22:13:11.
  19.  */
  20. class BibTexTest extends PHPUnit2_Framework_TestCase {
  21.     var $obj;
  22.  
  23.     /**
  24.      * Runs the test methods of this class.
  25.      *
  26.      * @access public
  27.      * @static
  28.      */
  29.     public static function main({
  30.         require_once "PHPUnit2/TextUI/TestRunner.php";
  31.         $suite  = new PHPUnit2_Framework_TestSuite("Structures_BibTexTest");
  32.         $result = PHPUnit2_TextUI_TestRunner::run($suite);
  33.     }
  34.  
  35.     /**
  36.      * Sets up the fixture, for example, open a network connection.
  37.      * This method is called before a test is executed.
  38.      *
  39.      * @access protected
  40.      */
  41.     protected function setUp({
  42.         $this->obj = new Structures_BibTex();
  43.     }
  44.  
  45.     /**
  46.      * Tears down the fixture, for example, close a network connection.
  47.      * This method is called after a test is executed.
  48.      *
  49.      * @access protected
  50.      */
  51.     protected function tearDown({
  52.         unset($this->obj);
  53.     }
  54.  
  55.     public function testLoadFileFileExists({
  56.         $ret $this->obj->loadFile("BibTexTest.php");
  57.         $this->content ''//Erasing the loaded content again because it is senseless
  58.         $this->assertTrue($ret);
  59.     }
  60.  
  61.     public function testLoadFileFileDoesNotExists({
  62.         $ret $this->obj->loadFile((string)time());
  63.         $this->assertTrue(PEAR::isError($ret));
  64.     }
  65.  
  66.     /**
  67.      * @todo Implement test_parseEntry().
  68.      */
  69.     public function test_parseEntry({
  70.         //Remember here that there is no closing brace!
  71.         $test "@foo{bar,john=doe";
  72.         $shouldbe = array();
  73.         $shouldbe['john''doe';
  74.         $shouldbe['cite''bar';
  75.         $shouldbe['type''foo';
  76.         $this->assertEquals($shouldbe$this->obj->_parseEntry($test));
  77.     }
  78.  
  79.     public function test_checkEqualSignTrue({
  80.         $test "={=}";
  81.         $this->assertTrue($this->obj->_checkEqualSign($test,0));
  82.     }
  83.     public function test_checkEqualSignFalse({
  84.         $test "={=}";
  85.         $this->assertFalse($this->obj->_checkEqualSign($test,2));
  86.     }
  87.  
  88.     public function testClearWarnings({
  89.         $this->obj->clearWarnings();
  90.         $this->obj->_generateWarning('type''entry');
  91.         $this->obj->clearWarnings();
  92.         $this->assertFalse($this->obj->hasWarning());
  93.     }
  94.  
  95.     /*
  96.      * the next tests check for the generation of the following Warnings:
  97.      * - WARNING_AT_IN_BRACES
  98.      * - WARNING_ESCAPED_DOUBLE_QUOTE_INSIDE_DOUBLE_QUOTES
  99.      * - WARNING_UNBALANCED_AMOUNT_OF_BRACES
  100.      */
  101.     public function test_validateValueWarningAtInBraces({
  102.         $this->obj->clearWarnings();
  103.         $test '{john@doe}';
  104.         $this->obj->_validateValue($test'');
  105.         $this->assertEquals('WARNING_AT_IN_BRACES'$this->obj->warnings[0]['warning']);
  106.     }
  107.     public function test_validateValueWarningEscapedDoubleQuoteInsideDoubleQuotes({
  108.         $this->obj->clearWarnings();
  109.         $test '"john\"doe"';
  110.         $this->obj->_validateValue($test'');
  111.         $this->assertEquals('WARNING_ESCAPED_DOUBLE_QUOTE_INSIDE_DOUBLE_QUOTES'$this->obj->warnings[0]['warning']);
  112.     }
  113.     public function test_validateValueWarningUnbalancedAmountOfBracesOpen({
  114.         $this->obj->clearWarnings();
  115.         $test '{john{doe}';
  116.         $this->obj->_validateValue($test'');
  117.         $this->assertEquals('WARNING_UNBALANCED_AMOUNT_OF_BRACES'$this->obj->warnings[0]['warning']);
  118.     }
  119.     public function test_validateValueWarningUnbalancedAmountOfBracesClosed({
  120.         $this->obj->clearWarnings();
  121.         $test '{john}doe}';
  122.         $this->obj->_validateValue($test'');
  123.         $this->assertEquals('WARNING_UNBALANCED_AMOUNT_OF_BRACES'$this->obj->warnings[0]['warning']);
  124.     }
  125.  
  126.     public function test_generateWarning({
  127.         $this->obj->clearWarnings();
  128.         $this->obj->_generateWarning('type''entry');
  129.         $ret $this->obj->hasWarning();
  130.         $this->obj->clearWarnings();
  131.         $this->assertTrue($ret);
  132.     }
  133.  
  134.     public function testHasWarning()
  135.     {
  136.         $this->obj->clearWarnings();
  137.         $this->assertFalse($this->obj->hasWarning());
  138.     }
  139.  
  140.     public function testAmount()
  141.     {
  142.         $teststring "@Article {art1,author = {John Doe and Jane Doe}}@Article { art2,author = {John Doe and Jane Doe}}";
  143.         $this->obj->content = $teststring;
  144.         $this->obj->parse();
  145.         $this->assertEquals(2$this->obj->amount());
  146.     }
  147.  
  148.     public function testGetStatistic()
  149.     {
  150.         $teststring "@Article {art1,author = {John Doe and Jane Doe}}@Article { art2,author = {John Doe and Jane Doe}}";
  151.         $this->obj->content = $teststring;
  152.         $this->obj->parse();
  153.         $shouldbe            = array();
  154.         $shouldbe['article'= 2;
  155.         $this->assertEquals($shouldbe$this->obj->getStatistic());
  156.     }
  157.     
  158.     function testSingleParse()
  159.     {
  160.         $teststring="@Article { ppm_jon:1991,
  161. author = {John Doe and Jane Doe}
  162. }";
  163.         $this->obj->content=$teststring;
  164.         $this->obj->parse();
  165.         $this->assertEquals(1,$this->obj->amount());
  166.     }
  167.  
  168.     function testMultiParse()
  169.     {
  170.         $teststring "@Article { art1,
  171. author = {John Doe and Jane Doe}
  172. }
  173. @Article { art2,
  174. author = {John Doe and Jane Doe}
  175. }";
  176.         $this->obj->content = $teststring;
  177.         $this->obj->parse();
  178.         $this->assertEquals(2,$this->obj->amount());
  179.     }
  180.  
  181.     function testParse()
  182.     {
  183.         $teststring "@Article { art1,
  184. title = {Titel1},
  185. author = {John Doe and Jane Doe}
  186. }";
  187.         $shouldbe = array();
  188.         $shouldbe[0]['type''article';
  189.         $shouldbe[0]['cite''art1';
  190.         $shouldbe[0]['title''Titel1';
  191.         $shouldbe[0]['author'][0]['first''John';
  192.         $shouldbe[0]['author'][0]['von']   '';
  193.         $shouldbe[0]['author'][0]['last']  'Doe';
  194.         $shouldbe[0]['author'][0]['jr']    '';
  195.         $shouldbe[0]['author'][1]['first''Jane';
  196.         $shouldbe[0]['author'][1]['von']   '';
  197.         $shouldbe[0]['author'][1]['last']  'Doe';
  198.         $shouldbe[0]['author'][1]['jr']    '';
  199.         $this->obj->content = $teststring;
  200.         $this->obj->parse();
  201.         $this->assertEquals($shouldbe,$this->obj->data);
  202.     }
  203.  
  204.     function testBibTex()
  205.     {
  206.         $testarray = array();
  207.         $testarray[0]['type''Article';
  208.         $testarray[0]['cite''art1';
  209.         $testarray[0]['title''Titel1';
  210.         $testarray[0]['author'][0]['first''John';
  211.         $testarray[0]['author'][0]['von']   '';
  212.         $testarray[0]['author'][0]['last']  'Doe';
  213.         $testarray[0]['author'][0]['jr']    '';
  214.         $testarray[0]['author'][1]['first''Jane';
  215.         $testarray[0]['author'][1]['von']   '';
  216.         $testarray[0]['author'][1]['last']  'Doe';
  217.         $testarray[0]['author'][1]['jr']    '';
  218.         $shouldbe "@article { art1,
  219.     title = {Titel1},
  220.     author = {Doe, , John and Doe, , Jane}
  221. }";
  222.         $this->obj->data = $testarray;
  223.         $this->assertEquals(trim($shouldbe),trim($this->obj->bibTex()));
  224.     }
  225.  
  226.     function testAddEntry()
  227.     {
  228.         $addarray = array();
  229.         $addarray['type''Article';
  230.         $addarray['cite''art2';
  231.         $addarray['title''Titel2';
  232.         $addarray['author'][0'John Doe';
  233.         $addarray['author'][1'Jane Doe';
  234.         $teststring "@Article { art1,
  235. title = {Titel1},
  236. author = {John Doe and Jane Doe}
  237. }";
  238.         $this->obj->content = $teststring;
  239.         $this->obj->parse();
  240.         $this->obj->addEntry($addarray);
  241.         $this->assertEquals(2,$this->obj->amount());
  242.     }
  243.  
  244.     function testEntryOverMoreLines()
  245.     {
  246.         //Entry found at http://en.wikipedia.org/wiki/BibTeX
  247.         $teststring "@Book{abramowitz+stegun,
  248.   author =       \"Milton Abramowitz and Irene A. Stegun\",
  249.   title =        \"Handbook of Mathematical Functions with
  250.                   Formulas, Graphs, and Mathematical Tables\",
  251.   publisher =    \"Dover\",
  252.   year =         1964,
  253.   address =      \"New York\",
  254.   edition =      \"ninth Dover printing, tenth GPO printing\",
  255.   isbn =         \"0-486-61272-4\"
  256. }";
  257.         $shouldbe = array();
  258.         $shouldbe[0]['type']  'book';
  259.         $shouldbe[0]['cite']  'abramowitz+stegun';
  260.         $shouldbe[0]['title'"Handbook of Mathematical Functions with
  261.                   Formulas, Graphs, and Mathematical Tables";
  262.         $shouldbe[0]['author'][0]['first''Milton';
  263.         $shouldbe[0]['author'][0]['von']   '';
  264.         $shouldbe[0]['author'][0]['last']  'Abramowitz';
  265.         $shouldbe[0]['author'][0]['jr']    '';
  266.         $shouldbe[0]['author'][1]['first''Irene A.';
  267.         $shouldbe[0]['author'][1]['von']   '';
  268.         $shouldbe[0]['author'][1]['last']  'Stegun';
  269.         $shouldbe[0]['author'][1]['jr']    '';
  270.         $shouldbe[0]['publisher''Dover';
  271.         $shouldbe[0]['year']      '1964';
  272.         $shouldbe[0]['address']   'New York';
  273.         $shouldbe[0]['edition']   'ninth Dover printing, tenth GPO printing';
  274.         $shouldbe[0]['isbn']      '0-486-61272-4';
  275.         $this->obj->content = $teststring;
  276.         $this->obj->parse();
  277.         $this->assertEquals($shouldbe$this->obj->data);
  278.     }
  279.  
  280.     function testParsingComment()
  281.     {
  282.         $teststring "@Article { art1,
  283. title = {Titel1},
  284. author = {John Doe and Jane Doe}
  285. }
  286. Here is a comment
  287. @Article { art2,
  288. title = {Titel2},
  289. author = {John Doe and Jane Doe}
  290. }";
  291.         $shouldbe = array();
  292.         $shouldbe[0]['type''article';
  293.         $shouldbe[0]['cite''art1';
  294.         $shouldbe[0]['title''Titel1';
  295.         $shouldbe[0]['author'][0]['first''John';
  296.         $shouldbe[0]['author'][0]['von']   '';
  297.         $shouldbe[0]['author'][0]['last']  'Doe';
  298.         $shouldbe[0]['author'][0]['jr']    '';
  299.         $shouldbe[0]['author'][1]['first''Jane';
  300.         $shouldbe[0]['author'][1]['von']   '';
  301.         $shouldbe[0]['author'][1]['last']  'Doe';
  302.         $shouldbe[0]['author'][1]['jr']    '';
  303.         $shouldbe[1]['type''article';
  304.         $shouldbe[1]['cite''art2';
  305.         $shouldbe[1]['title''Titel2';
  306.         $shouldbe[1]['author'][0]['first''John';
  307.         $shouldbe[1]['author'][0]['von']   '';
  308.         $shouldbe[1]['author'][0]['last']  'Doe';
  309.         $shouldbe[1]['author'][0]['jr']    '';
  310.         $shouldbe[1]['author'][1]['first''Jane';
  311.         $shouldbe[1]['author'][1]['von']   '';
  312.         $shouldbe[1]['author'][1]['last']  'Doe';
  313.         $shouldbe[1]['author'][1]['jr']    '';
  314.         $this->obj->content = $teststring;
  315.         $this->obj->parse();
  316.         $this->assertTrue($this->obj->data == $shouldbe);
  317.     }
  318.     /*
  319.     function testWrongBraces1() {
  320.         $teststring = "@Article { art1,
  321. title = {Tit}el1},
  322. author = {John Doe and Jane Doe}
  323. }";
  324.         $this->obj->content = $teststring;
  325.         $this->assertTrue(PEAR::isError($this->obj->parse()));
  326.     }
  327.     
  328.     function testWrongBraces2() {
  329.         $teststring = "@Article { art1,
  330. title = {Titel1},
  331. author = {John Doe and }Jane }Doe}
  332. }";
  333.         $this->obj->content = $teststring;
  334.         $this->assertTrue(PEAR::isError($this->obj->parse()));
  335.     }
  336.     */
  337.     function testWrongBraces3({
  338.         $teststring "@Article { art1,
  339. title = {Titel1},
  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 testWarningAtInBraces({
  347.         $teststring "@Article { art1,
  348. title = {Titel1},
  349. author = {John Doe and @Jane Doe}
  350. }";
  351.         $this->obj->content = $teststring;
  352.         $this->obj->parse();
  353.         $this->assertTrue('WARNING_AT_IN_BRACES'==$this->obj->warnings[0]['warning']);
  354.     }
  355.     function testWarningEscapedDoubleQuote({
  356.         $teststring "@Article { art1,
  357. title = {Titel1},
  358. author = \"John Doe and \\\"Jane Doe\"
  359. }";
  360.         $this->obj->content = $teststring;
  361.         $this->obj->parse();
  362.         $this->assertTrue('WARNING_ESCAPED_DOUBLE_QUOTE_INSIDE_DOUBLE_QUOTES'==$this->obj->warnings[0]['warning']);
  363.     }
  364.     /*
  365.     function testWarningAmountBraces() {
  366.         $teststring = "@Article { art1,
  367. title = {Tit{el1},
  368. author = {John Doe and }Jane Doe}
  369. }";
  370.         $this->obj->content = $teststring;
  371.         $this->obj->parse();
  372.         $this->assertTrue('WARNING_UNBALANCED_AMOUNT_OF_BRACES'==$this->obj->warnings[0]['warning']);
  373.     }
  374.     */
  375.     function testWarningMultipleEntries({
  376.         $teststring "@Article { art1,
  377. title = {Titel1},
  378. author = {John Doe and Jane Doe}
  379. }
  380. @Article { art2,
  381. title = {Titel1},
  382. author = {John Doe and Jane Doe}
  383. }
  384. @Article { art1,
  385. title = {Titel1},
  386. author = {John Doe and Jane Doe}
  387. }
  388. @Article { art2,
  389. title = {Titel1},
  390. author = {John Doe and Jane Doe}
  391. }
  392. @Article { art3,
  393. title = {Titel1},
  394. author = {John Doe and Jane Doe}
  395. }";
  396.         $this->obj->content = $teststring;
  397.         $this->obj->parse();
  398.         $this->assertTrue('WARNING_MULTIPLE_ENTRIES'==$this->obj->warnings[0]['warning']);
  399.     }
  400.  
  401.     /* This testing suite is needed to get the Authors correct.
  402.      for more information: http://artis.imag.fr/%7EXavier.Decoret/resources/xdkbibtex/bibtex_summary.html
  403.      The names of the functions are build as follows:
  404.      "test": Of course it is a unit test
  405.      "Author": Function testing the authors
  406.      "First": There are three different ways writing an author this is the first one
  407.      "Simple": Description of the tes
  408.     */
  409.   function testAuthorFirstSimple({
  410.       $test     "AA BB";
  411.       $shouldbe = array();
  412.       $shouldbe[0]['first''AA';
  413.       $shouldbe[0]['von']   '';
  414.       $shouldbe[0]['last']  'BB';
  415.       $shouldbe[0]['jr']    '';
  416.       $this->assertEquals($shouldbe$this->obj->_extractAuthors($test));
  417.     }
  418.   function testAuthorFirstLastCannotBeEmpty({
  419.       $test     "AA";
  420.       $shouldbe = array();
  421.       $shouldbe[0]['first''';
  422.       $shouldbe[0]['von']   '';
  423.       $shouldbe[0]['last']  'AA';
  424.       $shouldbe[0]['jr']    '';
  425.       $this->assertEquals($shouldbe$this->obj->_extractAuthors($test));
  426.   }
  427.   function testAuthorFirstSimpleLowerCase({
  428.       $test     "AA bb";
  429.       $shouldbe = array();
  430.       $shouldbe[0]['first''AA';
  431.       $shouldbe[0]['von']   '';
  432.       $shouldbe[0]['last']  'bb';
  433.       $shouldbe[0]['jr']    '';
  434.       $this->assertEquals($shouldbe$this->obj->_extractAuthors($test));
  435.   }
  436.   function testAuthorFirstLastCannotBeEmptyLowerCase({
  437.       $test     "aa";
  438.       $shouldbe = array();
  439.       $shouldbe[0]['first''';
  440.       $shouldbe[0]['von']   '';
  441.       $shouldbe[0]['last']  'aa';
  442.       $shouldbe[0]['jr']    '';
  443.       $this->assertEquals($shouldbe$this->obj->_extractAuthors($test));
  444.   }
  445.   function testAuthorFirstSimpleVon({
  446.       $test     "AA bb CC";
  447.       $shouldbe = array();
  448.       $shouldbe[0]['first''AA';
  449.       $shouldbe[0]['von']   'bb';
  450.       $shouldbe[0]['last']  'CC';
  451.       $shouldbe[0]['jr']    '';
  452.       $this->assertEquals($shouldbe$this->obj->_extractAuthors($test));
  453.   }
  454.   function testAuthorFirstSimpleVonInnerUppercase({
  455.       $test     "AA bb CC dd EE";
  456.       $shouldbe = array();
  457.       $shouldbe[0]['first''AA';
  458.       $shouldbe[0]['von']   'bb CC dd';
  459.       $shouldbe[0]['last']  'EE';
  460.       $shouldbe[0]['jr']    '';
  461.       $this->assertEquals($shouldbe$this->obj->_extractAuthors($test));
  462.   }
  463.   function testAuthorFirstDigitsArecaselessUppercase({
  464.       $test     "AA 1B cc dd";
  465.       $shouldbe = array();
  466.       $shouldbe[0]['first''AA 1B';
  467.       $shouldbe[0]['von']   'cc';
  468.       $shouldbe[0]['last']  'dd';
  469.       $shouldbe[0]['jr']    '';
  470.       $this->assertEquals($shouldbe$this->obj->_extractAuthors($test));
  471.   }
  472.   function testAuthorFirstDigitsArecaselessLowercase({
  473.       $test     "AA 1b cc dd";
  474.       $shouldbe = array();
  475.       $shouldbe[0]['first''AA';
  476.       $shouldbe[0]['von']   '1b cc';
  477.       $shouldbe[0]['last']  'dd';
  478.       $shouldbe[0]['jr']    '';
  479.       $this->assertEquals($shouldbe$this->obj->_extractAuthors($test));
  480.   }
  481.   function testAuthorFirstPseudoLettersAreCaselessLowerInsideUpperOutside({
  482.       $test     "AA {b}B cc dd";
  483.       $shouldbe = array();
  484.       $shouldbe[0]['first''AA {b}B';
  485.       $shouldbe[0]['von']   'cc';
  486.       $shouldbe[0]['last']  'dd';
  487.       $shouldbe[0]['jr']    '';
  488.       $this->assertEquals($shouldbe$this->obj->_extractAuthors($test));
  489.   }
  490.   function testAuthorFirstPseudoLettersAreCaselessLowerInsideLowerOutside({
  491.       $test     "AA {b}b cc dd";
  492.       $shouldbe = array();
  493.       $shouldbe[0]['first''AA';
  494.       $shouldbe[0]['von']   '{b}b cc';
  495.       $shouldbe[0]['last']  'dd';
  496.       $shouldbe[0]['jr']    '';
  497.       $this->assertEquals($shouldbe$this->obj->_extractAuthors($test));
  498.   }
  499.   function testAuthorFirstPseudoLettersAreCaselessUpperInsideUpperOutside({
  500.       $test     "AA {B}B cc dd";
  501.       $shouldbe = array();
  502.       $shouldbe[0]['first''AA {B}B';
  503.       $shouldbe[0]['von']   'cc';
  504.       $shouldbe[0]['last']  'dd';
  505.       $shouldbe[0]['jr']    '';
  506.       $this->assertEquals($shouldbe$this->obj->_extractAuthors($test));
  507.   }
  508.   function testAuthorFirstPseudoLettersAreCaselessUpperInsideLowerOutside({
  509.       $test     "AA {B}b cc dd";
  510.       $shouldbe = array();
  511.       $shouldbe[0]['first''AA';
  512.       $shouldbe[0]['von']   '{B}b cc';
  513.       $shouldbe[0]['last']  'dd';
  514.       $shouldbe[0]['jr']    '';
  515.       $this->assertEquals($shouldbe$this->obj->_extractAuthors($test));
  516.   }
  517.   function testAuthorFirstNonLettersAreCaselessUpperCase({
  518.       $test     "AA \BB{b} cc dd";
  519.       $shouldbe = array();
  520.       $shouldbe[0]['first''AA \BB{b}';
  521.       $shouldbe[0]['von']   'cc';
  522.       $shouldbe[0]['last']  'dd';
  523.       $shouldbe[0]['jr']    '';
  524.       $this->assertEquals($shouldbe$this->obj->_extractAuthors($test));
  525.   }
  526.   function testAuthorFirstNonLettersAreCaselessLowerCase({
  527.       $test     "AA \bb{b} cc dd";
  528.       $shouldbe = array();
  529.       $shouldbe[0]['first''AA';
  530.       $shouldbe[0]['von']   '\bb{b} cc';
  531.       $shouldbe[0]['last']  'dd';
  532.       $shouldbe[0]['jr']    '';
  533.       $this->assertEquals($shouldbe$this->obj->_extractAuthors($test));
  534.   }
  535.   function testAuthorFirstGroupingCaselessOne({
  536.       $test     "AA {bb} cc DD";
  537.       $shouldbe = array();
  538.       $shouldbe[0]['first''AA {bb}';
  539.       $shouldbe[0]['von']   'cc';
  540.       $shouldbe[0]['last']  'DD';
  541.       $shouldbe[0]['jr']    '';
  542.       $this->assertEquals($shouldbe$this->obj->_extractAuthors($test));
  543.   }
  544.   function testAuthorFirstGroupingCaselessTwo({
  545.       $test     "AA bb {cc} DD";
  546.       $shouldbe = array();
  547.       $shouldbe[0]['first''AA';
  548.       $shouldbe[0]['von']   'bb';
  549.       $shouldbe[0]['last']  '{cc} DD';
  550.       $shouldbe[0]['jr']    '';
  551.       $this->assertEquals($shouldbe$this->obj->_extractAuthors($test));
  552.   }
  553.   function testAuthorFirstGroupingCaselessThree({
  554.       $test     "AA {bb} CC";
  555.       $shouldbe = array();
  556.       $shouldbe[0]['first''AA {bb}';
  557.       $shouldbe[0]['von']   '';
  558.       $shouldbe[0]['last']  'CC';
  559.       $shouldbe[0]['jr']    '';
  560.       $this->assertEquals($shouldbe$this->obj->_extractAuthors($test));
  561.   }
  562.   function testAuthorSecondAndThirdSimpleCaseFirstUppercase({
  563.       $test     "bb CC, AA";
  564.       $shouldbe = array();
  565.       $shouldbe[0]['first''AA';
  566.       $shouldbe[0]['von']   'bb';
  567.       $shouldbe[0]['last']  'CC';
  568.       $shouldbe[0]['jr']    '';
  569.       $this->assertEquals($shouldbe$this->obj->_extractAuthors($test));
  570.   }
  571.   function testAuthorSecondAndThirdSimpleCaseFirstLowercase({
  572.       $test     "bb CC, aa";
  573.       $shouldbe = array();
  574.       $shouldbe[0]['first''aa';
  575.       $shouldbe[0]['von']   'bb';
  576.       $shouldbe[0]['last']  'CC';
  577.       $shouldbe[0]['jr']    '';
  578.       $this->assertEquals($shouldbe$this->obj->_extractAuthors($test));
  579.   }
  580.   function testAuthorSecondAndThirdSimpleVon({
  581.       $test     "bb CC dd EE, AA";
  582.       $shouldbe = array();
  583.       $shouldbe[0]['first''AA';
  584.       $shouldbe[0]['von']   'bb CC dd';
  585.       $shouldbe[0]['last']  'EE';
  586.       $shouldbe[0]['jr']    '';
  587.       $this->assertEquals($shouldbe$this->obj->_extractAuthors($test));
  588.   }
  589.   function testAuthorSecondAndThirdLastPartCoannotBeEmpty({
  590.       $test     "bb, AA";
  591.       $shouldbe = array();
  592.       $shouldbe[0]['first''AA';
  593.       $shouldbe[0]['von']   '';
  594.       $shouldbe[0]['last']  'bb';
  595.       $shouldbe[0]['jr']    '';
  596.       $this->assertEquals($shouldbe$this->obj->_extractAuthors($test));
  597.   }
  598.   function testAuthorSecondAndThirdFirstCanBeEmptyAfterComma({
  599.       $test     "BB,";
  600.       $shouldbe = array();
  601.       $shouldbe[0]['first''';
  602.       $shouldbe[0]['von']   '';
  603.       $shouldbe[0]['last']  'BB';
  604.       $shouldbe[0]['jr']    '';
  605.       $this->assertEquals($shouldbe$this->obj->_extractAuthors($test));
  606.   }
  607.   function testAuthorSecondAndThirdSimpleJrUppercase({
  608.       $test     "bb CC,XX, AA";
  609.       $shouldbe = array();
  610.       $shouldbe[0]['first''AA';
  611.       $shouldbe[0]['von']   'bb';
  612.       $shouldbe[0]['last']  'CC';
  613.       $shouldbe[0]['jr']    'XX';
  614.       $this->assertEquals($shouldbe$this->obj->_extractAuthors($test));
  615.   }
  616.   function testAuthorSecondAndThirdSimpleJrLowercase({
  617.       $test     "bb CC,xx, AA";
  618.       $shouldbe = array();
  619.       $shouldbe[0]['first''AA';
  620.       $shouldbe[0]['von']   'bb';
  621.       $shouldbe[0]['last']  'CC';
  622.       $shouldbe[0]['jr']    'xx';
  623.       $this->assertEquals($shouldbe$this->obj->_extractAuthors($test));
  624.   }
  625.   function testAuthorSecondAndThirdJrCanBeEmptyBetweenCommas({
  626.       $test     "BB,, AA";
  627.       $shouldbe = array();
  628.       $shouldbe[0]['first''AA';
  629.       $shouldbe[0]['von']   '';
  630.       $shouldbe[0]['last']  'BB';
  631.       $shouldbe[0]['jr']    '';
  632.       $this->assertEquals($shouldbe$this->obj->_extractAuthors($test));
  633.   }
  634.   /*Testing the case determination needed for the authors*/
  635.   function testCaseUpperSimple({
  636.       $test 'AA';
  637.       $this->assertEquals(1$this->obj->_determineCase($test));
  638.   }
  639.   function testCaseLowerSimple({
  640.       $test 'aa';
  641.       $this->assertEquals(0$this->obj->_determineCase($test));
  642.   }
  643.   function testCaseCaselessSimple({
  644.       $test '{a}';
  645.       $this->assertEquals(-1$this->obj->_determineCase($test));
  646.   }
  647.   function testCaseUpperComplexBrace({
  648.       $test '{A}A';
  649.       $this->assertEquals(1$this->obj->_determineCase($test));
  650.   }
  651.   function testCaseLowerComplexBrace({
  652.       $test '{a}a';
  653.       $this->assertEquals(0$this->obj->_determineCase($test));
  654.   }
  655.   function testCaseUpperComplexNumber({
  656.       $test '1A';
  657.       $this->assertEquals(1$this->obj->_determineCase($test));
  658.   }
  659.   function testCaseLowerComplexNumber({
  660.       $test '1a';
  661.       $this->assertEquals(0$this->obj->_determineCase($test));
  662.   }
  663.   function testCaseUpperComplexWhitespace({
  664.       $test ' A';
  665.       $this->assertEquals(1$this->obj->_determineCase($test));
  666.   }
  667.   function testCaseLowerComplexWhitespace({
  668.       $test ' a';
  669.       $this->assertEquals(0$this->obj->_determineCase($test));
  670.   }
  671.   function testCaseErrorEmptyString({
  672.       $test '';
  673.       $this->assertTrue(PEAR::isError($this->obj->_determineCase($test)));
  674.   }
  675.   function testCaseErrorNonString({
  676.       $test = 2;
  677.       $this->assertTrue(PEAR::isError($this->obj->_determineCase($test)));
  678.   }
  679. }
  680.  
  681. // Call Structures_BibTexTest::main() if this source file is executed directly.
  682. if (PHPUnit2_MAIN_METHOD == "BibTexTest::main"{
  683.     BibTexTest::main();
  684. }
  685. ?>

Documentation generated on Mon, 11 Mar 2019 14:41:30 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.