function CreateFaqTestCase::testFaqCreate in Frequently Asked Questions 7.2
Same name and namespace in other branches
- 7 faq.test \CreateFaqTestCase::testFaqCreate()
Test creating a FAQ node
File
- ./
faq.test, line 211 - 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
function testFaqCreate() {
// Create and log in user with create FAQ permissions
$this->admin_user = $this
->drupalCreateUser(array(
'create faq content',
'view faq page',
));
$this
->drupalLogin($this->admin_user);
// Verify that the faq page is visible and available but empty
$this
->drupalGet('faq-page');
$this
->assertText(t('Frequently Asked Questions'), t('FAQ page is available for view faq page permissions.'));
// Fill in the Create FAQ node 1 form and post it
$langcode = LANGUAGE_NONE;
$this->faq1 = array();
$this->faq1['title'] = 'faq1_' . $this
->randomName(8);
$this->faq1[$this->instance['field_name'] . '[' . $langcode . ']'] = $this->term->name;
$this->faq1['detailed_question'] = $this
->randomName(16);
$this->faq1["body[{$langcode}][0][value]"] = $this
->randomName(16);
$this
->drupalPost('node/add/faq', $this->faq1, t('Save'));
// Check that new FAQ node has actually been created
$this
->assertText(t('FAQ @title has been created.', array(
'@title' => $this->faq1['title'],
)));
// Fill in the Create FAQ node 2 form and post it
$this->faq2 = array();
$this->faq2['title'] = 'faq2_' . $this
->randomName(8);
$this->faq2[$this->instance['field_name'] . '[' . $langcode . ']'] = $this
->randomName(8);
// Add new term
$this->faq2['detailed_question'] = $this
->randomName(16);
$this->faq2["body[{$langcode}][0][value]"] = $this
->randomName(16);
$this
->drupalPost('node/add/faq', $this->faq2, t('Save'));
// Check that new FAQ node has actually been created
$this
->assertText(t('FAQ @title has been created.', array(
'@title' => $this->faq2['title'],
)));
// New user
$this
->drupalLogout();
// Verify that logged in user has no access to the faq page
$this
->faqVerifyNoAccess('faq-page');
// Check that the FAQ page is available and that the correct term is listed as grouping for the new FAQ node
$view_faq_user = $this
->drupalCreateUser(array(
'view faq page',
));
$this
->drupalLogin($view_faq_user);
$this
->drupalGet('faq-page');
$this
->assertText(t('Frequently Asked Questions'), t('FAQ page is available for view faq page permissions.'));
$this
->assertText($this->faq1['title'], t('Created FAQ node 1 available on FAQ page.'));
$this
->assertText($this->faq1[$this->instance['field_name'] . '[' . $langcode . ']'], t('Term for node 1 available on FAQ page.'));
$this
->assertText($this->faq2['title'], t('Created FAQ node 2 available on FAQ page.'));
$this
->assertText($this->faq2[$this->instance['field_name'] . '[' . $langcode . ']'], t('Term for node 2 available on FAQ page.'));
// Navigate to FAQ node created on FAQ page
$this
->clickLink(t($this->faq1['title']));
$this
->assertText(t($this->faq1["body[{$langcode}][0][value]"]));
// Enable categorisation of FAQ nodes
// Create and log in user with create and administer FAQ permissions
$this->admin_user = $this
->drupalCreateUser(array(
'create faq content',
'view faq page',
'administer faq',
));
$this
->drupalLogin($this->admin_user);
// faq_use_categories
$faqcfg = array();
$faqcfg['faq_use_categories'] = '1';
// Enable categorised FAQs
$this
->drupalPost('admin/config/content/faq/categories', $faqcfg, t('Save configuration'));
$this
->drupalLogout();
$this
->drupalLogin($view_faq_user);
$this
->drupalGet('faq-page');
$this
->assertText(t('Frequently Asked Questions'), t('FAQ page is available for view faq page permissions.'));
$this
->assertText($this->faq1['title'], t('Created FAQ node 1 available on FAQ page.'));
$this
->assertText($this->faq1[$this->instance['field_name'] . '[' . $langcode . ']'], t('Term for node 1 not available on FAQ page.'));
$this
->assertText($this->faq2['title'], t('Created FAQ node 2 available on FAQ page.'));
$this
->assertText($this->faq2[$this->instance['field_name'] . '[' . $langcode . ']'], t('Term for node 2 not available on FAQ page.'));
// TODO: Add update and Delete of FAQ nodes
}