You are here

public function IntegrationTest::testRegression2720953 in Views Entity Reference Filter 8

Tests that a user can only select items they have access to.

File

tests/src/Functional/IntegrationTest.php, line 161

Class

IntegrationTest
Tests the integration between Views Entity Reference Filter and Views.

Namespace

Drupal\Tests\verf\Functional

Code

public function testRegression2720953() {
  $published = $this
    ->drupalCreateNode([
    'type' => $this->nodeType
      ->id(),
  ]);
  $published
    ->setOwner($this->author)
    ->save();
  $unpublished = $this
    ->drupalCreateNode([
    'type' => $this->nodeType
      ->id(),
    'status' => NodeInterface::NOT_PUBLISHED,
  ]);
  $unpublished
    ->setOwner($this->author)
    ->save();
  $referencingPublished = $this
    ->drupalCreateNode([
    'type' => $this->nodeType
      ->id(),
    'field_refs' => [
      [
        'target_id' => $published
          ->id(),
      ],
    ],
  ]);
  $referencingUnpublished = $this
    ->drupalCreateNode([
    'type' => $this->nodeType
      ->id(),
    'field_refs' => [
      [
        'target_id' => $unpublished
          ->id(),
      ],
    ],
  ]);
  $this
    ->drupalLogin($this->admin);
  $this
    ->drupalGet('verftest');
  $this
    ->assertSelectOptionCanBeSelected('Refs (VERF selector)', $published
    ->getTitle());
  $this
    ->assertSelectOptionCanBeSelected('Refs (VERF selector)', $unpublished
    ->getTitle());
  $this
    ->drupalLogin($this->author);
  $this
    ->drupalGet('verftest');
  $this
    ->assertSelectOptionCanBeSelected('Refs (VERF selector)', $published
    ->getTitle());
  $this
    ->assertSelectOptionCanBeSelected('Refs (VERF selector)', $unpublished
    ->getTitle());
  $this
    ->drupalLogout();
  $this
    ->drupalGet('verftest');
  $this
    ->assertSelectOptionCanBeSelected('Refs (VERF selector)', $published
    ->getTitle());
  $this
    ->assertSelectOptionCanBeSelected('Refs (VERF selector)', '- Restricted access -');
  $this
    ->assertSelectOptionCanNotBeSelected('Refs (VERF selector)', $unpublished
    ->getTitle());
}