You are here

function Faq_AskAccessTestClass::testFaqAccess in FAQ_Ask 7

File

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

Faq_AskAccessTestClass

Code

function testFaqAccess() {

  // Verify that anonymous user has no access to the faq page
  $this
    ->faqVerifyNoAccess('faq-page');

  // Create and login user
  $normal_user = $this
    ->drupalCreateUser();
  $this
    ->drupalLogin($normal_user);

  // Verify that logged in user has no access to the faq page
  $this
    ->faqVerifyNoAccess('faq-page');
  $this
    ->drupalLogout();
  $view_faq_user = $this
    ->drupalCreateUser(array(
    'view faq page',
  ));
  $this
    ->drupalLogin($view_faq_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.'));

  /* Issue #161406: Categories not included in the FAQ list are showing up on the Expert Grid
   * Verify that only the selected categories are visible in the experts page
   */
  $this
    ->drupalLogin($this->admin_user);
  $oldvocabvid = $this->vocabulary->vid;
  $terms = array();

  // Load all the terms from the vocabulary we're not supposed to see
  foreach (taxonomy_term_load_multiple(array(), array(
    'vid' => $oldvocabvid,
  )) as $obj) {
    $terms[] = $obj->name;
  }
  $this
    ->setupTaxonomy();

  // Save the old vocabulary and create another one
  // faq_omit_vocabulary[1]
  // Enable most recent vocab, but not the old one
  $settings = array(
    'faq_omit_vocabulary[' . $oldvocabvid . ']' => TRUE,
    'faq_omit_vocabulary[' . $this->vocabulary->vid . ']' => FALSE,
  );

  // Apply the setting
  $this
    ->drupalPost('admin/config/content/faq/categories', $settings, t('Save configuration'));

  // faq_ask_vocabularies[]
  $settings = array(
    'faq_ask_vocabularies[]' => array(
      $this->vocabulary->vid,
    ),
  );

  // Enable new vocabulary only
  $this
    ->setFaqAskSettings($settings);

  // The terms from the old vocab should not be available
  $this
    ->pass('<pre>' . print_r($terms, TRUE) . '</pre>');
  foreach ($terms as $term) {
    $this
      ->assertNoText($term, t('Term @term is not visible on the experts page', array(
      '@term' => $term,
    )));
  }

  // The terms from the new vocab should be available
  $terms = array();

  // Reset terms list
  foreach (taxonomy_term_load_multiple(array(), array(
    'vid' => $this->vocabulary->vid,
  )) as $obj) {
    $terms[] = $obj->name;
  }
  $this
    ->pass('<pre>' . print_r($terms, TRUE) . '</pre>');
  foreach ($terms as $term) {
    $this
      ->assertText($term, t('Term @term is visible on the experts page', array(
      '@term' => $term,
    )));
  }
}