commit 430dbee28add225973cc94c4892d7d3fb56f7cc8 Author: Erik Stielstra Date: Sun Mar 8 15:20:18 2015 +0100 2417359-5 diff --git a/core/modules/menu_link_content/tests/src/Unit/MenuLinkContentAccessTest.php b/core/modules/menu_link_content/tests/src/Unit/MenuLinkContentAccessTest.php index 314770d..a5a494d 100644 --- a/core/modules/menu_link_content/tests/src/Unit/MenuLinkContentAccessTest.php +++ b/core/modules/menu_link_content/tests/src/Unit/MenuLinkContentAccessTest.php @@ -2,10 +2,10 @@ /** * @file - * Contains \Drupal\menu_link_content\Tests\MenuLinkContentAccessTest. + * Contains \Drupal\Tests\menu_link_content\Unit\MenuLinkContentAccessTest. */ -namespace Drupal\menu_link_content\Tests; +namespace Drupal\Tests\menu_link_content\Unit; use Drupal\Core\Access\AccessResult; use Drupal\Core\Entity\EntityInterface; @@ -20,45 +20,52 @@ class MenuLinkContentAccessTest extends UnitTestCase { /** - * The menu link content access control handler to test. + * The menu link content access control handler that is subject of this test. * * @var \Drupal\menu_link_content\MenuLinkContentAccessControlHandler */ protected $accessControlHandler; /** - * A reflection of the method we want to test. + * A reflection of MenuLinkContentAccessControlHandler::checkAccess. * * @var \ReflectionMethod */ protected $checkAccessMethod; /** - * The entity type used for testing. + * The menu link content entity used for testing. * - * @var \Drupal\Core\Entity\EntityTypeInterface|\PHPUnit_Framework_MockObject_MockObject + * @var \Drupal\Core\Entity\ContentEntityBase */ - protected $entityType; + protected $entity; /** - * The mocked access manager. + * The account used for testing. * - * @var \Drupal\Core\Access\AccessManagerInterface|\PHPUnit_Framework_MockObject_MockObject + * @var \Drupal\Core\Session\AccountInterface */ - protected $accessManager; + protected $account; /** * {@inheritdoc} */ protected function setUp() { - $this->entityType = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface'); - $this->accessManager = $this->getMock('\Drupal\Core\Access\AccessManagerInterface'); - $this->accessControlHandler = new MenuLinkContentAccessControlHandler($this->entityType, $this->accessManager); + // Setup the class we want to test. + $entityType = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface'); + $accessManager = $this->getMock('\Drupal\Core\Access\AccessManagerInterface'); + $this->accessControlHandler = new MenuLinkContentAccessControlHandler($entityType, $accessManager); // Setup a reflection method for the private method we want to test. $this->checkAccessMethod = new \ReflectionMethod($this->accessControlHandler, 'checkAccess'); $this->checkAccessMethod->setAccessible(TRUE); + + $this->entity = $this->getMockBuilder('Drupal\Core\Entity\ContentEntityBase') + ->disableOriginalConstructor() + ->getMock(); + + $this->account = $this->getMock('\Drupal\Core\Session\AccountInterface'); } /** @@ -66,13 +73,11 @@ protected function setUp() { */ public function testViewAccess() { - $entity = $this->getMockEntity(); $operation = 'view'; $langcode = ''; - $account = $this->getMock('\Drupal\Core\Session\AccountInterface'); - $access = $this->checkAccessMethod->invoke($this->accessControlHandler, $entity, $operation, $langcode, $account); + $access = $this->checkAccessMethod->invoke($this->accessControlHandler, $this->entity, $operation, $langcode, $this->account); - $this->assertEquals($access, AccessResult::neutral()); + $this->assertInstanceOf('\Drupal\Core\Access\AccessResultNeutral', $access); } /** @@ -80,7 +85,7 @@ public function testViewAccess() { */ public function testUpdateAccess() { - // @todo + $this->markTestIncomplete(); } /** @@ -88,22 +93,6 @@ public function testUpdateAccess() { */ public function testDeleteAccess() { - // @todo - } - - /** - * Creates an entity with specific methods mocked. - * - * @param array $values - * (optional) Values to pass to the constructor. - * @param array $methods - * (optional) The methods to mock. - * - * @return \Drupal\Core\Entity\EntityInterface|\PHPUnit_Framework_MockObject_MockObject - */ - public function getMockEntity(array $values = array(), $methods = array()) { - - return $this->getMockForAbstractClass('Drupal\Core\Config\Entity\ConfigEntityBase', array($values, 'test_entity_type'), '', TRUE, TRUE, TRUE, $methods); + $this->markTestIncomplete(); } - }