public function SearchByPageEnvironmentTest::testEnvironments in Search by Page 8
Tests that environment settings are working.
File
- tests/
src/ Functional/ SearchByPageEnvironmentTest.php, line 71 - Tests for the Search by Page module. By Jennifer Hodgdon of Poplar ProductivityWare, www.poplarware.com
Class
- SearchByPageEnvironmentTest
- Basic search environments test.
Namespace
Drupal\Tests\search_by_page\FunctionalCode
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/structure/block');
$this
->assertText(t('Search by page @env', [
'@env' => $this->envinfo1['environment_name'],
]), "Block 1 exists");
$this
->assertText(t('Search by page @env', [
'@env' => $this->envinfo1['environment_name'],
]), "Block 2 exists");
// Turn on both blocks.
$this
->drupalPostForm('admin/structure/block', [
'blocks[search_by_page_' . $this->envid1 . '][region]' => 'content',
'blocks[search_by_page_' . $this->envid2 . '][region]' => 'content',
], 'Save blocks');
// Verify block titles appear.
$this
->drupalGet('<front>');
$this
->assertText($this->envinfo1['block_title'], 'Block title is correct');
$this
->assertText($this->envinfo2['block_title'], 'Block title is correct');
}