You are here

BiblioNodeCreationTestCase.test in Bibliography Module 7

File

tests/BiblioNodeCreationTestCase.test
View source
<?php

/**
 * Test biblio node creation.
 */
class BiblioNodeCreationTestCase extends DrupalWebTestCase {

  /**
   * {@inheritdoc}
   */
  public static function getInfo() {
    return array(
      'name' => 'Biblio node creation',
      'description' => 'Create a biblio node and test saving it.',
      'group' => 'Biblio',
    );
  }

  /**
   * {@inheritdoc}
   */
  public function setUp() {
    parent::setUp('biblio');
    $web_user = $this
      ->drupalCreateUser(array(
      'create biblio content',
    ));
    $this
      ->drupalLogin($web_user);
  }

  /**
   * Create a biblio node and verify its consistency in the database.
   */
  public function testBiblioNodeCreation() {

    // Create a node.
    $edit = array();
    $edit["biblio_type"] = '101';
    $this
      ->drupalPost('node/add/biblio', $edit, t('Next'));

    // Check that the next step of the form appears.
    $this
      ->assertOptionSelected('edit-biblio-type', '101');
    $this
      ->assertFieldById('edit-title');
    $this
      ->assertFieldById('edit-biblio-year');
    $this
      ->assertRaw('Year of Publication ' . theme('form_required_marker'), t('Form required marker appears for "Year of Publication".'));
    $edit = array(
      'title' => $this
        ->randomString(32),
    );
    $this
      ->drupalPost(NULL, $edit, t('Save'));
    $this
      ->assertRaw('
Year of Publication field is required (on the <em class="placeholder">Publication</em> tab).', t('Custom "field is required" validation message appears.'));
    $edit = array(
      'title' => $this
        ->randomString(32),
      'biblio_year' => '2009',
      'biblio_contributors[0][name]' => 'Kevin Brown',
      'biblio_contributors[1][name]' => 'Martin Clark',
      'biblio_contributors[2][name]' => 'George Wei',
      'biblio_keywords' => 'architecture, building, wood',
    );
    $this
      ->drupalPost(NULL, $edit, t('Save'));

    // Check that the Basic page has been created.
    $this
      ->assertRaw(t('!post %title has been created.', array(
      '!post' => 'Biblio',
      '%title' => $edit["title"],
    )), t('Biblio entry created.'));

    // Check that the node exists in the database.
    $node = $this
      ->drupalGetNodeByTitle($edit['title']);
    $keywordstring = implode(', ', $node->biblio_keywords);
    $this
      ->assertIdentical($keywordstring, 'architecture, building, wood', t('Keywords are present on the biblio node.'));
    $this
      ->assertTrue($node, t('Node found in database.'));
  }

}

Classes

Namesort descending Description
BiblioNodeCreationTestCase Test biblio node creation.