You are here

public function SearchByPageEnvironmentTest::testEnvironments in Search by Page 6

Same name and namespace in other branches
  1. 7 tests/search_by_page.test \SearchByPageEnvironmentTest::testEnvironments()

Tests that environment settings are working.

File

tests/search_by_page.test, line 310
Tests for the Search by Page module. By Jennifer Hodgdon of Poplar ProductivityWare, www.poplarware.com

Class

SearchByPageEnvironmentTest
Basic search environments test.

Code

public function testEnvironments() {

  // Test that user1 and user2 can only see their pages.
  // And that the pages have correct text on them.
  // User 1 - has permission for env 1 only
  $this
    ->drupalLogin($this->user1);
  $this
    ->drupalGet($this->envinfo1['page_path']);

  // The assertTitle function is lame, because it includes the site name...
  $this
    ->assertTrue(strstr(current($this
    ->xpath('//title')), $this->envinfo1['page_title']), 'Page title contains correct string');
  $this
    ->assertText($this->envinfo1['page_title'], 'Page title is visible');
  $this
    ->assertText($this->envinfo1['field_label'], 'Field label is correct');
  $this
    ->assertRaw($this->envinfo1['button_label'], 'Button label is correct');
  $this
    ->drupalGet($this->envinfo2['page_path']);
  $this
    ->assertText('Access denied', 'Access denied to user without permission');

  // User 2 - has permission for env 2 only
  $this
    ->drupalLogin($this->user2);
  $this
    ->drupalGet($this->envinfo2['page_path']);
  $this
    ->assertTrue(strstr(current($this
    ->xpath('//title')), $this->envinfo2['page_title']), 'Page title contains correct string');
  $this
    ->assertText($this->envinfo2['page_title'], 'Page title is visible');
  $this
    ->assertText($this->envinfo2['field_label'], 'Field label is correct');
  $this
    ->assertRaw($this->envinfo2['button_label'], 'Button label is correct');
  $this
    ->drupalGet($this->envinfo1['page_path']);
  $this
    ->assertText(t('denied'), 'Access denied to user without permission');

  // Test that blocks exist and have right titles when displayed.
  $this
    ->drupalLogin($this->superuser);
  $this
    ->drupalGet('admin/build/block');
  $this
    ->assertText(t('Search by page @env', array(
    '@env' => $this->envinfo1['environment_name'],
  )), "Block 1 exists");
  $this
    ->assertText(t('Search by page @env', array(
    '@env' => $this->envinfo1['environment_name'],
  )), "Block 2 exists");

  // Turn on both blocks.
  $this
    ->drupalPost('admin/build/block', array(
    'search_by_page_' . $this->envid1 . '[region]' => 'content',
    'search_by_page_' . $this->envid2 . '[region]' => 'content',
  ), 'Save blocks');

  // Verify block titles appear.
  $this
    ->drupalGet('admin');
  $this
    ->assertText($this->envinfo1['block_title'], 'Block title is correct');
  $this
    ->assertText($this->envinfo2['block_title'], 'Block title is correct');
}