public function ViewsFieldTest::testFieldAndFilter in Workbench Access 8
Tests field and filter.
File
- tests/
src/ Functional/ ViewsFieldTest.php, line 139
Class
- ViewsFieldTest
- Defines a class for testing workbench access views.
Namespace
Drupal\Tests\workbench_access\FunctionalCode
public function testFieldAndFilter() {
$this
->drupalLogin($this->user);
$this
->drupalGet('admin/content/sections');
$assert = $this
->assertSession();
foreach ($this->terms as $section => $term) {
$assert
->elementExists('css', '.views-row:contains("' . $term
->label() . '")');
$assert
->elementExists('css', '.views-row:contains("' . $section . ' node 1' . '")');
}
// Now filter the page.
$this
->drupalGet('admin/content/sections', [
'query' => [
'section' => $this->terms['Some section']
->id(),
],
]);
$assert
->pageTextContains('Some section node 1');
$assert
->pageTextContains('Some section node 2');
$assert
->elementNotExists('css', '.views-row:contains("Another section")');
$assert
->elementNotExists('css', '.views-row:contains("More sections")');
$this
->drupalGet('admin/people/sections');
$row = $assert
->elementExists('css', '.views-row:contains("' . $this->user
->label() . '")');
// User 1 has all sections.
foreach ($this->terms as $section => $term) {
$assert
->elementExists('css', '.views-row:contains("' . $section . '")', $row);
}
// User 2 only has one.
$row = $assert
->elementExists('css', '.views-row:contains("' . $this->user2
->label() . '")');
$assert
->elementExists('css', '.views-row:contains("Some section")', $row);
// Now filter.
$this
->drupalGet('admin/people/sections', [
'query' => [
'section' => $this->terms['Some section']
->id(),
],
]);
$assert
->elementExists('css', '.views-row:contains("' . $this->user
->label() . '")');
$assert
->elementExists('css', '.views-row:contains("' . $this->user2
->label() . '")');
$this
->drupalGet('admin/people/sections', [
'query' => [
'section' => $this->terms['Another section']
->id(),
],
]);
$assert
->elementExists('css', '.views-row:contains("' . $this->user
->label() . '")');
$assert
->elementNotExists('css', '.views-row:contains("' . $this->user2
->label() . '")');
// Now test as user 2 who only has access to the first section.
$this
->drupalLogin($this->user2);
$this
->drupalGet('admin/content/sections');
$assert
->pageTextContains('Some section node 1');
$assert
->pageTextContains('Some section node 2');
$assert
->elementNotExists('css', '.views-row:contains("Another section")');
$assert
->elementNotExists('css', '.views-row:contains("More sections")');
}