Mercurial > hg > cmmr2012-drupal-site
diff core/modules/simpletest/tests/src/Unit/TestDiscoveryTest.php @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | a9cd425dd02b |
children |
line wrap: on
line diff
--- a/core/modules/simpletest/tests/src/Unit/TestDiscoveryTest.php Thu Feb 28 13:11:55 2019 +0000 +++ b/core/modules/simpletest/tests/src/Unit/TestDiscoveryTest.php Thu May 09 15:34:47 2019 +0100 @@ -3,6 +3,8 @@ namespace Drupal\Tests\simpletest\Unit; use Composer\Autoload\ClassLoader; +use Drupal\Core\DependencyInjection\Container; +use Drupal\Core\DrupalKernel; use Drupal\Core\Extension\Extension; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\simpletest\Exception\MissingGroupException; @@ -30,13 +32,14 @@ $tests[] = [ // Expected result. [ - 'name' => 'Drupal\Tests\simpletest\Unit\TestDiscoveryTest', + 'name' => static::class, 'group' => 'simpletest', + 'groups' => ['simpletest'], 'description' => 'Tests \Drupal\simpletest\TestDiscovery.', 'type' => 'PHPUnit-Unit', ], // Classname. - 'Drupal\Tests\simpletest\Unit\TestDiscoveryTest', + static::class, ]; // A core unit test. @@ -45,6 +48,7 @@ [ 'name' => 'Drupal\Tests\Core\DrupalTest', 'group' => 'DrupalTest', + 'groups' => ['DrupalTest'], 'description' => 'Tests \Drupal.', 'type' => 'PHPUnit-Unit', ], @@ -58,6 +62,7 @@ [ 'name' => 'Drupal\FunctionalTests\BrowserTestBaseTest', 'group' => 'browsertestbase', + 'groups' => ['browsertestbase'], 'description' => 'Tests BrowserTestBase functionality.', 'type' => 'PHPUnit-Functional', ], @@ -71,6 +76,7 @@ [ 'name' => '\Drupal\Tests\file\Kernel\FileItemValidationTest', 'group' => 'file', + 'groups' => ['file'], 'description' => 'Tests that files referenced in file and image fields are always validated.', 'type' => 'PHPUnit-Kernel', ], @@ -85,6 +91,7 @@ [ 'name' => 'Drupal\simpletest\Tests\ExampleSimpleTest', 'group' => 'simpletest', + 'groups' => ['simpletest'], 'description' => 'Tests the Simpletest UI internal browser.', 'type' => 'Simpletest', ], @@ -105,6 +112,7 @@ [ 'name' => 'Drupal\simpletest\Tests\ExampleSimpleTest', 'group' => 'simpletest', + 'groups' => ['simpletest'], 'description' => 'Tests the Simpletest UI internal browser.', 'type' => 'Simpletest', ], @@ -127,6 +135,7 @@ [ 'name' => 'Drupal\simpletest\Tests\ExampleSimpleTest', 'group' => 'simpletest', + 'groups' => ['simpletest'], 'description' => 'Tests the Simpletest UI internal browser. * @', 'type' => 'Simpletest', ], @@ -147,6 +156,7 @@ [ 'name' => 'Drupal\simpletest\Tests\ExampleSimpleTest', 'group' => 'Test', + 'groups' => ['Test', 'simpletest'], 'description' => 'Tests the Simpletest UI internal browser.', 'type' => 'Simpletest', ], @@ -162,6 +172,33 @@ ", ]; + // A great number of @group annotations. + $tests['many-group-annotations'] = [ + // Expected result. + [ + 'name' => 'Drupal\simpletest\Tests\ExampleSimpleTest', + 'group' => 'Test', + 'groups' => ['Test', 'simpletest', 'another', 'more', 'many', 'enough', 'whoa'], + 'description' => 'Tests the Simpletest UI internal browser.', + 'type' => 'Simpletest', + ], + // Classname. + 'Drupal\simpletest\Tests\ExampleSimpleTest', + // Doc block. + "/** + * Tests the Simpletest UI internal browser. + * + * @group Test + * @group simpletest + * @group another + * @group more + * @group many + * @group enough + * @group whoa + */ + ", + ]; + // @dependencies annotation. $tests[] = [ // Expected result. @@ -171,6 +208,7 @@ 'type' => 'Simpletest', 'requires' => ['module' => ['test']], 'group' => 'simpletest', + 'groups' => ['simpletest'], ], // Classname. 'Drupal\simpletest\Tests\ExampleSimpleTest', @@ -193,6 +231,7 @@ 'type' => 'Simpletest', 'requires' => ['module' => ['test', 'test1', 'test2']], 'group' => 'simpletest', + 'groups' => ['simpletest'], ], // Classname. 'Drupal\simpletest\Tests\ExampleSimpleTest', @@ -214,6 +253,7 @@ 'description' => 'Tests the Simpletest UI internal browser. And the summary line continues an there is no gap to the annotation.', 'type' => 'Simpletest', 'group' => 'simpletest', + 'groups' => ['simpletest'], ], // Classname. 'Drupal\simpletest\Tests\ExampleSimpleTest', @@ -270,6 +310,18 @@ class FunctionalExampleTest {} EOF; + $test_profile_info = <<<EOF +name: Testing +type: profile +core: 8.x +EOF; + + $test_module_info = <<<EOF +name: Testing +type: module +core: 8.x +EOF; + vfsStream::create([ 'modules' => [ 'test_module' => [ @@ -280,7 +332,7 @@ 'FunctionalExampleTest2.php' => str_replace(['FunctionalExampleTest', '@group example'], ['FunctionalExampleTest2', '@group example2'], $test_file), ], 'Kernel' => [ - 'KernelExampleTest3.php' => str_replace(['FunctionalExampleTest', '@group example'], ['KernelExampleTest3', '@group example2'], $test_file), + 'KernelExampleTest3.php' => str_replace(['FunctionalExampleTest', '@group example'], ['KernelExampleTest3', "@group example2\n * @group kernel\n"], $test_file), 'KernelExampleTestBase.php' => str_replace(['FunctionalExampleTest', '@group example'], ['KernelExampleTestBase', '@group example2'], $test_file), 'KernelExampleTrait.php' => str_replace(['FunctionalExampleTest', '@group example'], ['KernelExampleTrait', '@group example2'], $test_file), 'KernelExampleInterface.php' => str_replace(['FunctionalExampleTest', '@group example'], ['KernelExampleInterface', '@group example2'], $test_file), @@ -289,6 +341,23 @@ ], ], ], + 'profiles' => [ + 'test_profile' => [ + 'test_profile.info.yml' => $test_profile_info, + 'modules' => [ + 'test_profile_module' => [ + 'test_profile_module.info.yml' => $test_module_info, + 'tests' => [ + 'src' => [ + 'Kernel' => [ + 'KernelExampleTest4.php' => str_replace(['FunctionalExampleTest', '@group example'], ['KernelExampleTest4', '@group example3'], $test_file), + ], + ], + ], + ], + ], + ], + ], ]); } @@ -307,13 +376,14 @@ ]; $test_discovery->setExtensions($extensions); $result = $test_discovery->getTestClasses(); - $this->assertCount(2, $result); + $this->assertCount(3, $result); $this->assertEquals([ 'example' => [ 'Drupal\Tests\test_module\Functional\FunctionalExampleTest' => [ 'name' => 'Drupal\Tests\test_module\Functional\FunctionalExampleTest', 'description' => 'Test description', 'group' => 'example', + 'groups' => ['example'], 'type' => 'PHPUnit-Functional', ], ], @@ -322,12 +392,23 @@ 'name' => 'Drupal\Tests\test_module\Functional\FunctionalExampleTest2', 'description' => 'Test description', 'group' => 'example2', + 'groups' => ['example2'], 'type' => 'PHPUnit-Functional', ], 'Drupal\Tests\test_module\Kernel\KernelExampleTest3' => [ 'name' => 'Drupal\Tests\test_module\Kernel\KernelExampleTest3', 'description' => 'Test description', 'group' => 'example2', + 'groups' => ['example2', 'kernel'], + 'type' => 'PHPUnit-Kernel', + ], + ], + 'kernel' => [ + 'Drupal\Tests\test_module\Kernel\KernelExampleTest3' => [ + 'name' => 'Drupal\Tests\test_module\Kernel\KernelExampleTest3', + 'description' => 'Test description', + 'group' => 'example2', + 'groups' => ['example2', 'kernel'], 'type' => 'PHPUnit-Kernel', ], ], @@ -346,10 +427,11 @@ $extensions = [ 'test_module' => new Extension('vfs://drupal', 'module', 'modules/test_module/test_module.info.yml'), + 'test_profile_module' => new Extension('vfs://drupal', 'profile', 'profiles/test_profile/modules/test_profile_module/test_profile_module.info.yml'), ]; $test_discovery->setExtensions($extensions); $result = $test_discovery->getTestClasses(NULL, ['PHPUnit-Kernel']); - $this->assertCount(2, $result); + $this->assertCount(4, $result); $this->assertEquals([ 'example' => [], 'example2' => [ @@ -357,6 +439,25 @@ 'name' => 'Drupal\Tests\test_module\Kernel\KernelExampleTest3', 'description' => 'Test description', 'group' => 'example2', + 'groups' => ['example2', 'kernel'], + 'type' => 'PHPUnit-Kernel', + ], + ], + 'kernel' => [ + 'Drupal\Tests\test_module\Kernel\KernelExampleTest3' => [ + 'name' => 'Drupal\Tests\test_module\Kernel\KernelExampleTest3', + 'description' => 'Test description', + 'group' => 'example2', + 'groups' => ['example2', 'kernel'], + 'type' => 'PHPUnit-Kernel', + ], + ], + 'example3' => [ + 'Drupal\Tests\test_profile_module\Kernel\KernelExampleTest4' => [ + 'name' => 'Drupal\Tests\test_profile_module\Kernel\KernelExampleTest4', + 'description' => 'Test description', + 'group' => 'example3', + 'groups' => ['example3'], 'type' => 'PHPUnit-Kernel', ], ], @@ -364,6 +465,36 @@ } /** + * @covers ::getTestClasses + */ + public function testGetTestsInProfiles() { + $this->setupVfsWithTestClasses(); + $class_loader = $this->prophesize(ClassLoader::class); + $module_handler = $this->prophesize(ModuleHandlerInterface::class); + + $container = new Container(); + $container->set('kernel', new DrupalKernel('prod', new ClassLoader())); + $container->set('site.path', 'sites/default'); + \Drupal::setContainer($container); + + $test_discovery = new TestDiscovery('vfs://drupal', $class_loader->reveal(), $module_handler->reveal()); + + $result = $test_discovery->getTestClasses(NULL, ['PHPUnit-Kernel']); + $expected = [ + 'example3' => [ + 'Drupal\Tests\test_profile_module\Kernel\KernelExampleTest4' => [ + 'name' => 'Drupal\Tests\test_profile_module\Kernel\KernelExampleTest4', + 'description' => 'Test description', + 'group' => 'example3', + 'groups' => ['example3'], + 'type' => 'PHPUnit-Kernel', + ], + ], + ]; + $this->assertEquals($expected, $result); + } + + /** * @covers ::getPhpunitTestSuite * @dataProvider providerTestGetPhpunitTestSuite */ @@ -439,15 +570,3 @@ } } - -namespace Drupal\simpletest\Tests; - -use Drupal\simpletest\WebTestBase; - -/** - * Tests the Simpletest UI internal browser. - * - * @group simpletest - */ -class ExampleSimpleTest extends WebTestBase { -}