EntityAccessCheckTest.php 1.77 KB
Newer Older
1
2
3
4
5
6
7
8
9
<?php

/**
 * @file
 * Contains \Drupal\Tests\Core\Entity\EntityAccessCheckTest.
 */

namespace Drupal\Tests\Core\Entity;

10
11
use Drupal\Core\Cache\Context\CacheContextsManager;
use Drupal\Core\DependencyInjection\Container;
12
use Symfony\Component\HttpFoundation\ParameterBag;
13
use Symfony\Component\Routing\Route;
14
use Drupal\Core\Access\AccessResult;
15
16
17
18
use Drupal\Core\Entity\EntityAccessCheck;
use Drupal\Tests\UnitTestCase;

/**
19
 * Unit test of entity access checking system.
20
 *
21
 * @group Access
22
23
24
25
26
27
28
29
 * @group Entity
 */
class EntityAccessCheckTest extends UnitTestCase {

  /**
   * Tests the method for checking access to routes.
   */
  public function testAccess() {
30
31
32
33
34
    $cache_contexts_manager = $this->prophesize(CacheContextsManager::class)->reveal();
    $container = new Container();
    $container->set('cache_contexts_manager', $cache_contexts_manager);
    \Drupal::setContainer($container);

35
    $route = new Route('/foo', array(), array('_entity_access' => 'node.update'));
36
37
38
39
40
    $upcasted_arguments = new ParameterBag();
    $route_match = $this->getMock('Drupal\Core\Routing\RouteMatchInterface');
    $route_match->expects($this->once())
      ->method('getParameters')
      ->will($this->returnValue($upcasted_arguments));
41
    $node = $this->getMockBuilder('Drupal\node\Entity\Node')
42
43
44
45
      ->disableOriginalConstructor()
      ->getMock();
    $node->expects($this->any())
      ->method('access')
46
      ->will($this->returnValue(AccessResult::allowed()->cachePerPermissions()));
47
    $access_check = new EntityAccessCheck();
48
    $upcasted_arguments->set('node', $node);
49
    $account = $this->getMock('Drupal\Core\Session\AccountInterface');
50
    $access = $access_check->access($route, $route_match, $account);
51
    $this->assertEquals(AccessResult::allowed()->cachePerPermissions(), $access);
52
53
54
  }

}