View source
<?php
class BiblioContributorWebTestCase extends BiblioWebTestCase {
public static function getInfo() {
return array(
'name' => 'Biblio contributor web tests',
'description' => 'Web tests for contributor functions.',
'group' => 'Biblio',
);
}
public function setUp() {
parent::setUp('biblio');
require_once __DIR__ . '/../includes/biblio.contributors.inc';
}
public function testBiblioUpdateContributors() {
$node = $this
->createNode();
$nid = $node->nid;
$vid1 = $node->vid;
$this
->assertIdentical($node->biblio_contributors[2]['firstname'], 'George', 'Test biblio_insert_contributors($node), firstname');
$this
->assertIdentical($node->biblio_contributors[2]['lastname'], 'Bushzzzzzz', 'Test biblio_insert_contributors($node), lastname');
unset($node->biblio_contributors[2]);
$node->revision = TRUE;
node_save($node);
$node = node_load($nid, NULL, TRUE);
$this
->assertFalse(isset($node->biblio_contributors[2]), 'Test removing an author and updating the node');
biblio_delete_contributor_revision($node->biblio_contributors[1]['cid'], $node->vid);
$node = node_load($nid, NULL, TRUE);
$this
->assertEqual(count($node->biblio_contributors), 1, 'Test biblio_delete_contributor_revision($cid, $vid)');
$node = node_load($nid, $vid1, TRUE);
$this
->assertEqual(count($node->biblio_contributors), 3, 'Test load original vid, still three authors');
biblio_delete_contributors($node);
$node = node_load($nid, NULL, TRUE);
$this
->assertFalse(count($node->biblio_contributors), 'Test biblio_delete_contributors($node), should be zero authors on reload');
$account = $this
->getUser('access biblio content');
$this
->drupalLogin($account);
foreach (array(
'biblio/authors/1',
'admin/config/content/biblio/author/1',
) as $url) {
$this
->drupalGet($url);
$headers = $this
->drupalGetHeaders(TRUE);
list(, $status) = explode(' ', $headers[0][':status'], 3);
$this
->assertEqual($status, 302, 'Redirection response code was sent.' . $status);
$this
->assertUrl('biblio', array(
'query' => array(
'f[author]' => 1,
),
));
}
$this
->assertNoText('[edit]');
$account = $this
->getUser('administer biblio');
$this
->drupalLogin($account);
$this
->drupalGet('biblio', array(
'query' => array(
'f[author]' => 1,
),
));
$this
->assertText('[edit]');
}
public function testBiblioDeleteOrphanAuthors() {
$orphan_authors = array();
$orphan_authors = biblio_get_orphan_authors();
$orphan_count = biblio_count_orphan_authors();
$author = array(
'name' => 'Ron J. Jeromezzzzzz',
'auth_type' => 1,
);
biblio_save_contributor($author);
$before_count = biblio_count_orphan_authors();
$this
->assertTrue($before_count != 0, "There are {$before_count} orphans to delete");
biblio_delete_orphan_authors(TRUE);
$after_count = biblio_count_orphan_authors();
$this
->assertEqual($after_count, 0, "There are now {$after_count} orphans");
foreach ($orphan_authors as $author) {
biblio_save_contributor($author);
}
$restored_count = biblio_count_orphan_authors();
$this
->assertEqual($orphan_count, $restored_count, "Restored {$restored_count} of {$orphan_count} original orphans");
}
public function testFormatting() {
$random = $this
->randomName();
$author = (object) array(
'cid' => $random,
);
require_once __DIR__ . '/../includes/biblio.pages.inc';
$link = _biblio_author_edit_links($author);
$this
->assertTrue(preg_match(',^<a href="/.+/authors/' . $random . '/edit"> \\[edit\\]</a>$,', $link), '_biblio_author_edit_links() returns valid link.');
}
}