You are here

function CreateFaqTestCase::testFaqCreate in Frequently Asked Questions 7

Same name and namespace in other branches
  1. 7.2 faq.test \CreateFaqTestCase::testFaqCreate()

Test creating a FAQ node

This test creates a faq with detailed question shown and labeled questions and answers

File

./faq.test, line 213
Test FAQ functionality Base test class. All tests inherits this one. Hugely based on code from the test file block.test by boombatower

Class

CreateFaqTestCase

Code

function testFaqCreate() {

  // Create and log in user with create FAQ permissions
  $this
    ->drupalLogin($this->admin_user);

  // Show the detailed question
  $this
    ->drupalGet('admin/config/content/faq/questions');

  // Set faq to allow long question text and labeled questions and answers
  $this
    ->drupalPost('admin/config/content/faq/questions', array(
    'faq_question_long_form' => '1',
    'faq_qa_mark' => '1',
  ), t('Save configuration'));
  $this
    ->drupalPost('admin/config/content/faq/questions', array(
    'faq_question_length' => 'both',
  ), t('Save configuration'));
  $this->afaq_user = $this
    ->drupalCreateUser(array(
    'create faq content',
    'view faq page',
  ));
  $this
    ->drupalLogin($this->afaq_user);

  // Verify that the faq page is visible and available but empty
  $this
    ->drupalGet(_faq_path());
  $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["field_detailed_question[{$langcode}][0][value]"] = $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'],
  )));

  // Check that faq is found on the correct taxonomy term page too
  $this
    ->drupalGet('taxonomy/term/' . $this->term->tid);
  $this
    ->assertText(t('@title', 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["field_detailed_question[{$langcode}][0][value]"] = $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_path());

  // 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_path());
  $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["field_detailed_question[{$langcode}][0][value]"]), t('Detailed question visible'));

  // Dependant on the question setting
  $this
    ->assertText(t($this->faq1["body[{$langcode}][0][value]"]), t('Answer visible'));

  // 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_path());
  $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
}