You are here

public function BiblioContributorWebTestCase::testBiblioUpdateContributors in Bibliography Module 7

File

tests/BiblioContributorWebTestCase.test, line 30

Class

BiblioContributorWebTestCase
Web tests for contributor functions.

Code

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');

  // Test that expected author paths redirect to author pages.
  $account = $this
    ->getUser('access biblio content');
  $this
    ->drupalLogin($account);
  foreach (array(
    'biblio/authors/1',
    'admin/config/content/biblio/author/1',
  ) as $url) {

    // Get the expected author path.
    $this
      ->drupalGet($url);

    // HTTP status is correct.
    $headers = $this
      ->drupalGetHeaders(TRUE);
    list(, $status) = explode(' ', $headers[0][':status'], 3);
    $this
      ->assertEqual($status, 302, 'Redirection response code was sent.' . $status);

    // URL is correct.
    $this
      ->assertUrl('biblio', array(
      'query' => array(
        'f[author]' => 1,
      ),
    ));
  }

  // Edit links do not appear for 'access biblio content'.
  $this
    ->assertNoText('[edit]');

  // Edit links appear for 'administer biblio'.
  $account = $this
    ->getUser('administer biblio');
  $this
    ->drupalLogin($account);
  $this
    ->drupalGet('biblio', array(
    'query' => array(
      'f[author]' => 1,
    ),
  ));
  $this
    ->assertText('[edit]');
}