You are here

BiblioContributorWebTestCase.test in Bibliography Module 7

File

tests/BiblioContributorWebTestCase.test
View source
<?php

/**
 * Web tests for contributor functions.
 */
class BiblioContributorWebTestCase extends BiblioWebTestCase {

  /**
   * {@inheritdoc}
   */
  public static function getInfo() {
    return array(
      'name' => 'Biblio contributor web tests',
      'description' => 'Web tests for contributor functions.',
      'group' => 'Biblio',
    );
  }

  /**
   * {@inheritdoc}
   */
  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');

    // 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]');
  }

  /**
   *
   */
  public function testBiblioDeleteOrphanAuthors() {
    $orphan_authors = array();

    // First save any existing orphans so we can put them back.
    $orphan_authors = biblio_get_orphan_authors();
    $orphan_count = biblio_count_orphan_authors();
    $author = array(
      'name' => 'Ron J. Jeromezzzzzz',
      'auth_type' => 1,
    );

    // Create a new orphan so we will have at least one.
    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");
  }

  /**
   * Test formatting functions.
   */
  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.');
  }

}

Classes

Namesort descending Description
BiblioContributorWebTestCase Web tests for contributor functions.