You are here

public function ViewsFieldMenuTest::testFieldAndFilter in Workbench Access 8

Tests field and filter.

File

tests/src/Functional/ViewsFieldMenuTest.php, line 143

Class

ViewsFieldMenuTest
Defines a class for testing workbench access views.

Namespace

Drupal\Tests\workbench_access\Functional

Code

public function testFieldAndFilter() {
  $this
    ->drupalLogin($this->user);
  $this
    ->drupalGet('admin/content/sections/menu');
  $assert = $this
    ->assertSession();
  foreach ($this->links as $section => $link) {
    $row = $assert
      ->elementExists('css', '.views-row:contains("' . $link
      ->label() . '")');
    $assert
      ->pageTextContains($section . ' node 1');
  }

  // Now filter the page.
  $this
    ->drupalGet('admin/content/sections/menu', [
    'query' => [
      'workbench_access_section' => $this->links['Some section']
        ->getPluginId(),
    ],
  ]);
  $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/menu');
  $row = $assert
    ->elementExists('css', '.views-row:contains("' . $this->user
    ->label() . '")');

  // User 1 has all sections.
  foreach ($this->links as $section => $link) {
    $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/menu', [
    'query' => [
      'section' => $this->links['Some section']
        ->getPluginId(),
    ],
  ]);
  $assert
    ->elementExists('css', '.views-row:contains("' . $this->user
    ->label() . '")');
  $assert
    ->elementExists('css', '.views-row:contains("' . $this->user2
    ->label() . '")');
  $this
    ->drupalGet('admin/people/sections/menu', [
    'query' => [
      'section' => $this->links['Another section']
        ->getPluginId(),
    ],
  ]);
  $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/menu');
  $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")');
}