diff --git a/node_display_title.test b/node_display_title.test index ab59f0e..ec19cce 100644 --- a/node_display_title.test +++ b/node_display_title.test @@ -10,12 +10,6 @@ */ class NodeDisplayTitleTestCase extends DrupalWebTestCase { - protected $webUser; - protected $adminUser; - - /** - * {@inheritdoc} - */ public static function getInfo() { return array( 'name' => 'Node Display Title Tests', @@ -25,21 +19,28 @@ class NodeDisplayTitleTestCase extends DrupalWebTestCase { } /** - * Creates field on page node. + * {@inheritdoc} */ public function setUp() { - $this->adminUser = $this->drupalCreateUser(array('bypass node access', 'administer nodes')); $this->public_files_directory = variable_get('file_public_path'); - $this->drupalLogin($this->adminUser); + parent::setup(array('node_display_title')); + + // Create an admin user and log in. + $this->drupalLogin( + $this->drupalCreateUser(array('bypass node access', 'administer nodes')) + ); + // Enable title on article. $field_name = 'field_node_display_title'; $type = 'page'; + // Get weight of title. $field_instances_by_node_type = field_info_instances('node'); $instance = $field_instances_by_node_type[$type]; $extra_fields = field_info_extra_fields('node', $type, 'form'); $title_field_weight = $extra_fields['title']['weight']; + // Move all fields below title down one position. // Define field instance options. $instance_options = array( @@ -57,35 +58,41 @@ class NodeDisplayTitleTestCase extends DrupalWebTestCase { ), ), ); + $node_display_title_settings[] = $type; + // Add field instance if not already present for given node type. if (!isset($instance['field_node_display_title'])) { field_create_instance($instance_options); } - $web_user = $this->drupalCreateUser(array('create page content', 'edit own page content')); - $this->drupalLogin($web_user); } /** * Creates page and test values. */ public function testNodeDisplayTitleCreate() { + // Create a web user and log in. + $this->drupalLogin( + $this->drupalCreateUser(array('create page content', 'edit own page content')) + ); + $edit = array(); - $langcode = LANGUAGE_NONE; $edit["title"] = $this->randomName(8); - $edit["body[$langcode][0][value]"] = $this->randomName(16); - $edit["field_node_display_title[$langcode][0][value]"] = $this->randomName(8); + $edit["body[und][0][value]"] = $this->randomName(16); + $edit["field_node_display_title[und][0][value]"] = $this->randomName(8); + $this->drupalPost('node/add/page', $edit, t('Save')); - // Check that the Basic page has been created. + $this->assertRaw(t('!post %title has been created.', array('!post' => 'Basic page', '%title' => $edit["title"])), 'Basic page created.'); - // Check that the node exists in the database. + $node = $this->drupalGetNodeByTitle($edit["title"]); + $this->assertTrue($node, 'Node found in database.'); - // Check that the title is set on the node. - $this->assertEqual($node->field_node_display_title[$langcode][0]['value'], $edit["field_node_display_title[$langcode][0][value]"], 'Value found saved on page correctly'); - // Edit page and check that text is set correctly on the field. + $this->assertEqual($node->field_node_display_title[LANGUAGE_NONE][0]['value'], $edit["field_node_display_title[und][0][value]"]); + $this->clickLink(t('Edit')); - $this->assertFieldById('edit-field-node-display-title-und-0-value', $edit["field_node_display_title[$langcode][0][value]"], 'value is set correctly on edit page'); + + $this->assertFieldById('edit-field-node-display-title-und-0-value', $edit["field_node_display_title[und][0][value]"]); } }