MenuLinkContentEntityAccessTest.php

Same filename in other branches
  1. 9 core/modules/menu_link_content/tests/src/Unit/MenuLinkContentEntityAccessTest.php
  2. 8.9.x core/modules/menu_link_content/tests/src/Unit/MenuLinkContentEntityAccessTest.php
  3. 11.x core/modules/menu_link_content/tests/src/Unit/MenuLinkContentEntityAccessTest.php

Namespace

Drupal\Tests\menu_link_content\Unit

File

core/modules/menu_link_content/tests/src/Unit/MenuLinkContentEntityAccessTest.php

View source
<?php

declare (strict_types=1);
namespace Drupal\Tests\menu_link_content\Unit;

use Drupal\Core\Access\AccessManagerInterface;
use Drupal\Core\Access\AccessResultInterface;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\menu_link_content\MenuLinkContentAccessControlHandler;
use Drupal\Tests\UnitTestCase;

/**
 * Tests menu link content entity access.
 *
 * @coversDefaultClass \Drupal\menu_link_content\MenuLinkContentAccessControlHandler
 * @group menu_link_content
 */
class MenuLinkContentEntityAccessTest extends UnitTestCase {
    
    /**
     * Tests an operation not implemented by the access control handler.
     *
     * @covers ::checkAccess
     */
    public function testUnrecognizedOperation() : void {
        $entityType = $this->createMock(EntityTypeInterface::class);
        $accessManager = $this->createMock(AccessManagerInterface::class);
        $moduleHandler = $this->createMock(ModuleHandlerInterface::class);
        $moduleHandler->expects($this->any())
            ->method('invokeAll')
            ->willReturn([]);
        $language = $this->createMock(LanguageInterface::class);
        $language->expects($this->any())
            ->method('getId')
            ->willReturn('de');
        $entity = $this->createMock(ContentEntityInterface::class);
        $entity->expects($this->any())
            ->method('language')
            ->willReturn($language);
        $account = $this->createMock(AccountInterface::class);
        $accessControl = new MenuLinkContentAccessControlHandler($entityType, $accessManager);
        $accessControl->setModuleHandler($moduleHandler);
        $access = $accessControl->access($entity, 'not-an-op', $account, TRUE);
        $this->assertInstanceOf(AccessResultInterface::class, $access);
    }

}

Classes

Title Deprecated Summary
MenuLinkContentEntityAccessTest Tests menu link content entity access.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.