Unverified Commit 06076a3d authored by alexpott's avatar alexpott
Browse files

Issue #2932909 by Mile23, Lendude, dawehner, alexpott: Convert web tests to...

Issue #2932909 by Mile23, Lendude, dawehner, alexpott: Convert web tests to browser tests for Simpletest module
parent 62297ee7
......@@ -8,6 +8,7 @@
* Tests the internal browser of the testing framework.
*
* @group simpletest
* @group WebTestBase
*/
class BrowserTest extends WebTestBase {
......
<?php
namespace Drupal\simpletest\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Verifies that tests bundled with installation profile modules are found.
*
* @group simpletest
*/
class InstallationProfileModuleTestsTest extends WebTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['simpletest'];
/**
* An administrative user with permission to administer unit tests.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
/**
* Use the Testing profile.
*
* The Testing profile contains drupal_system_listing_compatible_test.test,
* which attempts to:
* - run tests using the Minimal profile (which does not contain the
* drupal_system_listing_compatible_test.module)
* - but still install the drupal_system_listing_compatible_test.module
* contained in the Testing profile.
*
* @see \Drupal\Tests\drupal_system_listing_compatible_test\Kernel\SystemListingCrossProfileCompatibleTest
*
* @var string
*/
protected $profile = 'testing';
protected function setUp() {
parent::setUp();
$this->adminUser = $this->drupalCreateUser(['administer unit tests']);
$this->drupalLogin($this->adminUser);
}
/**
* Tests existence of test case located in an installation profile module.
*/
public function testInstallationProfileTests() {
$this->drupalGet('admin/config/development/testing');
$this->assertText('Drupal\Tests\drupal_system_listing_compatible_test\Kernel\SystemListingCrossProfileCompatibleTest');
$edit = [
'tests[Drupal\Tests\drupal_system_listing_compatible_test\Kernel\SystemListingCrossProfileCompatibleTest]' => TRUE,
];
$this->drupalPostForm(NULL, $edit, t('Run tests'));
// Verifies that tests in installation profile modules are passed.
$element = $this->xpath('//tr[contains(@class, :class)]/td[contains(text(), :value)]', [
':class' => 'simpletest-pass',
':value' => 'Drupal\Tests\drupal_system_listing_compatible_test\Kernel\SystemListingCrossProfileCompatibleTest',
]);
$this->assertTrue(!empty($element));
}
}
......@@ -8,6 +8,7 @@
* Tests a test case with missing requirements.
*
* @group simpletest
* @group WebTestBase
*/
class MissingCheckedRequirementsTest extends WebTestBase {
......
......@@ -4,12 +4,12 @@
use Drupal\Core\Url;
use Drupal\simpletest\WebTestBase;
use Drupal\Tests\simpletest\Functional\ThroughUITest;
/**
* Tests the Simpletest UI internal browser.
* Tests the WebTestBase internal browser.
*
* @group simpletest
* @group WebTestBase
*/
class SimpleTestBrowserTest extends WebTestBase {
......@@ -116,33 +116,4 @@ public function testUserAgentValidation() {
$this->assertResponse(403, 'Requesting https.php with a normal User-Agent fails.');
}
/**
* Tests that PHPUnit and KernelTestBase tests work through the UI.
*/
public function testTestingThroughUI() {
$this->drupalGet('admin/config/development/testing');
$this->assertTrue(strpos($this->drupalSettings['simpleTest']['images'][0], 'core/misc/menu-collapsed.png') > 0, 'drupalSettings contains a link to core/misc/menu-collapsed.png.');
// We can not test WebTestBase tests here since they require a valid .htkey
// to be created. However this scenario is covered by the testception of
// \Drupal\simpletest\Tests\SimpleTestTest.
$tests = [
// A KernelTestBase test.
'Drupal\KernelTests\KernelTestBaseTest',
// A PHPUnit unit test.
'Drupal\Tests\action\Unit\Menu\ActionLocalTasksTest',
// A PHPUnit functional test.
ThroughUITest::class,
];
foreach ($tests as $test) {
$this->drupalGet('admin/config/development/testing');
$edit = [
"tests[$test]" => TRUE,
];
$this->drupalPostForm(NULL, $edit, t('Run tests'));
$this->assertText('0 fails, 0 exceptions');
}
}
}
......@@ -12,6 +12,10 @@
* installation when running tests.
*
* @group simpletest
* @group WebTestBase
* @group FunctionalTestSetupTrait
*
* @see \Drupal\FunctionalTests\Core\Test\ModuleInstallBatchTest
*/
class SimpleTestInstallBatchTest extends WebTestBase {
......@@ -20,10 +24,10 @@ class SimpleTestInstallBatchTest extends WebTestBase {
*
* @var array
*/
public static $modules = ['simpletest', 'simpletest_test', 'entity_test'];
public static $modules = ['test_batch_test', 'entity_test'];
/**
* Tests loading entities created in a batch in simpletest_test_install().
* Tests loading entities created in a batch in test_batch_test_install().
*/
public function testLoadingEntitiesCreatedInBatch() {
$entity1 = EntityTest::load(1);
......
......@@ -12,6 +12,7 @@
* internal browser and APIs implicitly.
*
* @group simpletest
* @group WebTestBase
*/
class SimpleTestTest extends WebTestBase {
......
......@@ -11,9 +11,13 @@
* This means that if you specify this test to run-tests.sh with --class or
* --file, this test will run and fail.
*
* Only WebTestBase tests are skipped by TestDiscovery. Other tests use the
* PHPUnit @-require module annotation.
*
* @dependencies module_does_not_exist
*
* @group simpletest
* @group WebTestBase
*
* @todo Change or remove this test when Simpletest-based tests are able to skip
* themselves based on requirements.
......
......@@ -5,9 +5,10 @@
use Drupal\simpletest\WebTestBase;
/**
* This test will check SimpleTest's default time zone handling.
* This test will check WebTestBase's default time zone handling.
*
* @group simpletest
* @group WebTestBase
*/
class TimeZoneTest extends WebTestBase {
......
......@@ -8,6 +8,7 @@
* Tests the test-specifics customisations done in the installation.
*
* @group simpletest
* @group WebTestBase
*/
class WebTestBaseInstallTest extends WebTestBase {
......
<?php
namespace Drupal\Tests\simpletest\Functional;
use Drupal\Core\Url;
use Drupal\KernelTests\KernelTestBaseTest;
use Drupal\Tests\action\Unit\Menu\ActionLocalTasksTest;
use Drupal\Tests\BrowserTestBase;
/**
* Test various aspects of testing through the UI form.
*
* @group simpletest
*/
class SimpletestUiTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['simpletest'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->drupalLogin($this->createUser(['administer unit tests']));
}
/**
* Tests that unit, kernel, and functional tests work through the UI.
*/
public function testTestingThroughUI() {
$url = Url::fromRoute('simpletest.test_form');
$assertion = $this->assertSession();
$this->drupalGet($url);
$settings = $this->getDrupalSettings();
$this->assertTrue(strpos($settings['simpleTest']['images'][0], 'core/misc/menu-collapsed.png') > 0, 'drupalSettings contains a link to core/misc/menu-collapsed.png.');
// We can not test WebTestBase tests here since they require a valid .htkey
// to be created. However this scenario is covered by the testception of
// \Drupal\simpletest\Tests\SimpleTestTest.
$tests = [
// A KernelTestBase test.
KernelTestBaseTest::class,
// A PHPUnit unit test.
ActionLocalTasksTest::class,
// A PHPUnit functional test.
ThroughUITest::class,
];
foreach ($tests as $test) {
$edit = [
"tests[$test]" => TRUE,
];
$this->drupalPostForm($url, $edit, t('Run tests'));
$assertion->pageTextContains('0 fails, 0 exceptions');
}
}
}
<?php
namespace Drupal\Tests\simpletest\Unit;
use Drupal\Tests\Listeners\SimpletestUiPrinter;
use Drupal\Tests\UnitTestCase;
/**
* @coversDefaultClass \Drupal\Tests\Listeners\SimpletestUiPrinter
*
* @group simpletest
*/
class SimpletestUiPrinterTest extends UnitTestCase {
/**
* Data provider for testWrite().
*
* @return string[]
* Array of data for testWrite().
* - Expected output from SimpletestUiPrinter->write().
* - Buffer to pass into SimpletestUiPrinter->write().
*/
public function provideBuffer() {
return [
['&amp;&quot;&#039;&lt;&gt;', '&"\'<>'],
['<a href="http:////www.example.com" target="_blank" title="http:////www.example.com">http:////www.example.com</a>', 'http:////www.example.com'],
['this is some text <a href="http://www.example.com/" target="_blank" title="http://www.example.com/">http://www.example.com/</a> with a link in it.', 'this is some text http://www.example.com/ with a link in it.'],
["HTML output was generated<br />\n", "HTML output was generated\n"],
];
}
/**
* @covers ::write
*
* @dataProvider provideBuffer
*/
public function testWrite($expected, $buffer) {
$printer = new SimpletestUiPrinter();
// Set up our expectation.
$this->expectOutputString($expected);
// Write the buffer.
$printer->write($buffer);
}
}
......@@ -8,6 +8,7 @@
* @requires extension curl
* @coversDefaultClass \Drupal\simpletest\TestBase
* @group simpletest
* @group TestBase
*/
class TestBaseTest extends UnitTestCase {
......
......@@ -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;
......@@ -272,6 +274,18 @@ protected function setupVfsWithTestClasses() {
* @group example
*/
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([
......@@ -293,6 +307,23 @@ class FunctionalExampleTest {}
],
],
],
'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),
],
],
],
],
],
],
],
]);
}
......@@ -350,10 +381,11 @@ public function testGetTestClassesWithSelectedTypes() {
$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(3, $result);
$this->assertEquals([
'example' => [],
'example2' => [
......@@ -364,9 +396,46 @@ public function testGetTestClassesWithSelectedTypes() {
'type' => 'PHPUnit-Kernel',
],
],
'example3' => [
'Drupal\Tests\test_profile_module\Kernel\KernelExampleTest4' => [
'name' => 'Drupal\Tests\test_profile_module\Kernel\KernelExampleTest4',
'description' => 'Test description',
'group' => 'example3',
'type' => 'PHPUnit-Kernel',
],
],
], $result);
}
/**
* @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',
'type' => 'PHPUnit-Kernel',
],
],
];
$this->assertEquals($expected, $result);
}
/**
* @covers ::getPhpunitTestSuite
* @dataProvider providerTestGetPhpunitTestSuite
......
......@@ -8,6 +8,7 @@
* @requires extension curl
* @coversDefaultClass \Drupal\simpletest\WebTestBase
* @group simpletest
* @group WebTestBase
*/
class WebTestBaseTest extends UnitTestCase {
......
name: 'Simpletest test'
name: 'Test install batch test'
type: module
description: 'Support module for Simpletest tests.'
description: 'Support module for functional tests.'
package: Testing
version: VERSION
core: 8.x
......
......@@ -10,11 +10,11 @@
/**
* Implements hook_install().
*/
function simpletest_test_install() {
function test_batch_test_install() {
$total = 2;
$operations = [];
for ($i = 1; $i <= $total; $i++) {
$operations[] = ['_simpletest_test_callback', [$i]];
$operations[] = ['_test_batch_test_callback', [$i]];
}
$batch = [
'operations' => $operations,
......@@ -28,7 +28,7 @@ function simpletest_test_install() {
/**
* Callback for batch operations.
*/
function _simpletest_test_callback($id) {
function _test_batch_test_callback($id) {
$entity = EntityTest::create(['id' => $id]);
$entity->save();
}
<?php
namespace Drupal\Tests\simpletest\Traits;
namespace Drupal\Tests\system\Traits;
/**
* A nothing trait, but declared in the Drupal\Tests namespace.
......@@ -8,7 +8,7 @@
* We use this trait to test autoloading of traits outside of the normal test
* suite namespaces.
*
* @see \Drupal\Tests\simpletest\Unit\TraitAccessTest
* @see \Drupal\Tests\system\Unit\TraitAccessTest
*/
trait TestTrait {
......
<?php
namespace Drupal\Tests\simpletest\Unit;
namespace Drupal\Tests\system\Unit;
use Drupal\Tests\UnitTestCase;
use Drupal\Tests\simpletest\Traits\TestTrait;
use Drupal\Tests\system\Traits\TestTrait;
/**
* Test whether traits are autoloaded during PHPUnit discovery time.
*
* @group simpletest
* @group system
* @group Test
*/
class TraitAccessTest extends UnitTestCase {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment