EntityAccessCheckTest.php 1.44 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
use Symfony\Component\HttpFoundation\ParameterBag;
11
use Symfony\Component\Routing\Route;
12
use Drupal\Core\Access\AccessResult;
13
14
15
16
use Drupal\Core\Entity\EntityAccessCheck;
use Drupal\Tests\UnitTestCase;

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

  /**
   * Tests the method for checking access to routes.
   */
  public function testAccess() {
    $route = new Route('/foo', array(), array('_entity_access' => 'node.update'));
29
30
31
32
33
    $upcasted_arguments = new ParameterBag();
    $route_match = $this->getMock('Drupal\Core\Routing\RouteMatchInterface');
    $route_match->expects($this->once())
      ->method('getParameters')
      ->will($this->returnValue($upcasted_arguments));
34
    $node = $this->getMockBuilder('Drupal\node\Entity\Node')
35
36
37
38
      ->disableOriginalConstructor()
      ->getMock();
    $node->expects($this->any())
      ->method('access')
39
      ->will($this->returnValue(AccessResult::allowed()->cachePerPermissions()));
40
    $access_check = new EntityAccessCheck();
41
    $upcasted_arguments->set('node', $node);
42
    $account = $this->getMock('Drupal\Core\Session\AccountInterface');
43
    $access = $access_check->access($route, $route_match, $account);
44
    $this->assertEquals(AccessResult::allowed()->cachePerPermissions(), $access);
45
46
47
  }

}