diff --git a/.github/workflows/TestGitHubActions.yml b/.github/workflows/TestGitHubActions.yml index 31deaae5..0d26998e 100644 --- a/.github/workflows/TestGitHubActions.yml +++ b/.github/workflows/TestGitHubActions.yml @@ -59,7 +59,6 @@ jobs: echo "api_version: 1" >> pantheon.yml echo "web_docroot: true" >> pantheon.yml echo "php_version: 8.3" >> pantheon.yml - echo "drush_version: 13" >> pantheon.yml echo "database:" >> pantheon.yml echo " version: 10.6" >> pantheon.yml echo "enforce_https: full+subdomains" >> pantheon.yml diff --git a/tasks/test.yml b/tasks/test.yml index 16fe030f..0fe8ba09 100644 --- a/tasks/test.yml +++ b/tasks/test.yml @@ -114,7 +114,7 @@ tasks: CONFIG="$(pwd)/vendor/lullabot/drainpipe/scaffold/phpunit-testtraits.xml" fi if [ "{{.format}}" == "junit" ]; then - mkdir -p test_result + mkdir -p test_result/phpunit ./vendor/bin/phpunit --testsuite=unit -c $CONFIG --log-junit $(pwd)/test_result/phpunit.xml else ./vendor/bin/phpunit -c $CONFIG --testsuite=unit @@ -128,7 +128,7 @@ tasks: CONFIG="$(pwd)/vendor/lullabot/drainpipe/scaffold/phpunit-testtraits.xml" fi if [ "{{.format}}" == "junit" ]; then - mkdir -p test_result + mkdir -p test_result/phpunit ./vendor/bin/phpunit --exclude-testsuite=unit -c $CONFIG --log-junit $(pwd)/test_result/phpunit-functional.xml else ./vendor/bin/phpunit -c $CONFIG --exclude-testsuite=unit diff --git a/tests/fixtures/phpunit/testmodule/modules/testsubmodule/tests/src/Unit/PermissionAccessCheckTest.php b/tests/fixtures/phpunit/testmodule/modules/testsubmodule/tests/src/Unit/PermissionAccessCheckTest.php index 5f0bb587..3660e00f 100644 --- a/tests/fixtures/phpunit/testmodule/modules/testsubmodule/tests/src/Unit/PermissionAccessCheckTest.php +++ b/tests/fixtures/phpunit/testmodule/modules/testsubmodule/tests/src/Unit/PermissionAccessCheckTest.php @@ -1,6 +1,8 @@ container = new ContainerBuilder(); - $cache_contexts_manager = $this->prophesize(CacheContextsManager::class); - $cache_contexts_manager->assertValidTokens()->willReturn(TRUE); - $cache_contexts_manager->reveal(); - $this->container->set('cache_contexts_manager', $cache_contexts_manager); - \Drupal::setContainer($this->container); + $this->container = new ContainerBuilder(); + $cache_contexts_manager = $this->prophesize(CacheContextsManager::class); + $cache_contexts_manager->assertValidTokens()->willReturn(TRUE); + $cache_contexts_manager->reveal(); + $this->container->set('cache_contexts_manager', $cache_contexts_manager); + \Drupal::setContainer($this->container); - $this->accessCheck = new PermissionAccessCheck(); - } + $this->accessCheck = new PermissionAccessCheck(); + } - /** - * Provides data for the testAccess method. - * - * @dataProvider providerTestAccess - * @return array - */ - public function providerTestAccess() { - return [ - [[], FALSE], - [['_permission' => 'allowed'], TRUE, ['user.permissions']], - [['_permission' => 'denied'], FALSE, ['user.permissions'], "The 'denied' permission is required."], - [['_permission' => 'allowed+denied'], TRUE, ['user.permissions']], - [['_permission' => 'allowed+denied+other'], TRUE, ['user.permissions']], - [['_permission' => 'allowed,denied'], FALSE, ['user.permissions'], "The following permissions are required: 'allowed' AND 'denied'."], - ]; - } + /** + * Provides data for the testAccess method. + * + * @return array + */ + public static function providerTestAccess() { + return [ + [[], FALSE], + [['_permission' => 'allowed'], TRUE, ['user.permissions']], + [['_permission' => 'denied'], FALSE, ['user.permissions'], "The 'denied' permission is required."], + [['_permission' => 'allowed+denied'], TRUE, ['user.permissions']], + [['_permission' => 'allowed+denied+other'], TRUE, ['user.permissions']], + [['_permission' => 'allowed,denied'], FALSE, ['user.permissions'], "The following permissions are required: 'allowed' AND 'denied'."], + ]; + } - /** - * Tests the access check method. - */ - public function testAccess($requirements, $access, array $contexts = [], $message = '') { - $access_result = AccessResult::allowedIf($access)->addCacheContexts($contexts); - if (!empty($message)) { - $access_result->setReason($message); - } - $user = $this->createMock('Drupal\Core\Session\AccountInterface'); - $user->expects($this->any()) - ->method('hasPermission') - ->willReturnMap([ - ['allowed', TRUE], - ['denied', FALSE], - ['other', FALSE], - ]); - $route = new Route('', [], $requirements); - - $this->assertEquals($access_result, $this->accessCheck->access($route, $user)); + /** + * Tests the access check method. + * + * @dataProvider providerTestAccess + * @covers ::access + */ + public function testAccess($requirements, $access, array $contexts = [], $message = ''): void { + $access_result = AccessResult::allowedIf($access)->addCacheContexts($contexts); + if (!empty($message)) { + $access_result->setReason($message); } + $user = $this->createMock('Drupal\Core\Session\AccountInterface'); + $user->expects($this->any()) + ->method('hasPermission') + ->willReturnMap([ + ['allowed', TRUE], + ['denied', FALSE], + ['other', FALSE], + ]); + $route = new Route('', [], $requirements); + + $this->assertEquals($access_result, $this->accessCheck->access($route, $user)); + } } diff --git a/tests/fixtures/phpunit/testmodule/tests/src/Unit/PermissionAccessCheckTest.php b/tests/fixtures/phpunit/testmodule/tests/src/Unit/PermissionAccessCheckTest.php index 3da1ff08..3660e00f 100644 --- a/tests/fixtures/phpunit/testmodule/tests/src/Unit/PermissionAccessCheckTest.php +++ b/tests/fixtures/phpunit/testmodule/tests/src/Unit/PermissionAccessCheckTest.php @@ -1,6 +1,8 @@ container = new ContainerBuilder(); - $cache_contexts_manager = $this->prophesize(CacheContextsManager::class); - $cache_contexts_manager->assertValidTokens()->willReturn(TRUE); - $cache_contexts_manager->reveal(); - $this->container->set('cache_contexts_manager', $cache_contexts_manager); - \Drupal::setContainer($this->container); + $this->container = new ContainerBuilder(); + $cache_contexts_manager = $this->prophesize(CacheContextsManager::class); + $cache_contexts_manager->assertValidTokens()->willReturn(TRUE); + $cache_contexts_manager->reveal(); + $this->container->set('cache_contexts_manager', $cache_contexts_manager); + \Drupal::setContainer($this->container); - $this->accessCheck = new PermissionAccessCheck(); - } + $this->accessCheck = new PermissionAccessCheck(); + } - /** - * Provides data for the testAccess method. - * - * @dataProvider providerTestAccess - * @return array - */ - public function providerTestAccess() { - return [ - [[], FALSE], - [['_permission' => 'allowed'], TRUE, ['user.permissions']], - [['_permission' => 'denied'], FALSE, ['user.permissions'], "The 'denied' permission is required."], - [['_permission' => 'allowed+denied'], TRUE, ['user.permissions']], - [['_permission' => 'allowed+denied+other'], TRUE, ['user.permissions']], - [['_permission' => 'allowed,denied'], FALSE, ['user.permissions'], "The following permissions are required: 'allowed' AND 'denied'."], - ]; - } + /** + * Provides data for the testAccess method. + * + * @return array + */ + public static function providerTestAccess() { + return [ + [[], FALSE], + [['_permission' => 'allowed'], TRUE, ['user.permissions']], + [['_permission' => 'denied'], FALSE, ['user.permissions'], "The 'denied' permission is required."], + [['_permission' => 'allowed+denied'], TRUE, ['user.permissions']], + [['_permission' => 'allowed+denied+other'], TRUE, ['user.permissions']], + [['_permission' => 'allowed,denied'], FALSE, ['user.permissions'], "The following permissions are required: 'allowed' AND 'denied'."], + ]; + } - /** - * Tests the access check method. - */ - public function testAccess($requirements, $access, array $contexts = [], $message = '') { - $access_result = AccessResult::allowedIf($access)->addCacheContexts($contexts); - if (!empty($message)) { - $access_result->setReason($message); - } - $user = $this->createMock('Drupal\Core\Session\AccountInterface'); - $user->expects($this->any()) - ->method('hasPermission') - ->willReturnMap([ - ['allowed', TRUE], - ['denied', FALSE], - ['other', FALSE], - ]); - $route = new Route('', [], $requirements); - - $this->assertEquals($access_result, $this->accessCheck->access($route, $user)); + /** + * Tests the access check method. + * + * @dataProvider providerTestAccess + * @covers ::access + */ + public function testAccess($requirements, $access, array $contexts = [], $message = ''): void { + $access_result = AccessResult::allowedIf($access)->addCacheContexts($contexts); + if (!empty($message)) { + $access_result->setReason($message); } + $user = $this->createMock('Drupal\Core\Session\AccountInterface'); + $user->expects($this->any()) + ->method('hasPermission') + ->willReturnMap([ + ['allowed', TRUE], + ['denied', FALSE], + ['other', FALSE], + ]); + $route = new Route('', [], $requirements); + + $this->assertEquals($access_result, $this->accessCheck->access($route, $user)); + } }