WebformAccessTestBase.php in Webform 8.5
File
tests/src/Unit/Access/WebformAccessTestBase.php
View source
<?php
namespace Drupal\Tests\webform\Unit\Access;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Tests\UnitTestCase;
abstract class WebformAccessTestBase extends UnitTestCase {
protected $container;
protected function setUp() {
parent::setUp();
$this->container = new ContainerBuilder();
\Drupal::setContainer($this->container);
$cache_contexts_manager = $this
->getMockBuilder('Drupal\\Core\\Cache\\Context\\CacheContextsManager')
->disableOriginalConstructor()
->getMock();
$cache_contexts_manager
->method('assertValidTokens')
->willReturn(TRUE);
$this->container
->set('cache_contexts_manager', $cache_contexts_manager);
}
protected function mockAccount(array $permissions = []) {
$value_map = [];
foreach ($permissions as $permission => $result) {
$value_map[] = [
$permission,
$result,
];
}
$account = $this
->createMock('Drupal\\Core\\Session\\AccountInterface');
$account
->expects($this
->any())
->method('hasPermission')
->will($this
->returnValueMap($value_map));
return $account;
}
}