You are here

function FaqAskCRUDTestClass::testVerifyExpertAccess in FAQ_Ask 6.2

File

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

Class

FaqAskCRUDTestClass

Code

function testVerifyExpertAccess() {

  // Add a new expert
  $new_expert = $this
    ->drupalCreateUser(array(
    'view faq page',
    'edit faq',
    'access content',
    'answer question',
  ));
  $this
    ->drupalLogin($new_expert);
  $this
    ->drupalLogin($this->admin_user);

  //Change name and assign expert role to new expert user
  $this
    ->drupalGet('user/' . $new_expert->uid . '/edit');
  $edit = array(
    'roles[' . $this->expert_role . ']' => $this->expert_role,
    'pass[pass1]' => 'password',
    'pass[pass2]' => 'password',
  );
  $this
    ->drupalPost('user/' . $new_expert->uid . '/edit', $edit, t('Save'));
  $this
    ->drupalGet('user/' . $new_expert->uid . '/edit');

  // Set up new expert on settings page for faq_ask
  $this
    ->drupalGet('admin/settings/faq/ask');
  $edit = array(
    'faq_ask_notify' => TRUE,
    'faq_ask_asker_notify' => TRUE,
    'faq_expert_role[]' => array(
      $this->faq_expert->uid,
      $new_expert->uid,
    ),
  );
  $this
    ->drupalPost('admin/settings/faq/ask', $edit, 'Save configuration');
  $edit['expert_' . $new_expert->uid . '_2'] = TRUE;

  // Add term 2 for new expert
  $edit['expert_1_2'] = '0';

  // Remove term 2 for admin (user1)
  $this
    ->drupalPost('admin/settings/faq/ask', $edit, 'Save configuration');

  // Post a new question
  $this
    ->drupalLogin($this->faq_asker);

  // Fill in the Create FAQ node 1 form and post it
  $this->faq = array();
  $this->faq['title'] = $this
    ->randomName(8);
  $this->faq['taxonomy[tags][1]'] = $this->term2['name'];

  // Add existing term
  $this->faq['detailed_question'] = $this
    ->randomName(16);

  //$this->faq['faq_notify'] = TRUE;
  $this
    ->drupalPost('faq_ask', $this->faq, t('Save'));

  // Preview first
  // Check that new FAQ node has actually been created
  $this
    ->assertText(t('FAQ @title has been created.', array(
    '@title' => $this->faq['title'],
  )));

  // Verify that new expert can view the new question
  $this
    ->drupalLogin($new_expert);
  $this
    ->drupalGet('faq_ask/unanswered');
  $this
    ->assertLink($this->faq['title'], $index = 0, t('Link to question @q found when logged in as user @u assigned to term @t', array(
    '@u' => $new_expert->name,
    '@q' => $this->faq['title'],
    '@t' => $this->term2['name'],
  )));
  $mails = $this
    ->drupalGetMails();
  foreach ($mails as $mail) {
    $this
      ->pass('<pre>' . print_r($mail, TRUE) . '</pre>');
  }
  $mail = $mails['0'];
  $this
    ->assertEqual($mail['subject'], 'You have a question waiting on Drupal', 'Notification e-mail found.');
  $this
    ->assertMail("subject", "You have a question waiting on Drupal", 'The last message subject was "You have a question waiting on Drupal"');
  $this
    ->assertMail('to', $new_expert->mail, 'The last message was sent to the correct expert.');
}