Skip to content

Commit

Permalink
Remove deprecated call to Prophecy on phpunit
Browse files Browse the repository at this point in the history
  • Loading branch information
tbsiqueira committed Oct 31, 2022
1 parent 828cad0 commit 47517e6
Showing 1 changed file with 31 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@

namespace Drupal\entity_access_by_field\Tests;

use Prophecy\PhpUnit\ProphecyTrait;
use Drupal\Core\Session\AccountInterface;
use Drupal\node\NodeInterface;
use Drupal\Tests\UnitTestCase;
use Drupal\entity_access_by_field\EntityAccessHelper;
use Prophecy\Prophet;

/**
* Unit test of entity_access_by_field hook_node_access implementation.
*/
class EntityAccessTest extends UnitTestCase {

use ProphecyTrait;

/**
* The field type random machinename.
*
Expand Down Expand Up @@ -50,12 +48,34 @@ class EntityAccessTest extends UnitTestCase {
*/
protected $nodeOwnerId;

/**
* The prophecy object.
*
* @var \Prophecy\Prophet
*/
private $prophet;

/**
* Set up.
*/
protected function setUp(): void {
parent::setUp();
$this->prophet = new Prophet();
}

/**
* Tear down.
*/
protected function tearDown(): void {
$this->prophet->checkPredictions();
}

/**
* Tests the EntityAccessHelper::entityAccessCheck for Neutral Access.
*/
public function testNeutralAccess(): void {

$node = $this->prophesize(NodeInterface::class);
$node = $this->prophet->prophesize(NodeInterface::class);

$this->fieldType = $this->randomMachineName();
$fieldDefinitionInterface = $this->createMock('Drupal\Core\Field\FieldDefinitionInterface');
Expand All @@ -68,7 +88,7 @@ public function testNeutralAccess(): void {

$op = 'view';

$account = $this->prophesize(AccountInterface::class)->reveal();
$account = $this->prophet->prophesize(AccountInterface::class)->reveal();

/** @var \Drupal\node\NodeInterface $node */
/** @var \Drupal\Core\Session\AccountInterface $account */
Expand All @@ -88,7 +108,7 @@ public function testNeutralAccess(): void {
* Tests the EntityAccessHelper::entityAccessCheck for Forbidden Access.
*/
public function testForbiddenAccess(): void {
$node = $this->prophesize(NodeInterface::class);
$node = $this->prophet->prophesize(NodeInterface::class);
$node->getEntityTypeId()->willReturn('node');
$node->bundle()->willReturn('article');

Expand All @@ -115,7 +135,7 @@ public function testForbiddenAccess(): void {

$op = 'view';

$account = $this->prophesize(AccountInterface::class);
$account = $this->prophet->prophesize(AccountInterface::class);
$account->hasPermission('view ' . $this->fieldId . ':' . $this->fieldValue . ' content')
->willReturn(FALSE);
$account->isAuthenticated()->willReturn(TRUE);
Expand All @@ -141,7 +161,7 @@ public function testForbiddenAccess(): void {
* Tests the EntityAccessHelper::entityAccessCheck for Allowed Access.
*/
public function testAllowedAccess(): void {
$node = $this->prophesize(NodeInterface::class);
$node = $this->prophet->prophesize(NodeInterface::class);
$node->getEntityTypeId()->willReturn('node');
$node->bundle()->willReturn('article');

Expand Down Expand Up @@ -172,7 +192,7 @@ public function testAllowedAccess(): void {

$op = 'view';

$account = $this->prophesize(AccountInterface::class);
$account = $this->prophet->prophesize(AccountInterface::class);
$account->hasPermission('view ' . $this->fieldId . ':' . $this->fieldValue . ' content')
->willReturn(TRUE);
$account->isAuthenticated()->willReturn(TRUE);
Expand All @@ -197,7 +217,7 @@ public function testAllowedAccess(): void {
* Tests the EntityAccessHelper::entityAccessCheck for Author Access Allowed.
*/
public function testAuthorAccessAllowed(): void {
$node = $this->prophesize(NodeInterface::class);
$node = $this->prophet->prophesize(NodeInterface::class);
$node->getEntityTypeId()->willReturn('node');
$node->bundle()->willReturn('article');

Expand Down Expand Up @@ -226,7 +246,7 @@ public function testAuthorAccessAllowed(): void {

$op = 'view';

$account = $this->prophesize(AccountInterface::class);
$account = $this->prophet->prophesize(AccountInterface::class);
$account->hasPermission('view ' . $this->fieldId . ':' . $this->fieldValue . ' content')
->willReturn(FALSE);
$account->isAuthenticated()->willReturn(TRUE);
Expand Down

0 comments on commit 47517e6

Please sign in to comment.