function FaqAskCRUDTestClass::testCreateFaqAskQuestion in FAQ_Ask 6.2
File
- ./
faq_ask.test, line 413 - 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 testCreateFaqAskQuestion() {
// Check anonymous creation of questions
// Change rights for anonymous user - Enable asking a question
$this
->drupalLogin($this->admin_user);
$edit = array(
'1[create faq]' => TRUE,
'1[ask question]' => TRUE,
);
$this
->drupalPost('admin/user/permissions', $edit, 'Save permissions');
$this
->drupalGet('admin/user/permissions');
// Set up faq-ask
// Done with admin user
$this
->drupalLogout();
// Anonymous user have access
$this
->drupalGet('faq_ask');
$this
->assertText(t('Ask a Question'), t('Ask a Question page is available for anonymous users.'));
$this
->assertNoFieldByName('body', $value = '', 'Body field (answer) is not visible in form.');
// Verify preloaded term
$this
->drupalGet('faq_ask/' . '1');
// Load url with term 1
$this
->assertFieldByName('taxonomy[tags][1]', $this->term1['name'], 'Term preloaded on question form.');
// Fill in the Create FAQ node 1 form and post it
$this->faq3 = array();
$this->faq3['title'] = $this
->randomName(8);
$this->faq3['taxonomy[tags][1]'] = $this->term1['name'];
// Add existing term
$this->faq3['detailed_question'] = $this
->randomName(16);
$this->faq3['faq_email'] = $this
->randomName(8) . '@' . $this
->randomName(8) . '.com';
$this
->drupalPost('faq_ask', $this->faq3, t('Preview'));
// Preview first
// Verify preview
$this
->assertText('Not answered yet.', 'Not answered yet text shown.');
$this
->assertLink($this->faq3['title'], $index = 0, 'Link to question found');
// Verify field content is still available
$this
->assertFieldByName('title', $this->faq3['title'], 'Title field content kept after preview.');
$this
->assertFieldByName('taxonomy[tags][1]', $this->faq3['taxonomy[tags][1]'], 'Taxonomy term field content kept after preview.');
$this
->assertFieldByName('detailed_question', $this->faq3['detailed_question'], 'Detailed question field content kept after preview.');
$this
->assertFieldByName('faq_email', $this->faq3['faq_email'], 'E-mail field content kept after preview.');
// Post and save the question
$this
->drupalPost('faq_ask', $this->faq3, t('Save'));
// Preview first
// Check that new FAQ node has actually been created
$this
->assertText(t('FAQ @title has been created.', array(
'@title' => $this->faq3['title'],
)));
// Check logged in user with rights
$this
->drupalLogin($this->faq_asker);
// Verify that the Ask a Question page is visible and available but empty
$this
->drupalGet('faq_ask');
$this
->assertText(t('Ask a Question'), t('Ask a Question page is available for view faq page permissions.'));
// Fill in the Create FAQ node 2 form and post it
$this->faq4 = array();
$this->faq4['title'] = $this
->randomName(8);
$this->faq4['taxonomy[tags][1]'] = $this
->randomName(8);
// Add new term
$this->faq4['detailed_question'] = $this
->randomName(16);
$this
->drupalPost('faq_ask', $this->faq4, t('Save'));
// Check that new FAQ node has actually been created
$this
->assertText(t('FAQ @title has been created.', array(
'@title' => $this->faq4['title'],
)));
$this
->drupalGet('faq_ask/unanswered');
$this
->drupalLogout();
// Verify usage of taxonomy - One to each expert
// Verify that message is sent on cron run
// $this->cronRun(); // Does not work with Simpletest 6.x
$mails = $this
->drupalGetMails();
foreach ($mails as $mail) {
$this
->pass('<pre>' . print_r($mail, TRUE) . '</pre>');
}
}