You are here

public function UserRoleTest::testPrepareValueNonAllowedRole in Feeds 8.3

Tests referencing a non-allowed role.

@covers ::prepareValue @covers ::findEntity

File

tests/src/Unit/Feeds/Target/UserRoleTest.php, line 152

Class

UserRoleTest
@coversDefaultClass \Drupal\feeds\Feeds\Target\UserRole @group feeds

Namespace

Drupal\Tests\feeds\Unit\Feeds\Target

Code

public function testPrepareValueNonAllowedRole() {
  $this->entityFinder
    ->findEntities($this
    ->getReferencableEntityTypeId(), 'label', 'Foo')
    ->willReturn([
    'foo',
  ])
    ->shouldBeCalled();

  // The 'Foo' role may not be used.
  $target_plugin = $this
    ->createTargetPluginInstance([
    'allowed_roles' => [
      'foo' => FALSE,
    ],
  ]);
  $method = $this
    ->getProtectedClosure($target_plugin, 'prepareValue');
  $values = [
    'target_id' => 'Foo',
  ];
  $this
    ->expectException(TargetValidationException::class, 'The role <em class=\\"placeholder\\">foo</em> may not be referenced.');
  $method(0, $values);
}