You are here

function CreateFaq_AskTestCase::testFaqCreate in FAQ_Ask 7

Test creating a FAQ node

File

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

Class

CreateFaq_AskTestCase

Code

function testFaqCreate() {

  // Create and log in user with create FAQ permissions

  //$this->admin_user = $this->drupalCreateUser(array('view faq page'));
  $this
    ->drupalLogin($this->ask_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.'));
  $this
    ->pass('<pre>' . print_r($this->term, TRUE) . '</pre>');

  // Fill in the Create FAQ node 1 form and post it
  $this->faq1 = array();
  $this->faq1['title'] = $this
    ->randomName(8);
  $this->faq1['taxonomy_' . $this->vocabulary->machine_name . '[und]'] = $this->term->name;

  // Add existing term
  $this->faq1['detailed_question'] = $this
    ->randomName(16);
  $this
    ->drupalPost('node/add/faq', $this->faq1, t('Save'));
  $this->faq1['body'] = $this
    ->randomName(16);

  // 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'] = $this
    ->randomName(8);
  $this->faq2['taxonomy_' . $this->vocabulary->machine_name . '[und]'] = $this->term->name;

  // Add existing term
  $this->faq2['detailed_question'] = $this
    ->randomName(16);
  $this
    ->drupalPost('node/add/faq', $this->faq2, t('Save'));
  $this->faq2['body'] = $this->faq1['body'];

  // Cheating a little. Same answer on both questions
  // 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
    ->assertNoText($this->faq1['title'], t('Created FAQ node 1 not yet available on FAQ page.'));
  $this
    ->assertNoText($this->faq1['taxonomy_' . $this->vocabulary->machine_name . '[und]'], t('Term for node 1 not yet  available on FAQ page.'));
  $this
    ->assertNoText($this->faq2['title'], t('Created FAQ node 2 not yet available on FAQ page.'));
  $this
    ->assertNoText($this->faq2['taxonomy_' . $this->vocabulary->machine_name . '[und]'], t('Term for node 2 not yet  available on FAQ page.'));

  // Navigate to FAQ node created on FAQ page
  $faq1_node = $this
    ->drupalGetNodeByTitle($this->faq1['title']);
  $this
    ->faqVerifyNoAccess('node/' . $faq1_node->nid);
  $faq2_node = $this
    ->drupalGetNodeByTitle($this->faq2['title']);
  $this
    ->faqVerifyNoAccess('node/' . $faq2_node->nid);

  // Verify status message when question is reassigned
  $this
    ->drupalLogin($this->admin_user);

  // Question is reassigned always
  $this
    ->setFaqAskSettings(array(
    'faq_ask_expert_own' => '2',
  ));

  // Enable categorisation of FAQ nodes
  // Log in user with Answer FAQ permissions
  $this
    ->drupalLogin($this->answer_user);

  // Answer first question
  $this
    ->drupalGet('faq_ask/unanswered');
  $this
    ->clickLink('Answer question');
  $this
    ->assertText(t('This question is being assigned to @name.', array(
    '@name' => $this->answer_user->name,
  )), t('Question assigned to expert'));
  $this
    ->drupalPost(NULL, array(
    'body[und][0][value]' => $this->faq1['body'],
  ), t('Save'));

  // Answer second question
  $this
    ->drupalGet('faq_ask/unanswered');
  $this
    ->clickLink('Answer question');
  $this
    ->drupalPost(NULL, array(
    'body[und][0][value]' => $this->faq2['body'],
  ), t('Save'));
  $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['taxonomy_' . $this->vocabulary->machine_name . '[und]'], 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['taxonomy_' . $this->vocabulary->machine_name . '[und]'], t('Term for node 2 not available on FAQ page.'));

  // TODO: Add update and Delete of FAQ nodes
}