public function CRUDFaqTestCase::testFaqEditDelete in Frequently Asked Questions 6
Test editing and deleting of an FAQ node.
File
- ./
faq.test, line 247 - Test FAQ functionality Base test class. All tests inherits this one. Hugely based on code from the test file block.test by boombatower
Class
Code
public function testFaqEditDelete() {
// Log in user with create FAQ permissions
$this
->drupalLogin($this->faq_user);
// Create a FAQ node.
$edit = array();
$edit['title'] = $this
->randomName(8);
$edit['taxonomy[tags][' . $this->taxonomy['id'] . ']'] = $this
->randomName(8);
$edit['detailed_question'] = $this
->randomName(64);
$edit['body'] = $this
->randomString(264);
$this
->drupalPost('node/add/faq', $edit, t('Save'));
$this
->assertText(t('FAQ @title has been created.', array(
'@title' => $edit['title'],
)));
// Check status for FAQ node - should be published
$node = $this
->drupalGetNodeByTitle($edit['title']);
$this
->assertTrue($node->status);
// Update FAQ
$this
->drupalGet('node/' . $node->nid . '/edit');
// Open edit page with node
$edit2['title'] = 'title-' . $this
->randomName(8);
$edit2['body'] = 'body-' . $this
->randomName(64);
$this
->drupalPost('node/' . $node->nid . '/edit', array(
'title' => $edit2['title'],
'body' => $edit2['body'],
), t('Save'));
$this
->assertText(t('FAQ @title has been updated.', array(
'@title' => $edit2['title'],
)));
$this
->assertText($edit2['title'], 'Title has changed');
$this
->assertText($edit2['body'], 'Body has changed');
// Delete FAQ
$this
->drupalPost('node/' . $node->nid . '/edit', array(), t('Delete'));
$this
->assertText(t('Are you sure you want to delete @title?', array(
'@title' => $edit2['title'],
)));
$this
->drupalPost('node/' . $node->nid . '/delete', array(), t('Delete'));
$this
->assertText(t('FAQ @title has been deleted.', array(
'@title' => $edit2['title'],
)));
}