summaryrefslogtreecommitdiff
path: root/modules/node/node.test
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2009-10-11 03:07:21 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2009-10-11 03:07:21 +0000
commitb3265dbe174ce0efefa181b8af6c1eaea3ff22c2 (patch)
treeaa7e8b709c162fd781748d8bebaa12c75727e01e /modules/node/node.test
parent64a1a0d67eb5aecc8e6d78469b19f58e8443c717 (diff)
downloadbrdo-b3265dbe174ce0efefa181b8af6c1eaea3ff22c2.tar.gz
brdo-b3265dbe174ce0efefa181b8af6c1eaea3ff22c2.tar.bz2
#557292 by peximo, plach, catch, and yched: Convert node title to Field API.
Diffstat (limited to 'modules/node/node.test')
-rw-r--r--modules/node/node.test142
1 files changed, 97 insertions, 45 deletions
diff --git a/modules/node/node.test b/modules/node/node.test
index f1c296a76..a4f5f90e1 100644
--- a/modules/node/node.test
+++ b/modules/node/node.test
@@ -31,15 +31,15 @@ class NodeLoadMultipleUnitTest extends DrupalWebTestCase {
// Confirm that promoted nodes appear in the default node listing.
$this->drupalGet('node');
- $this->assertText($node1->title, t('Node title appears on the default listing.'));
- $this->assertText($node2->title, t('Node title appears on the default listing.'));
- $this->assertNoText($node3->title, t('Node title does not appear in the default listing.'));
- $this->assertNoText($node4->title, t('Node title does not appear in the default listing.'));
+ $this->assertText($node1->title[FIELD_LANGUAGE_NONE][0]['value'], t('Node title appears on the default listing.'));
+ $this->assertText($node2->title[FIELD_LANGUAGE_NONE][0]['value'], t('Node title appears on the default listing.'));
+ $this->assertNoText($node3->title[FIELD_LANGUAGE_NONE][0]['value'], t('Node title does not appear in the default listing.'));
+ $this->assertNoText($node4->title[FIELD_LANGUAGE_NONE][0]['value'], t('Node title does not appear in the default listing.'));
// Load nodes with only a condition. Nodes 3 and 4 will be loaded.
$nodes = node_load_multiple(NULL, array('promote' => 0));
- $this->assertEqual($node3->title, $nodes[$node3->nid]->title, t('Node was loaded.'));
- $this->assertEqual($node4->title, $nodes[$node4->nid]->title, t('Node was loaded.'));
+ $this->assertEqual($node3->title[FIELD_LANGUAGE_NONE][0]['value'], $nodes[$node3->nid]->title[FIELD_LANGUAGE_NONE][0]['value'], t('Node was loaded.'));
+ $this->assertEqual($node4->title[FIELD_LANGUAGE_NONE][0]['value'], $nodes[$node4->nid]->title[FIELD_LANGUAGE_NONE][0]['value'], t('Node was loaded.'));
$count = count($nodes);
$this->assertTrue($count == 2, t('@count nodes loaded.', array('@count' => $count)));
@@ -58,9 +58,9 @@ class NodeLoadMultipleUnitTest extends DrupalWebTestCase {
$nodes = node_load_multiple(array(1, 2, 3, 4), array('type' => 'article'));
$count = count($nodes);
$this->assertTrue($count == 3, t('@count nodes loaded', array('@count' => $count)));
- $this->assertEqual($nodes[$node1->nid]->title, $node1->title, t('Node successfully loaded.'));
- $this->assertEqual($nodes[$node2->nid]->title, $node2->title, t('Node successfully loaded.'));
- $this->assertEqual($nodes[$node3->nid]->title, $node3->title, t('Node successfully loaded.'));
+ $this->assertEqual($nodes[$node1->nid]->title[FIELD_LANGUAGE_NONE][0]['value'], $node1->title[FIELD_LANGUAGE_NONE][0]['value'], t('Node successfully loaded.'));
+ $this->assertEqual($nodes[$node2->nid]->title[FIELD_LANGUAGE_NONE][0]['value'], $node2->title[FIELD_LANGUAGE_NONE][0]['value'], t('Node successfully loaded.'));
+ $this->assertEqual($nodes[$node3->nid]->title[FIELD_LANGUAGE_NONE][0]['value'], $node3->title[FIELD_LANGUAGE_NONE][0]['value'], t('Node successfully loaded.'));
$this->assertFalse(isset($nodes[$node4->nid]));
// Now that all nodes have been loaded into the static cache, ensure that
@@ -68,16 +68,16 @@ class NodeLoadMultipleUnitTest extends DrupalWebTestCase {
$nodes = node_load_multiple(array(1, 2, 3, 4), array('type' => 'article'));
$count = count($nodes);
$this->assertTrue($count == 3, t('@count nodes loaded.', array('@count' => $count)));
- $this->assertEqual($nodes[$node1->nid]->title, $node1->title, t('Node successfully loaded'));
- $this->assertEqual($nodes[$node2->nid]->title, $node2->title, t('Node successfully loaded'));
- $this->assertEqual($nodes[$node3->nid]->title, $node3->title, t('Node successfully loaded'));
+ $this->assertEqual($nodes[$node1->nid]->title[FIELD_LANGUAGE_NONE][0]['value'], $node1->title[FIELD_LANGUAGE_NONE][0]['value'], t('Node successfully loaded'));
+ $this->assertEqual($nodes[$node2->nid]->title[FIELD_LANGUAGE_NONE][0]['value'], $node2->title[FIELD_LANGUAGE_NONE][0]['value'], t('Node successfully loaded'));
+ $this->assertEqual($nodes[$node3->nid]->title[FIELD_LANGUAGE_NONE][0]['value'], $node3->title[FIELD_LANGUAGE_NONE][0]['value'], t('Node successfully loaded'));
$this->assertFalse(isset($nodes[$node4->nid]), t('Node was not loaded'));
// Load nodes by nid, where type = article and promote = 0.
$nodes = node_load_multiple(array(1, 2, 3, 4), array('type' => 'article', 'promote' => 0));
$count = count($nodes);
$this->assertTrue($count == 1, t('@count node loaded', array('@count' => $count)));
- $this->assertEqual($nodes[$node3->nid]->title, $node3->title, t('Node successfully loaded.'));
+ $this->assertEqual($nodes[$node3->nid]->title[FIELD_LANGUAGE_NONE][0]['value'], $node3->title[FIELD_LANGUAGE_NONE][0]['value'], t('Node successfully loaded.'));
}
}
@@ -152,7 +152,7 @@ class NodeRevisionsTestCase extends DrupalWebTestCase {
// Confirm that revisions revert properly.
$this->drupalPost("node/$node->nid/revisions/{$nodes[1]->vid}/revert", array(), t('Revert'));
$this->assertRaw(t('@type %title has been reverted back to the revision from %revision-date.',
- array('@type' => 'Page', '%title' => $nodes[1]->title,
+ array('@type' => 'Page', '%title' => $nodes[1]->title[FIELD_LANGUAGE_NONE][0]['value'],
'%revision-date' => format_date($nodes[1]->revision_timestamp))), t('Revision reverted.'));
$reverted_node = node_load($node->nid);
$this->assertTrue(($nodes[1]->body[FIELD_LANGUAGE_NONE][0]['value'] == $reverted_node->body[FIELD_LANGUAGE_NONE][0]['value']), t('Node reverted correctly.'));
@@ -161,7 +161,7 @@ class NodeRevisionsTestCase extends DrupalWebTestCase {
$this->drupalPost("node/$node->nid/revisions/{$nodes[1]->vid}/delete", array(), t('Delete'));
$this->assertRaw(t('Revision from %revision-date of @type %title has been deleted.',
array('%revision-date' => format_date($nodes[1]->revision_timestamp),
- '@type' => 'Page', '%title' => $nodes[1]->title)), t('Revision deleted.'));
+ '@type' => 'Page', '%title' => $nodes[1]->title[FIELD_LANGUAGE_NONE][0]['value'])), t('Revision deleted.'));
$this->assertTrue(db_query('SELECT COUNT(vid) FROM {node_revision} WHERE nid = :nid and vid = :vid', array(':nid' => $node->nid, ':vid' => $nodes[1]->vid))->fetchField() == 0, t('Revision not found.'));
}
}
@@ -187,15 +187,16 @@ class PageEditTestCase extends DrupalWebTestCase {
*/
function testPageEdit() {
$langcode = FIELD_LANGUAGE_NONE;
+ $title_key = "title[$langcode][0][value]";
$body_key = "body[$langcode][0][value]";
// Create node to edit.
$edit = array();
- $edit['title'] = $this->randomName(8);
+ $edit[$title_key] = $this->randomName(8);
$edit[$body_key] = $this->randomName(16);
$this->drupalPost('node/add/page', $edit, t('Save'));
// Check that the node exists in the database.
- $node = $this->drupalGetNodeByTitle($edit['title']);
+ $node = $this->drupalGetNodeByTitle($edit[$title_key]);
$this->assertTrue($node, t('Node found in database.'));
// Check that "edit" link points to correct page.
@@ -206,18 +207,18 @@ class PageEditTestCase extends DrupalWebTestCase {
// Check that the title and body fields are displayed with the correct values.
$this->assertLink(t('Edit'), 0, t('Edit tab found.'));
- $this->assertFieldByName('title', $edit['title'], t('Title field displayed.'));
+ $this->assertFieldByName($title_key, $edit[$title_key], t('Title field displayed.'));
$this->assertFieldByName($body_key, $edit[$body_key], t('Body field displayed.'));
// Edit the content of the node.
$edit = array();
- $edit['title'] = $this->randomName(8);
+ $edit[$title_key] = $this->randomName(8);
$edit[$body_key] = $this->randomName(16);
// Stay on the current page, without reloading.
$this->drupalPost(NULL, $edit, t('Save'));
// Check that the title and body fields are displayed with the updated values.
- $this->assertText($edit['title'], t('Title displayed.'));
+ $this->assertText($edit[$title_key], t('Title displayed.'));
$this->assertText($edit[$body_key], t('Body displayed.'));
// Login as a second administrator user.
@@ -226,13 +227,13 @@ class PageEditTestCase extends DrupalWebTestCase {
// Edit the same node, creating a new revision.
$this->drupalGet("node/$node->nid/edit");
$edit = array();
- $edit['title'] = $this->randomName(8);
+ $edit[$title_key] = $this->randomName(8);
$edit[$body_key] = $this->randomName(16);
$edit['revision'] = TRUE;
$this->drupalPost(NULL, $edit, t('Save'));
// Ensure that the node revision has been created.
- $revised_node = $this->drupalGetNodeByTitle($edit['title']);
+ $revised_node = $this->drupalGetNodeByTitle($edit[$title_key]);
$this->assertNotIdentical($node->vid, $revised_node->vid, 'A new revision has been created.');
// Ensure that the node author is preserved when it was not changed in the
// edit form.
@@ -266,21 +267,22 @@ class PagePreviewTestCase extends DrupalWebTestCase {
*/
function testPagePreview() {
$langcode = FIELD_LANGUAGE_NONE;
+ $title_key = "title[$langcode][0][value]";
$body_key = "body[$langcode][0][value]";
// Fill in node creation form and preview node.
$edit = array();
- $edit['title'] = $this->randomName(8);
+ $edit[$title_key] = $this->randomName(8);
$edit[$body_key] = $this->randomName(16);
$this->drupalPost('node/add/page', $edit, t('Preview'));
// Check that the preview is displaying the title and body.
$this->assertTitle(t('Preview | Drupal'), t('Page title is preview.'));
- $this->assertText($edit['title'], t('Title displayed.'));
+ $this->assertText($edit[$title_key], t('Title displayed.'));
$this->assertText($edit[$body_key], t('Body displayed.'));
// Check that the title and body fields are displayed with the correct values.
- $this->assertFieldByName('title', $edit['title'], t('Title field displayed.'));
+ $this->assertFieldByName($title_key, $edit[$title_key], t('Title field displayed.'));
$this->assertFieldByName($body_key, $edit[$body_key], t('Body field displayed.'));
}
@@ -289,24 +291,25 @@ class PagePreviewTestCase extends DrupalWebTestCase {
*/
function testPagePreviewWithRevisions() {
$langcode = FIELD_LANGUAGE_NONE;
+ $title_key = "title[$langcode][0][value]";
$body_key = "body[$langcode][0][value]";
// Force revision on page content.
variable_set('node_options_page', array('status', 'revision'));
// Fill in node creation form and preview node.
$edit = array();
- $edit['title'] = $this->randomName(8);
+ $edit[$title_key] = $this->randomName(8);
$edit[$body_key] = $this->randomName(16);
$edit['log'] = $this->randomName(32);
$this->drupalPost('node/add/page', $edit, t('Preview'));
// Check that the preview is displaying the title and body.
$this->assertTitle(t('Preview | Drupal'), t('Page title is preview.'));
- $this->assertText($edit['title'], t('Title displayed.'));
+ $this->assertText($edit[$title_key], t('Title displayed.'));
$this->assertText($edit[$body_key], t('Body displayed.'));
// Check that the title and body fields are displayed with the correct values.
- $this->assertFieldByName('title', $edit['title'], t('Title field displayed.'));
+ $this->assertFieldByName($title_key, $edit[$title_key], t('Title field displayed.'));
$this->assertFieldByName($body_key, $edit[$body_key], t('Body field displayed.'));
// Check that the log field has the correct value.
@@ -336,16 +339,16 @@ class PageCreationTestCase extends DrupalWebTestCase {
function testPageCreation() {
// Create a node.
$edit = array();
- $edit['title'] = $this->randomName(8);
$langcode = FIELD_LANGUAGE_NONE;
+ $edit["title[$langcode][0][value]"] = $this->randomName(8);
$edit["body[$langcode][0][value]"] = $this->randomName(16);
$this->drupalPost('node/add/page', $edit, t('Save'));
// Check that the page has been created.
- $this->assertRaw(t('!post %title has been created.', array('!post' => 'Page', '%title' => $edit['title'])), t('Page created.'));
+ $this->assertRaw(t('!post %title has been created.', array('!post' => 'Page', '%title' => $edit["title[$langcode][0][value]"])), t('Page created.'));
// Check that the node exists in the database.
- $node = $this->drupalGetNodeByTitle($edit['title']);
+ $node = $this->drupalGetNodeByTitle($edit["title[$langcode][0][value]"]);
$this->assertTrue($node, t('Node found in database.'));
}
}
@@ -446,18 +449,21 @@ class NodeTitleXSSTestCase extends DrupalWebTestCase {
$this->drupalLogin($web_user);
$xss = '<script>alert("xss")</script>';
-
+ $title = $xss . $this->randomName();
+ $langcode = FIELD_LANGUAGE_NONE;
$edit = array(
- 'title' => $xss . $this->randomName(),
+ "title[$langcode][0][value]" => $title,
);
+
$this->drupalPost('node/add/page', $edit, t('Preview'));
$this->assertNoRaw($xss, t('Harmful tags are escaped when previewing a node.'));
- $node = $this->drupalCreateNode($edit);
+ $settings = array('title' => array(FIELD_LANGUAGE_NONE => array(array('value' => $title))));
+ $node = $this->drupalCreateNode($settings);
$this->drupalGet('node/' . $node->nid);
// assertTitle() decodes HTML-entities inside the <title> element.
- $this->assertTitle($edit['title'] . ' | Drupal', t('Title is diplayed when viewing a node.'));
+ $this->assertTitle($edit["title[$langcode][0][value]"] . ' | Drupal', t('Title is diplayed when viewing a node.'));
$this->assertNoRaw($xss, t('Harmful tags are escaped when viewing a node.'));
$this->drupalGet('node/' . $node->nid . '/edit');
@@ -526,13 +532,13 @@ class NodePostSettingsTestCase extends DrupalWebTestCase {
// Create a node.
$edit = array();
- $edit['title'] = $this->randomName(8);
$langcode = FIELD_LANGUAGE_NONE;
+ $edit["title[$langcode][0][value]"] = $this->randomName(8);
$edit["body[$langcode][0][value]"] = $this->randomName(16);
$this->drupalPost('node/add/page', $edit, t('Save'));
// Check that the post information is displayed.
- $node = $this->drupalGetNodeByTitle($edit['title']);
+ $node = $this->drupalGetNodeByTitle($edit["title[$langcode][0][value]"]);
$this->assertRaw('<span class="submitted">', t('Post information is displayed.'));
}
@@ -548,13 +554,13 @@ class NodePostSettingsTestCase extends DrupalWebTestCase {
// Create a node.
$edit = array();
- $edit['title'] = $this->randomName(8);
$langcode = FIELD_LANGUAGE_NONE;
+ $edit["title[$langcode][0][value]"] = $this->randomName(8);
$edit["body[$langcode][0][value]"] = $this->randomName(16);
$this->drupalPost('node/add/page', $edit, t('Save'));
// Check that the post information is displayed.
- $node = $this->drupalGetNodeByTitle($edit['title']);
+ $node = $this->drupalGetNodeByTitle($edit["title[$langcode][0][value]"]);
$this->assertNoRaw('<span class="submitted">', t('Post information is not displayed.'));
}
}
@@ -792,7 +798,7 @@ class NodeSaveTestCase extends DrupalWebTestCase {
$test_nid = $max_nid + mt_rand(1000, 1000000);
$title = $this->randomName(8);
$node = array(
- 'title' => $title,
+ 'title' => array(FIELD_LANGUAGE_NONE => array(array('value' => $title))),
'body' => array(FIELD_LANGUAGE_NONE => array(array('value' => $this->randomName(32)))),
'uid' => $this->web_user->uid,
'type' => 'article',
@@ -966,7 +972,7 @@ class NodeAdminTestCase extends DrupalWebTestCase {
$node3 = $this->drupalCreateNode(array('type' => 'page'));
$this->drupalGet('admin/content');
- $this->assertText($node1->title, t('Node appears on the node administration listing.'));
+ $this->assertText($node1->title[FIELD_LANGUAGE_NONE][0]['value'], t('Node appears on the node administration listing.'));
// Filter the node listing by status.
$edit = array(
@@ -975,8 +981,8 @@ class NodeAdminTestCase extends DrupalWebTestCase {
);
$this->drupalPost('admin/content', $edit, t('Filter'));
$this->assertRaw(t('<strong>%type</strong> is <strong>%value</strong>', array('%type' => t('status'), '%value' => t('published'))), t('The node administration listing is filtered by status.'));
- $this->assertText($node1->title, t('Published node appears on the node administration listing.'));
- $this->assertNoText($node2->title, t('Unpublished node does not appear on the node administration listing.'));
+ $this->assertText($node1->title[FIELD_LANGUAGE_NONE][0]['value'], t('Published node appears on the node administration listing.'));
+ $this->assertNoText($node2->title[FIELD_LANGUAGE_NONE][0]['value'], t('Unpublished node does not appear on the node administration listing.'));
// Filter the node listing by content type.
$edit = array(
@@ -986,7 +992,53 @@ class NodeAdminTestCase extends DrupalWebTestCase {
$this->drupalPost('admin/content', $edit, t('Refine'));
$this->assertRaw(t('<strong>%type</strong> is <strong>%value</strong>', array('%type' => t('status'), '%value' => t('published'))), t('The node administration listing is filtered by status.'));
$this->assertRaw(t('<strong>%type</strong> is <strong>%value</strong>', array('%type' => t('type'), '%value' => 'Article')), t('The node administration listing is filtered by content type.'));
- $this->assertText($node1->title, t('Article node appears on the node administration listing.'));
- $this->assertNoText($node3->title, t('Page node does not appear on the node administration listing.'));
+ $this->assertText($node1->title[FIELD_LANGUAGE_NONE][0]['value'], t('Article node appears on the node administration listing.'));
+ $this->assertNoText($node3->title[FIELD_LANGUAGE_NONE][0]['value'], t('Page node does not appear on the node administration listing.'));
+ }
+}
+
+/**
+ * Test node title.
+ */
+class NodeTitleTestCase extends DrupalWebTestCase {
+ protected $admin_user;
+
+ public static function getInfo() {
+ return array(
+ 'name' => 'Node title',
+ 'description' => 'Test node title.',
+ 'group' => 'Node'
+ );
+ }
+
+ function setUp() {
+ parent::setUp();
+ $this->admin_user = $this->drupalCreateUser(array('administer nodes', 'create article content', 'create page content'));
+ $this->drupalLogin($this->admin_user);
+ }
+
+ /**
+ * Create one node and test if the node title has the correct value.
+ */
+ function testNodeTitle() {
+ // Create page content with title
+ $settings = array(
+ 'title' => array(FIELD_LANGUAGE_NONE => array(array('value' => $this->randomName(8)))),
+ );
+ $node = $this->drupalCreateNode($settings);
+
+ // Test <title> tag.
+ $this->drupalGet("node/$node->nid");
+ $xpath = '//title';
+ $this->assertEqual(current($this->xpath($xpath)), $node->title[FIELD_LANGUAGE_NONE][0]['value'] .' | Drupal', 'Page title is equal to node title.', 'Node');
+
+ // Test breadcrumb in comment preview.
+ $this->drupalGet("comment/reply/$node->nid");
+ $xpath = '//div[@class="breadcrumb"]/a[last()]';
+ $this->assertEqual(current($this->xpath($xpath)), $node->title[FIELD_LANGUAGE_NONE][0]['value'], 'Node breadcrumb is equal to node title.', 'Node');
+
+ // Test node title in comment preview.
+ $xpath = '//div[@id="node-'. $node->nid .'"]/h2/a';
+ $this->assertEqual(current($this->xpath($xpath)), $node->title[FIELD_LANGUAGE_NONE][0]['value'], 'Node preview title is equal to node title.', 'Node');
}
}