Skip to content
Snippets Groups Projects
Select Git revision
  • 9d5aefb739809c20da3947a1609ddb364f12c72d
  • 11.x default protected
  • 11.2.x protected
  • 10.5.x protected
  • 10.6.x protected
  • 11.1.x protected
  • 10.4.x protected
  • 11.0.x protected
  • 10.3.x protected
  • 7.x protected
  • 10.2.x protected
  • 10.1.x protected
  • 9.5.x protected
  • 10.0.x protected
  • 9.4.x protected
  • 9.3.x protected
  • 9.2.x protected
  • 9.1.x protected
  • 8.9.x protected
  • 9.0.x protected
  • 8.8.x protected
  • 10.5.1 protected
  • 11.2.2 protected
  • 11.2.1 protected
  • 11.2.0 protected
  • 10.5.0 protected
  • 11.2.0-rc2 protected
  • 10.5.0-rc1 protected
  • 11.2.0-rc1 protected
  • 10.4.8 protected
  • 11.1.8 protected
  • 10.5.0-beta1 protected
  • 11.2.0-beta1 protected
  • 11.2.0-alpha1 protected
  • 10.4.7 protected
  • 11.1.7 protected
  • 10.4.6 protected
  • 11.1.6 protected
  • 10.3.14 protected
  • 10.4.5 protected
  • 11.0.13 protected
41 results

EntityAccessCheckTest.php

Blame
  • Nathaniel Catchpole's avatar
    Issue #2048223 by dawehner, ParisLiakos, herom, fubhy, damiankloip, vijaycs85,...
    catch authored
    Issue #2048223 by dawehner, ParisLiakos, herom, fubhy, damiankloip, vijaycs85, joelpittet, tim.plunkett: Add $account argument to AccessCheckInterface::access() method and use the current_user() service.
    9d5aefb7
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    EntityAccessCheckTest.php 1.63 KiB
    <?php
    
    /**
     * @file
     * Contains \Drupal\Tests\Core\Entity\EntityAccessCheckTest.
     */
    
    namespace Drupal\Tests\Core\Entity;
    
    use Symfony\Component\HttpFoundation\Request;
    use Symfony\Component\Routing\Route;
    use Drupal\Core\Access\AccessCheckInterface;
    use Drupal\Core\Entity\EntityAccessCheck;
    use Drupal\Tests\UnitTestCase;
    
    /**
     * Tests the entity access controller.
     *
     * @group Entity
     */
    class EntityAccessCheckTest extends UnitTestCase {
    
      public static function getInfo() {
        return array(
          'name' => 'Entity access check test',
          'description' => 'Unit test of entity access checking system.',
          'group' => 'Entity'
        );
      }
    
      /**
       * Tests the appliesTo method for the access checker.
       */
      public function testAppliesTo() {
        $entity_access = new EntityAccessCheck();
        $this->assertEquals($entity_access->appliesTo(), array('_entity_access'), 'Access checker returned the expected appliesTo() array.');
      }
    
      /**
       * Tests the method for checking access to routes.
       */
      public function testAccess() {
        $route = new Route('/foo', array(), array('_entity_access' => 'node.update'));
        $request = new Request();
        $node = $this->getMockBuilder('Drupal\node\Entity\Node')
          ->disableOriginalConstructor()
          ->getMock();
        $node->expects($this->any())
          ->method('access')
          ->will($this->returnValue(TRUE));
        $access_check = new EntityAccessCheck();
        $request->attributes->set('node', $node);
        $account = $this->getMock('Drupal\Core\Session\AccountInterface');
        $access = $access_check->access($route, $request, $account);
        $this->assertSame(AccessCheckInterface::ALLOW, $access);
      }
    
    }