You are here

function BlockFaq_AskTestCase::testAskQuestionBlock in FAQ_Ask 7

Ask a question via the block Does this: 1. Changes the block title on the ask a question block 2. Swithes it on 3. Posts a question via the block form using an asker user 4. Turns unanswered block off 5. Verifies question visibility to the answer role 6. Answers the question 7. Hides the question block 8. Enables the question block again

File

./faq_ask.test, line 863
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

BlockFaq_AskTestCase

Code

function testAskQuestionBlock() {
  $this
    ->drupalLogin($this->admin_user);

  // Select the Ask a Question block to be configured and moved.
  $block = array();
  $block['module'] = 'faq_ask';
  $block['delta'] = 'ask_a_question';

  // Ask a Question Block
  $block['title'] = $this
    ->randomName(8);

  // Set block title to confirm that interface works and override any custom titles.
  $this
    ->drupalPost('admin/structure/block/manage/' . $block['module'] . '/' . $block['delta'] . '/' . 'configure', array(
    'title' => $block['title'],
  ), t('Save block'));
  $this
    ->assertText(t('The block configuration has been saved.'), t('Block title set.'));
  $bid = db_query_range("SELECT * FROM {block} WHERE module = '%s'", 0, 1, array(
    $block['module'],
    $block['delta'],
  ))
    ->fetchObject();

  // Check to see if the block was created by checking that it's in the database.
  $this
    ->assertNotNull($bid, t('Block found in database'));

  // Swich off User login block
  $this
    ->turnBlockOff('user', 'login');

  // Set the created block to a specific region.
  $this
    ->turnBlockOn('faq_ask', 'ask_a_question');

  // Confirm that the block is being displayed.
  $this
    ->drupalLogin($this->ask_user);
  $this
    ->assertText(t($block['title']), t('Block successfully being displayed on the page.'));

  // Show front page of site
  $this
    ->drupalGet('node');

  // Fill in a form and save
  $edit = array();
  $edit['title'] = 'Q-' . $this
    ->randomName(8);
  $edit['detailed_question'] = 'DetailedQ-' . $this
    ->randomName(16);
  $edit['taxonomy_' . $this->vocabulary->machine_name . '[und]'] = $this->term->name;
  $this
    ->drupalPost('node', $edit, t('Save'));

  // Check that the question is posted and unanswered
  $this
    ->assertText(t('FAQ @title has been created.', array(
    '@title' => $edit['title'],
  )));
  $this
    ->assertText(t('Your question has been submitted. It will appear in the FAQ listing as soon as it has been answered.'));

  // Check status for FAQ node - should be not published
  $node = $this
    ->drupalGetNodeByTitle($edit['title']);
  $this
    ->assertFalse($node->status);

  // Turn unanswered block off
  $this
    ->drupalLogin($this->admin_user);
  $this
    ->turnBlockOff('faq_ask', 'unanswered');

  // FAQ node should not be visible for user with view faq permissions
  $this
    ->drupalLogin($this->ask_user);
  $this
    ->drupalGet("faq-page");

  // Load faq page
  $this
    ->assertNoText($edit['title']);

  // Node should not be listed here
  $this
    ->drupalGet('node/' . $node->nid);

  // But should be possible to open the node directly by the author who created it
  $this
    ->assertResponse(200);

  // Turn on unanswered block;
  $this
    ->drupalLogin($this->admin_user);
  $this
    ->turnBlockOn('faq_ask', 'unanswered');
  $this
    ->turnBlockOff('faq_ask', 'ask_a_question');
  $question = $this
    ->askQuestion($this->ask_user);

  // Log in user with answer question. Must also have edit faq and view faq page permission
  $this
    ->drupalLogin($this->answer_user);
  $this
    ->assertText('Unanswered questions', t('Unanswered block is visible'));
  $this
    ->assertText($edit['title'], t('Title of first question visible'));
  $this
    ->assertText($question['title'], t('Title of second question visible'));

  // Open unanswered question
  // Verify that logged in 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);

  // Select question
  $this
    ->clickLink($edit['title']);

  // Click the node name in unanswered questions box
  // Post an answer to the question
  $edit['answer'] = $this
    ->randomName(64);
  $this
    ->drupalPost(NULL, array(
    'body[und][0][value]' => $edit['answer'],
  ), t('Save'));

  // Check status for FAQ node - should now be published
  $q = $this
    ->drupalGetNodeByTitle($edit['title']);

  // Create and log in user with view FAQ permissions
  $faq_view_user = $this
    ->drupalCreateUser(array(
    'view faq page',
    'access content',
  ));
  $this
    ->drupalLogin($faq_view_user);

  // Verify visibility on faq page
  $this
    ->drupalGet("faq-page");

  // Load faq page
  $this
    ->assertText($edit['title'], t('Question title found on FAQ-Page'));

  // Node should be listed here
  $this
    ->assertText($edit['detailed_question'], t('Detailed question text found on FAQ-Page'));

  // Node should be listed here
  $this
    ->assertText($edit['answer'], t('Answer to question found on FAQ-Page'));

  // Node should be listed here
  $this
    ->drupalGet('node/' . $node->nid);

  // It should also be possible to open the node directly
  // Turn off the block
  $this
    ->drupalLogin($this->admin_user);
  $this
    ->turnBlockOff('faq_ask', 'ask_a_question');
  $this
    ->drupalLogin($faq_view_user);

  // Confirm that the block was moved to the proper region.
  $this
    ->assertNoText(t($block['title']), t('Block no longer appears on page.'));

  // For convenience of developers, put the navigation block back.
  $this
    ->drupalLogin($this->admin_user);
  $this
    ->turnBlockOn('faq_ask', 'ask_a_question');
  $this
    ->drupalLogin($faq_view_user);
}