public function CRAUDFaqTestCase::testFaqCreate in Frequently Asked Questions 7
Same name and namespace in other branches
- 7.2 faq.test \CRAUDFaqTestCase::testFaqCreate()
Test creating an FAQ and verify its status
File
- ./
faq.test, line 323 - 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 testFaqCreate() {
// Verify that logged in user has no access to the faq page
$this
->faqVerifyNoAccess(_faq_path());
// Log in user with create FAQ permissions
$this
->drupalLogin($this->faq_user);
// Create a FAQ node.
$edit = array();
$edit['title'] = $this
->randomName(8);
$edit[$this->instance['field_name'] . '[' . LANGUAGE_NONE . ']'] = $this
->randomName(8);
$edit['field_detailed_question[' . LANGUAGE_NONE . '][0][value]'] = $this
->randomName(64);
$edit['body[' . LANGUAGE_NONE . '][0][value]'] = $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);
$this
->drupalLogout();
// Verify that anonymous user has no access to the unanswered node display
// $this->faqVerifyNoAccess('node/' . $node->nid);
$this
->drupalGet('node/' . $node->nid . '/edit');
// Open edit page with node
// $this->assertResponse(200);
// Create and log in user with view FAQ permissions
$faq_view_user = $this
->drupalCreateUser(array(
'view faq page',
));
$this
->drupalLogin($faq_view_user);
// Verify visibility on faq page
$this
->drupalGet(_faq_path());
// Load faq page
$this
->assertText($edit['title']);
// Node should be listed here
$this
->drupalGet('node/' . $node->nid);
// It should also be possible to open the node directly
// Update FAQ
// Log in user with answer question. Must also have edit any faq content and view faq page permissions.
$this
->drupalLogin($this->faq_user);
$edit2['title'] = 'title-' . $this
->randomName(8);
$edit2['body[' . LANGUAGE_NONE . '][0][value]'] = 'body-' . $this
->randomName(64);
$this
->drupalPost('node/' . $node->nid . '/edit', $edit2, 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[' . LANGUAGE_NONE . '][0][value]'], 'Body has changed');
// Delete FAQ
// Try deleting faq by edit faq permission
$this
->drupalPost('node/' . $node->nid . '/edit', array(), t('Delete'));
// Log in user with delete FAQ permissions
$this
->drupalLogin($this->admin_user);
$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'],
)));
}