View source
<?php
class BiblioNodeCreationTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Biblio node creation',
'description' => 'Create a biblio node and test saving it.',
'group' => 'Biblio',
);
}
public function setUp() {
parent::setUp('biblio');
$web_user = $this
->drupalCreateUser(array(
'create biblio content',
));
$this
->drupalLogin($web_user);
}
public function testBiblioNodeCreation() {
$edit = array();
$edit["biblio_type"] = '101';
$this
->drupalPost('node/add/biblio', $edit, t('Next'));
$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'));
$this
->assertRaw(t('!post %title has been created.', array(
'!post' => 'Biblio',
'%title' => $edit["title"],
)), t('Biblio entry created.'));
$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.'));
}
}