/[drupal]/contributions/modules/biblio/tests/contributor.test
ViewVC logotype

Diff of /contributions/modules/biblio/tests/contributor.test

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1 by rjerome, Mon Nov 16 02:24:22 2009 UTC revision 1.1.2.1 by rjerome, Mon Nov 16 02:24:22 2009 UTC
# Line 0  Line 1 
1    <?php
2    // $Id$
3    /*
4     * @file
5     * Tests for contributor handling in the Biblio module
6     *
7     */
8    
9    class BiblioContributorWebTestCase extends BiblioWebTestCase {
10      function setUp() {
11        require_once(drupal_get_path('module', 'biblio') .'/biblio.contributors.inc');
12      }
13    
14    
15    }
16    
17    class BiblioContributorUnitTest extends BiblioContributorWebTestCase {
18    
19      public static function getInfo() {
20        return array(
21          'name' => 'Biblio contributor unit tests',
22          'description' => 'Unit tests for contributor functions.',
23          'group' => 'Biblio',
24        );
25      }
26    
27      function testGrabSurname() {
28    
29        $surname = 'van der Plus';
30        list ($surname, $prefix) = _grabSurname($surname);
31        $this->assertIdentical($surname, 'Plus' );
32        $this->assertIdentical($prefix, 'van der' );
33        $surname = 'Van den Bussche';
34        list ($surname, $prefix) = _grabSurname($surname);
35        $this->assertIdentical($surname, 'Van den Bussche' );
36        $this->assertIdentical($prefix, FALSE );
37      }
38      function testGrabFirstnameInitials() {
39    
40        $string = "Ron";
41        list($firstname,$initials,$prefix) = _grabFirstnameInitials($string);
42        $this->assertIdentical($firstname, 'Ron' );
43        $this->assertIdentical($initials, '' );
44        $string = "Ron J.";
45        list($firstname,$initials,$prefix) = _grabFirstnameInitials($string);
46        $this->assertIdentical($firstname, 'Ron' );
47        $this->assertIdentical($initials, 'J' );
48        $string = "sir Ron J.";
49        list($firstname,$initials,$prefix) = _grabFirstnameInitials($string);
50        $this->assertIdentical($firstname, 'Ron' );
51        $this->assertIdentical($initials, 'J' );
52        $this->assertIdentical($prefix, 'sir' );
53        $string = "R J";
54        list($firstname,$initials,$prefix) = _grabFirstnameInitials($string);
55        $this->assertIdentical($firstname, '' );
56        $this->assertIdentical($initials, 'R J' );
57        $string = "R. J.";
58        list($firstname,$initials,$prefix) = _grabFirstnameInitials($string);
59        $this->assertIdentical($firstname, '' );
60        $this->assertIdentical($initials, 'R J' );
61        $string = "R.J.";
62        list($firstname,$initials,$prefix) = _grabFirstnameInitials($string);
63        $this->assertIdentical($firstname, '' );
64        $this->assertIdentical($initials, 'R J' );
65    
66      }
67    
68      function testBiblioParseAuthor() {
69    
70        $author['name'] = 'Bush, Jr. III, George W';
71        $author = biblio_parse_author($author);
72        $this->assertIdentical($author['firstname'], 'George', 'Test biblio_parse_author($author), firstname' );
73        $this->assertIdentical($author['lastname'], 'Bush', 'Test biblio_parse_author($author), lastname');
74        $this->assertIdentical($author['initials'], 'W', 'Test biblio_parse_author($author), initials' );
75        $this->assertIdentical($author['suffix'], 'Jr. III', 'Test biblio_parse_author($author), suffix' );
76    
77      }
78    
79      function testBiblioUpdateContributors() {
80    
81        $node = $this->createNode();
82        $nid = $node->nid;
83        $vid1 = $node->vid;
84        $node->biblio_contributors[1][] = array('name' => 'Ron J. Jeromezzzzzz',  'auth_type' => 1);
85        $node->biblio_contributors[1][] = array('name' => 'John Smithzzzzzz',     'auth_type' => 1);
86        $node->biblio_contributors[1][] = array('name' => 'George W. Bushzzzzzz', 'auth_type' => 1);
87        biblio_insert_contributors($node);
88        $node = node_load($nid, NULL, TRUE);
89        foreach($node->biblio_contributors[1] as $author) {
90          $this->cids[] = $author['cid'];
91        }
92        $this->assertIdentical($node->biblio_contributors[1][2]['firstname'], 'George', 'Test biblio_insert_contributors($node), firstname');
93        $this->assertIdentical($node->biblio_contributors[1][2]['lastname'], 'Bushzzzzzz', 'Test biblio_insert_contributors($node), lastname' );
94        unset ($node->biblio_contributors[1][2]);
95        $node->revision = TRUE;
96        node_save($node);
97    
98        $node = node_load($nid, NULL, TRUE);
99        $this->assertFalse(isset($node->biblio_contributors[1][2]),'Test removing an author and updating the node');
100    
101        biblio_delete_contributor_revision($node->biblio_contributors[1][1]['cid'], $node->vid);
102        $node = node_load($nid, NULL, TRUE);
103        $this->assertEqual(count($node->biblio_contributors[1]), 1, 'Test biblio_delete_contributor_revision($cid, $vid)');
104    
105        $node = node_load($nid, $vid1, TRUE);
106    
107        $this->assertEqual(count($node->biblio_contributors[1]), 3, 'Test load original vid, still three authors');
108    
109        biblio_delete_contributors($node);
110        $node = node_load($nid, NULL, TRUE);
111        $this->assertFalse(count($node->biblio_contributors),'Test biblio_delete_contributors($node), should be zero authors on reload');
112    
113      }
114    
115      function testBiblioDeleteOrphanAuthors() {
116        $orphan_authors = array();
117        $orphan_authors = biblio_get_orphan_authors(); // first save any existing orphans so we can put them back
118        $orphan_count = biblio_count_orphan_authors();
119        $author = array('name' => 'Ron J. Jeromezzzzzz',  'auth_type' => 1);
120        biblio_save_contributor($author);  // create a new orphan so we will have at least one
121        $before_count = biblio_count_orphan_authors();
122        $this->assertTrue($before_count != 0, "There are $before_count orphans to delete");
123        biblio_delete_orphan_authors(TRUE);
124        $after_count = biblio_count_orphan_authors();
125        $this->assertEqual($after_count, 0, "There are now $after_count orphans");
126    
127    
128        foreach ($orphan_authors as $author) {
129          biblio_save_contributor($author);
130        }
131        $restored_count = biblio_count_orphan_authors();
132        $this->assertEqual($orphan_count, $restored_count, "Restored $restored_count of $orphan_count original orphans");
133    
134      }
135    
136    }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.1.2.1

  ViewVC Help
Powered by ViewVC 1.1.3