first commit
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<testsuites>
|
||||
<testsuite name="Drupal Unit Test Suite" tests="1" assertions="0" failures="0" errors="1" time="0.002680">
|
||||
<testsuite name="Drupal\Tests\Component\PhpStorage\FileStorageTest" file="/home/chx/www/system/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php" namespace="Drupal\Tests\Component\PhpStorage" fullPackage="Drupal.Tests.Component.PhpStorage" tests="0" assertions="0" failures="0" errors="0" time="0.000000"/>
|
||||
<testsuite name="Drupal\Tests\Component\PhpStorage\MTimeProtectedFastFileStorageTest" file="/home/chx/www/system/core/tests/Drupal/Tests/Component/PhpStorage/MTimeProtectedFastFileStorageTest.php" namespace="Drupal\Tests\Component\PhpStorage" fullPackage="Drupal.Tests.Component.PhpStorage" tests="0" assertions="0" failures="0" errors="0" time="0.000000"/>
|
||||
<testsuite name="Drupal\Tests\Core\Cache\BackendChainImplementationUnitTest" file="/home/chx/www/system/core/tests/Drupal/Tests/Core/Cache/BackendChainImplementationUnitTest.php" namespace="Drupal\Tests\Core\Cache" fullPackage="Drupal.Tests.Core.Cache" tests="0" assertions="0" failures="0" errors="0" time="0.000000"/>
|
||||
<testsuite name="Drupal\Tests\Core\Cache\NullBackendTest" file="/home/chx/www/system/core/tests/Drupal/Tests/Core/Cache/NullBackendTest.php" namespace="Drupal\Tests\Core\Cache" fullPackage="Drupal.Tests.Core.Cache" tests="0" assertions="0" failures="0" errors="0" time="0.000000"/>
|
||||
<testsuite name="Drupal\Tests\Core\Extension\ModuleHandlerUnitTest" file="/home/chx/www/system/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerUnitTest.php" namespace="Drupal\Tests\Core\Extension" fullPackage="Drupal.Tests.Core.Extension" tests="1" assertions="0" failures="0" errors="1" time="0.002680">
|
||||
<testcase name="testloadInclude" class="Drupal\Tests\Core\Extension\ModuleHandlerUnitTest" file="/home/chx/www/system/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerUnitTest.php" line="37" assertions="0" time="0.002680">
|
||||
<error type="PHPUnit\Framework\Error\Notice">Drupal\Tests\Core\Extension\ModuleHandlerUnitTest::testloadInclude
|
||||
Undefined index: foo
|
||||
|
||||
/home/chx/www/system/core/lib/Drupal/Core/Extension/ModuleHandler.php:219
|
||||
/home/chx/www/system/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerUnitTest.php:40
|
||||
</error>
|
||||
</testcase>
|
||||
</testsuite>
|
||||
<testsuite name="Drupal\Tests\Core\NestedArrayUnitTest" file="/home/chx/www/system/core/tests/Drupal/Tests/Core/NestedArrayUnitTest.php" namespace="Drupal\Tests\Core" fullPackage="Drupal.Tests.Core" tests="0" assertions="0" failures="0" errors="0" time="0.000000"/>
|
||||
<testsuite name="Drupal\breakpoint\Tests\BreakpointMediaQueryTest" file="/home/chx/www/system/core/modules/breakpoint/tests/Drupal/breakpoint/Tests/BreakpointMediaQueryTest.php" namespace="Drupal\breakpoint\Tests" fullPackage="Drupal.breakpoint.Tests" tests="0" assertions="0" failures="0" errors="0" time="0.000000"/>
|
||||
<testsuite name="Drupal\Tests\Core\Route\RoleAccessCheckTest" file="/var/www/d8/core/tests/Drupal/Tests/Core/Route/RoleAccessCheckTestkTest.php" namespace="Drupal\Tests\Core\Route" fullPackage="Drupal.Tests.Core.Route" tests="3" assertions="3" failures="3" errors="0" time="0.009176">
|
||||
<testsuite name="Drupal\Tests\Core\Route\RoleAccessCheckTest::testRoleAccess" tests="3" assertions="3" failures="3" errors="0" time="0.009176">
|
||||
<testcase name="testRoleAccess with data set #0" assertions="1" time="0.004519">
|
||||
<failure type="PHPUnit\Framework\ExpectationFailedException">Drupal\Tests\Core\Route\RoleAccessCheckTest::testRoleAccess with data set #0 ('role_test_1', array(Drupal\user\Entity\User, Drupal\user\Entity\User))
|
||||
Access granted for user with the roles role_test_1 on path: role_test_1
|
||||
Failed asserting that false is true.
|
||||
</failure>
|
||||
</testcase>
|
||||
<testcase name="testRoleAccess with data set #1" assertions="1" time="0.002354">
|
||||
<failure type="PHPUnit\Framework\ExpectationFailedException">Drupal\Tests\Core\Route\RoleAccessCheckTest::testRoleAccess with data set #1 ('role_test_2', array(Drupal\user\Entity\User, Drupal\user\Entity\User))
|
||||
Access granted for user with the roles role_test_2 on path: role_test_2
|
||||
Failed asserting that false is true.
|
||||
</failure>
|
||||
</testcase>
|
||||
<testcase name="testRoleAccess with data set #2" assertions="1" time="0.002303">
|
||||
<failure type="PHPUnit\Framework\ExpectationFailedException">Drupal\Tests\Core\Route\RoleAccessCheckTest::testRoleAccess with data set #2 ('role_test_3', array(Drupal\user\Entity\User))
|
||||
Access granted for user with the roles role_test_1, role_test_2 on path: role_test_3
|
||||
Failed asserting that false is true.
|
||||
</failure>
|
||||
</testcase>
|
||||
</testsuite>
|
||||
</testsuite>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
@@ -0,0 +1,4 @@
|
||||
<select name="test">
|
||||
<option value="1">One</option>
|
||||
<option value="2" selected="selected">Two</option>
|
||||
</select>
|
||||
@@ -0,0 +1,4 @@
|
||||
<select name="test">
|
||||
<option value="1">One</option>
|
||||
<option value="2">Two</option>
|
||||
</select>
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
// phpcs:ignoreFile
|
||||
|
||||
namespace Drupal\Tests\simpletest\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* A PHPUnit-based browser test that will be run from Simpletest.
|
||||
*
|
||||
* To avoid accidentally running it is not in a normal PSR-4 directory.
|
||||
*
|
||||
* @group simpletest
|
||||
*/
|
||||
class SimpletestPhpunitBrowserTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Dummy test that logs the visited front page for HTML output.
|
||||
*/
|
||||
public function testOutput() {
|
||||
$this->drupalGet('<front>');
|
||||
$this->assertSession()->responseContains('<h2>TEST escaping</h2>');
|
||||
}
|
||||
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
// phpcs:ignoreFile
|
||||
|
||||
namespace Drupal\Tests\simpletest\Unit;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* This test crashes PHP.
|
||||
*
|
||||
* To avoid accidentally running, it is not in a normal PSR-4 directory, the
|
||||
* file name does not adhere to PSR-4 and an environment variable also needs to
|
||||
* be set for the crash to happen.
|
||||
*
|
||||
* @see \Drupal\Tests\simpletest\Unit\SimpletestPhpunitRunCommandTest::testSimpletestPhpUnitRunCommand()
|
||||
*/
|
||||
class SimpletestPhpunitRunCommandTestWillDie extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* Performs the status specified by SimpletestPhpunitRunCommandTestWillDie.
|
||||
*/
|
||||
public function testWillDie() {
|
||||
$status = (int) getenv('SimpletestPhpunitRunCommandTestWillDie');
|
||||
if ($status == 0) {
|
||||
$this->assertTrue(TRUE, 'Assertion to ensure test pass');
|
||||
return;
|
||||
}
|
||||
exit($status);
|
||||
}
|
||||
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
name: 'Simpletest deprecation test'
|
||||
type: module
|
||||
description: 'Support module for Simpletest deprecation tests.'
|
||||
package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Mock module for testing simpletest.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_simpletest_alter().
|
||||
*
|
||||
* This hook is deprecated and should trigger a deprecation error when invoked.
|
||||
*/
|
||||
function simpletest_deprecation_test_simpletest_alter(&$groups) {
|
||||
// No-op.
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_test_group_started().
|
||||
*
|
||||
* This hook is deprecated and should trigger a deprecation error when invoked.
|
||||
*/
|
||||
function simpletest_deprecation_test_test_group_started() {
|
||||
// No-op.
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_test_group_finished().
|
||||
*
|
||||
* This hook is deprecated and should trigger a deprecation error when invoked.
|
||||
*/
|
||||
function simpletest_deprecation_test_test_group_finished() {
|
||||
// No-op.
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_test_finished().
|
||||
*
|
||||
* This hook is deprecated and should trigger a deprecation error when invoked.
|
||||
*/
|
||||
function simpletest_deprecation_test_test_finished($results) {
|
||||
// No-op.
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\simpletest\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
use Drupal\Core\Url;
|
||||
|
||||
/**
|
||||
* Verifies that tests in other installation profiles are found.
|
||||
*
|
||||
* @group simpletest
|
||||
* @group legacy
|
||||
*
|
||||
* @see \Drupal\simpletest\Tests\InstallationProfileModuleTestsTest
|
||||
*/
|
||||
class OtherInstallationProfileTestsTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['simpletest'];
|
||||
|
||||
/**
|
||||
* Use the Minimal profile.
|
||||
*
|
||||
* The Testing profile contains drupal_system_listing_compatible_test.test,
|
||||
* which should be found.
|
||||
*
|
||||
* The Standard profile contains \Drupal\standard\Tests\StandardTest, which
|
||||
* should be found.
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
* @see \Drupal\simpletest\Tests\InstallationProfileModuleTestsTest
|
||||
* @see \Drupal\Tests\drupal_system_listing_compatible_test\Kernel\SystemListingCrossProfileCompatibleTest
|
||||
*/
|
||||
protected $profile = 'minimal';
|
||||
|
||||
/**
|
||||
* An administrative user with permission to administer unit tests.
|
||||
*
|
||||
* @var \Drupal\user\UserInterface
|
||||
*/
|
||||
protected $adminUser;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->adminUser = $this->drupalCreateUser(['administer unit tests']);
|
||||
$this->drupalLogin($this->adminUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that tests located in another installation profile appear.
|
||||
*
|
||||
* @expectedDeprecation Drupal\simpletest\TestDiscovery is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\TestDiscovery instead. See https://www.drupal.org/node/2949692
|
||||
*/
|
||||
public function testOtherInstallationProfile() {
|
||||
// Assert the existence of a test in a different installation profile than
|
||||
// the current.
|
||||
$this->drupalGet(Url::fromRoute('simpletest.test_form'));
|
||||
$this->assertText('Tests Standard installation profile expectations.');
|
||||
|
||||
// Assert the existence of a test for a module in a different installation
|
||||
// profile than the current.
|
||||
$this->assertText('Drupal\Tests\drupal_system_listing_compatible_test\Kernel\SystemListingCrossProfileCompatibleTest');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\simpletest\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Basic functionality of the Testing module.
|
||||
*
|
||||
* @group simpletest
|
||||
*/
|
||||
class SimpletestTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['simpletest'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $defaultTheme = 'stark';
|
||||
|
||||
/**
|
||||
* Test that we can uninstall the module without mishap.
|
||||
*
|
||||
* Upon uninstall, simpletest will clean up after itself. This should neither
|
||||
* break the test runner's expectations, nor cause any kind of exception.
|
||||
*
|
||||
* Note that this might break run-tests.sh test runs that don't use the
|
||||
* --sqlite argument.
|
||||
*/
|
||||
public function testUninstallModule() {
|
||||
/* @var $installer \Drupal\Core\Extension\ModuleInstallerInterface */
|
||||
$installer = $this->container->get('module_installer');
|
||||
$this->assertTrue($installer->uninstall(['simpletest']));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?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 #slow
|
||||
* @group simpletest
|
||||
* @group legacy
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @expectedDeprecation Drupal\simpletest\TestDiscovery is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\TestDiscovery instead. See https://www.drupal.org/node/2949692
|
||||
*/
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\simpletest\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Fixture test that is executed during Simpletest UI testing.
|
||||
*
|
||||
* @see \Drupal\simpletest\Tests::testTestingThroughUI()
|
||||
*
|
||||
* @group simpletest
|
||||
* @group legacy
|
||||
*/
|
||||
class ThroughUITest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* This test method must always pass.
|
||||
*/
|
||||
public function testThroughUi() {
|
||||
$this->pass('Success!');
|
||||
}
|
||||
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\simpletest\Kernel\Cache\Context;
|
||||
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\simpletest\Cache\Context\TestDiscoveryCacheContext;
|
||||
use Drupal\simpletest\TestDiscovery;
|
||||
|
||||
/**
|
||||
* @group simpletest
|
||||
* @group legacy
|
||||
*/
|
||||
class TestDiscoveryCacheContextTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['simpletest'];
|
||||
|
||||
/**
|
||||
* Tests that test context hashes are unique.
|
||||
*
|
||||
* @expectedDeprecation Drupal\simpletest\TestDiscovery is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\TestDiscovery instead. See https://www.drupal.org/node/2949692
|
||||
*/
|
||||
public function testContext() {
|
||||
// Mock test discovery.
|
||||
$discovery = $this->getMockBuilder(TestDiscovery::class)
|
||||
->setMethods(['getTestClasses'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
// Set getTestClasses() to return different results on subsequent calls.
|
||||
// This emulates changed tests in the filesystem.
|
||||
$discovery->expects($this->any())
|
||||
->method('getTestClasses')
|
||||
->willReturnOnConsecutiveCalls(
|
||||
['group1' => ['Test']],
|
||||
['group2' => ['Test2']]
|
||||
);
|
||||
|
||||
// Make our cache context object.
|
||||
$cache_context = new TestDiscoveryCacheContext($discovery, $this->container->get('private_key'));
|
||||
|
||||
// Generate a context hash.
|
||||
$context_hash = $cache_context->getContext();
|
||||
|
||||
// Since the context stores the hash, we have to reset it.
|
||||
$hash_ref = new \ReflectionProperty($cache_context, 'hash');
|
||||
$hash_ref->setAccessible(TRUE);
|
||||
$hash_ref->setValue($cache_context, NULL);
|
||||
|
||||
// And then assert that we did not generate the same hash for different
|
||||
// content.
|
||||
$this->assertNotSame($context_hash, $cache_context->getContext());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\simpletest\Kernel;
|
||||
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\Core\Test\EnvironmentCleanerInterface;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
|
||||
/**
|
||||
* Verify deprecation errors for the cleanup functions.
|
||||
*
|
||||
* @group simpletest
|
||||
* @group legacy
|
||||
*/
|
||||
class DeprecatedCleanupTest extends KernelTestBase {
|
||||
|
||||
public static $modules = ['simpletest'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function register(ContainerBuilder $container) {
|
||||
parent::register($container);
|
||||
$cleaner_definition = new Definition(StubEnvironmentCleanerService::class);
|
||||
$container->setDefinition('environment_cleaner', $cleaner_definition);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedDeprecation simpletest_clean_environment is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Access the environment_cleaner service and call its cleanEnvironment() method, or use \Drupal\Core\Test\EnvironmentCleaner::cleanEnvironment() instead.. See https://www.drupal.org/node/3076634
|
||||
* @expectedDeprecation simpletest_clean_database is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Access the environment_cleaner service and call its cleanDatabase() method, or use \Drupal\Core\Test\EnvironmentCleaner::cleanDatabase() instead. See https://www.drupal.org/node/3076634
|
||||
* @expectedDeprecation simpletest_clean_temporary_directories is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Access the environment_cleaner service and call its cleanTemporaryDirectories() method, or use \Drupal\Core\Test\EnvironmentCleaner::cleanTemporaryDirectories() instead. See https://www.drupal.org/node/3076634
|
||||
* @expectedDeprecation simpletest_clean_results_table is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Access the environment_cleaner service and call its cleanResultsTable() method, or use \Drupal\Core\Test\EnvironmentCleaner::cleanResultsTable() instead. See https://www.drupal.org/node/3076634
|
||||
*/
|
||||
public function testDeprecatedCleanFunctions() {
|
||||
$this->assertNull(simpletest_clean_environment());
|
||||
$this->assertNull(simpletest_clean_database());
|
||||
$this->assertNull(simpletest_clean_temporary_directories());
|
||||
$this->assertEquals(0, simpletest_clean_results_table());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock environment_cleaner service that does not perform any cleaning.
|
||||
*/
|
||||
class StubEnvironmentCleanerService implements EnvironmentCleanerInterface {
|
||||
|
||||
public function cleanDatabase() {
|
||||
|
||||
}
|
||||
|
||||
public function cleanEnvironment($clear_results = TRUE, $clear_temp_directories = TRUE, $clear_database = TRUE) {
|
||||
|
||||
}
|
||||
|
||||
public function cleanResultsTable($test_id = NULL) {
|
||||
|
||||
}
|
||||
|
||||
public function cleanTemporaryDirectories() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\simpletest\Kernel\Migrate\d6;
|
||||
|
||||
use Drupal\Tests\SchemaCheckTestTrait;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Upgrade variables to simpletest.settings.yml.
|
||||
*
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateSimpletestConfigsTest extends MigrateDrupal6TestBase {
|
||||
|
||||
use SchemaCheckTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['simpletest'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installConfig(['simpletest']);
|
||||
$this->executeMigration('d6_simpletest_settings');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration of simpletest variables to simpletest.settings.yml.
|
||||
*/
|
||||
public function testSimpletestSettings() {
|
||||
$config = $this->config('simpletest.settings');
|
||||
$this->assertIdentical(TRUE, $config->get('clear_results'));
|
||||
$this->assertIdentical(CURLAUTH_BASIC, $config->get('httpauth.method'));
|
||||
// NULL in the dump means defaults which is empty string. Same as omitting
|
||||
// them.
|
||||
$this->assertIdentical('', $config->get('httpauth.password'));
|
||||
$this->assertIdentical('', $config->get('httpauth.username'));
|
||||
$this->assertIdentical(TRUE, $config->get('verbose'));
|
||||
$this->assertConfigSchema(\Drupal::service('config.typed'), 'simpletest.settings', $config->get());
|
||||
}
|
||||
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\simpletest\Kernel\Migrate\d7;
|
||||
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
|
||||
|
||||
/**
|
||||
* Tests migration of SimpleTest's variables to configuration.
|
||||
*
|
||||
* @group simpletest
|
||||
*/
|
||||
class MigrateSimpletestSettingsTest extends MigrateDrupal7TestBase {
|
||||
|
||||
public static $modules = ['simpletest'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installConfig(static::$modules);
|
||||
$this->executeMigration('d7_simpletest_settings');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration of SimpleTest settings to configuration.
|
||||
*/
|
||||
public function testMigration() {
|
||||
$config = \Drupal::config('simpletest.settings')->get();
|
||||
$this->assertTrue($config['clear_results']);
|
||||
$this->assertIdentical(CURLAUTH_BASIC, $config['httpauth']['method']);
|
||||
$this->assertIdentical('testbot', $config['httpauth']['username']);
|
||||
$this->assertIdentical('foobaz', $config['httpauth']['password']);
|
||||
$this->assertTrue($config['verbose']);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\simpletest\Kernel;
|
||||
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
* Tests PHPUnit errors are getting converted to Simpletest errors.
|
||||
*
|
||||
* @group simpletest
|
||||
* @group legacy
|
||||
*/
|
||||
class PhpUnitErrorTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* Enable the simpletest module.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected static $modules = ['simpletest'];
|
||||
|
||||
/**
|
||||
* Test errors reported.
|
||||
*
|
||||
* @expectedDeprecation simpletest_phpunit_xml_to_rows is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\JUnitConverter::xmlToRows() instead. See https://www.drupal.org/node/2948547
|
||||
*/
|
||||
public function testPhpUnitXmlParsing() {
|
||||
$phpunit_error_xml = __DIR__ . '/../../fixtures/phpunit_error.xml';
|
||||
|
||||
$res = simpletest_phpunit_xml_to_rows(1, $phpunit_error_xml);
|
||||
$this->assertCount(4, $res, 'All testcases got extracted');
|
||||
$this->assertNotEquals($res[0]['status'], 'pass');
|
||||
$this->assertEquals($res[0]['status'], 'fail');
|
||||
|
||||
// Test nested testsuites, which appear when you use @dataProvider.
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$this->assertNotEquals($res[$i + 1]['status'], 'pass');
|
||||
$this->assertEquals($res[$i + 1]['status'], 'fail');
|
||||
}
|
||||
|
||||
// Make sure simpletest_phpunit_xml_to_rows() does not balk if the test
|
||||
// didn't run.
|
||||
$this->assertNull(simpletest_phpunit_xml_to_rows(1, 'does_not_exist'));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\simpletest\Kernel;
|
||||
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\simpletest\TestDiscovery;
|
||||
|
||||
/**
|
||||
* Verify deprecations within the simpletest module.
|
||||
*
|
||||
* @group simpletest
|
||||
* @group legacy
|
||||
*/
|
||||
class SimpletestDeprecationTest extends KernelTestBase {
|
||||
|
||||
public static $modules = ['simpletest'];
|
||||
|
||||
/**
|
||||
* @expectedDeprecation The simpletest_phpunit_configuration_filepath function is deprecated since version 8.4.x and will be removed in 9.0.0.
|
||||
* @expectedDeprecation The simpletest_test_get_all function is deprecated in version 8.3.x and will be removed in 9.0.0. Use \Drupal::service('test_discovery')->getTestClasses($extension, $types) instead.
|
||||
* @expectedDeprecation The simpletest_classloader_register function is deprecated in version 8.3.x and will be removed in 9.0.0. Use \Drupal::service('test_discovery')->registerTestNamespaces() instead.
|
||||
*/
|
||||
public function testDeprecatedFunctions() {
|
||||
$this->assertNotEmpty(simpletest_phpunit_configuration_filepath());
|
||||
$this->assertNotEmpty(simpletest_test_get_all());
|
||||
simpletest_classloader_register();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedDeprecation Drupal\simpletest\TestDiscovery is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\TestDiscovery instead. See https://www.drupal.org/node/2949692
|
||||
* @expectedDeprecation The "test_discovery" service relies on the deprecated "Drupal\simpletest\TestDiscovery" class. It should either be deprecated or its implementation upgraded.
|
||||
*/
|
||||
public function testDeprecatedServices() {
|
||||
$this->assertInstanceOf(TestDiscovery::class, $this->container->get('test_discovery'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedDeprecation simpletest_phpunit_xml_filepath is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\PhpUnitTestRunner::xmlLogFilepath() instead. See https://www.drupal.org/node/2948547
|
||||
* @expectedDeprecation simpletest_phpunit_command is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\PhpUnitTestRunner::phpUnitCommand() instead. See https://www.drupal.org/node/2948547
|
||||
* @expectedDeprecation simpletest_phpunit_find_testcases is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\JUnitConverter::findTestCases() instead. See https://www.drupal.org/node/2948547
|
||||
* @expectedDeprecation simpletest_phpunit_testcase_to_row is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\JUnitConverter::convertTestCaseToSimpletestRow() instead. See https://www.drupal.org/node/2948547
|
||||
* @expectedDeprecation simpletest_summarize_phpunit_result is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\PhpUnitTestRunner::summarizeResults() instead. See https://www.drupal.org/node/2948547
|
||||
*/
|
||||
public function testDeprecatedPhpUnitFunctions() {
|
||||
// We can't test the deprecation errors for the following functions because
|
||||
// they cannot be mocked, and calling them would change the test results:
|
||||
// - simpletest_run_phpunit_tests().
|
||||
// - simpletest_phpunit_run_command().
|
||||
// - simpletest_phpunit_xml_to_rows().
|
||||
$this->assertStringEndsWith('/phpunit-23.xml', simpletest_phpunit_xml_filepath(23));
|
||||
|
||||
$this->assertInternalType('string', simpletest_phpunit_command());
|
||||
|
||||
$this->assertEquals([], simpletest_phpunit_find_testcases(new \SimpleXMLElement('<not_testcase></not_testcase>')));
|
||||
|
||||
$this->assertEquals([
|
||||
'test_id' => 23,
|
||||
'test_class' => '',
|
||||
'status' => 'pass',
|
||||
'message' => '',
|
||||
'message_group' => 'Other',
|
||||
'function' => '->()',
|
||||
'line' => 0,
|
||||
'file' => NULL,
|
||||
], simpletest_phpunit_testcase_to_row(23, new \SimpleXMLElement('<not_testcase></not_testcase>')));
|
||||
|
||||
$this->assertEquals(
|
||||
[
|
||||
static::class => [
|
||||
'#pass' => 0,
|
||||
'#fail' => 0,
|
||||
'#exception' => 0,
|
||||
'#debug' => 1,
|
||||
],
|
||||
],
|
||||
simpletest_summarize_phpunit_result([
|
||||
[
|
||||
'test_class' => static::class,
|
||||
'status' => 'debug',
|
||||
],
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedDeprecation simpletest_generate_file() is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Tests\TestFileCreationTrait::generateFile() instead. See https://www.drupal.org/node/3077768
|
||||
*/
|
||||
public function testDeprecatedSimpletestGenerateFile() {
|
||||
$file = simpletest_generate_file('foo', 40, 10);
|
||||
$public_file = 'public://' . $file . '.txt';
|
||||
$this->assertFileExists($public_file);
|
||||
$this->assertTrue(unlink($public_file));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedDeprecation simpletest_process_phpunit_results() is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\TestDatabase::processPhpUnitResults() instead. See https://www.drupal.org/node/3075252
|
||||
*/
|
||||
public function testProcessPhpUnitResults() {
|
||||
// The only safe way to test this deprecation is to call it with an empty
|
||||
// result set. This should not touch the results database.
|
||||
$this->assertNull(simpletest_process_phpunit_results([]));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\simpletest\Kernel;
|
||||
|
||||
use Drupal\Core\Database\Connection;
|
||||
use Drupal\Core\Database\Query\Insert;
|
||||
use Drupal\Core\Render\Renderer;
|
||||
use Drupal\Core\StreamWrapper\PublicStream;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\simpletest\TestDiscovery;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
/**
|
||||
* Test the deprecation messages for Simpletest test hooks.
|
||||
*
|
||||
* @group simpletest
|
||||
* @group legacy
|
||||
*/
|
||||
class TestDeprecatedTestHooks extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['simpletest', 'simpletest_deprecation_test'];
|
||||
|
||||
/**
|
||||
* @expectedDeprecation The deprecated hook hook_test_group_finished() is implemented in these functions: simpletest_deprecation_test_test_group_finished(). Convert your test to a PHPUnit-based one and implement test listeners. See https://www.drupal.org/node/2934242
|
||||
*/
|
||||
public function testHookTestGroupFinished() {
|
||||
// @todo Mock the messenger service and add expectations when
|
||||
// \Drupal::messenger() actually uses the service.
|
||||
// @see https://www.drupal.org/node/2928994
|
||||
$this->assertNull(_simpletest_batch_finished(TRUE, [], [], 10));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedDeprecation The deprecated hook hook_test_group_started() is implemented in these functions: simpletest_deprecation_test_test_group_started(). Convert your test to a PHPUnit-based one and implement test listeners. See https://www.drupal.org/node/2934242
|
||||
*/
|
||||
public function testHookTestGroupStarted() {
|
||||
// Mock a database connection enough for simpletest_run_tests().
|
||||
$insert = $this->getMockBuilder(Insert::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['execute', 'useDefaults'])
|
||||
->getMock();
|
||||
$insert->expects($this->any())
|
||||
->method('useDefaults')
|
||||
->willReturn($insert);
|
||||
$insert->expects($this->any())
|
||||
->method('execute')
|
||||
// Return an arbitrary test ID.
|
||||
->willReturn(__METHOD__);
|
||||
|
||||
$connection = $this->getMockBuilder(Connection::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['insert'])
|
||||
->getMockForAbstractClass();
|
||||
$connection->expects($this->once())
|
||||
->method('insert')
|
||||
->willReturn($insert);
|
||||
|
||||
// Mock public stream wrapper enough for simpletest_run_tests().
|
||||
$public = $this->getMockBuilder(PublicStream::class)
|
||||
->disableOriginalConstructor()
|
||||
// Mock all methods to do nothing and return NULL.
|
||||
->setMethods([])
|
||||
->getMock();
|
||||
|
||||
// Set up the container.
|
||||
$this->container->set('database', $connection);
|
||||
$this->container->set('stream_wrapper.public', $public);
|
||||
|
||||
// Make sure our mocked database is in use by expecting a test ID that is
|
||||
// __METHOD__.
|
||||
$this->assertEquals(__METHOD__, simpletest_run_tests([static::class]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedDeprecation The deprecated hook hook_test_finished() is implemented in these functions: simpletest_deprecation_test_test_finished(). Convert your test to a PHPUnit-based one and implement test listeners. See https://www.drupal.org/node/2934242
|
||||
*/
|
||||
public function testHookTestFinished() {
|
||||
// Mock test_discovery.
|
||||
$discovery = $this->getMockBuilder(TestDiscovery::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['registerTestNamespaces'])
|
||||
->getMock();
|
||||
$discovery->expects($this->once())
|
||||
->method('registerTestNamespaces')
|
||||
->willReturn([]);
|
||||
|
||||
// Mock renderer.
|
||||
$renderer = $this->getMockBuilder(Renderer::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['render'])
|
||||
->getMock();
|
||||
// We don't care what the rendered batch elements look like.
|
||||
$renderer->expects($this->any())
|
||||
->method('render')
|
||||
->willReturn('');
|
||||
|
||||
// Set up the container.
|
||||
$this->container->set('test_discovery', $discovery);
|
||||
$this->container->set('renderer', $renderer);
|
||||
|
||||
// A mock batch.
|
||||
$context = [];
|
||||
|
||||
// InnocuousTest is a WebTestBase test class which passes and never touches
|
||||
// the database.
|
||||
_simpletest_batch_operation([InnocuousTest::class], __METHOD__, $context);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A very simple WebTestBase test that never touches the database.
|
||||
*
|
||||
* @group WebTestBase
|
||||
* @group legacy
|
||||
*/
|
||||
class InnocuousTest extends WebTestBase {
|
||||
|
||||
/**
|
||||
* Override to prevent any environmental side-effects.
|
||||
*/
|
||||
protected function prepareEnvironment() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Override run() since it uses TestBase.
|
||||
*/
|
||||
public function run(array $methods = []) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to prevent any assertions from being stored.
|
||||
*/
|
||||
protected function storeAssertion(array $assertion) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to prevent any assertions from being stored.
|
||||
*/
|
||||
public static function insertAssert($test_id, $test_class, $status, $message = '', $group = 'Other', array $caller = []) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\simpletest\Kernel;
|
||||
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\simpletest\TestDiscovery;
|
||||
|
||||
/**
|
||||
* @group simpletest
|
||||
* @group legacy
|
||||
*
|
||||
* @coversDefaultClass \Drupal\simpletest\TestDiscovery
|
||||
*/
|
||||
class TestDiscoveryDeprecationTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['simpletest', 'simpletest_deprecation_test'];
|
||||
|
||||
/**
|
||||
* @expectedDeprecation The deprecated alter hook hook_simpletest_alter() is implemented in these functions: simpletest_deprecation_test_simpletest_alter. Convert your test to a PHPUnit-based one and implement test listeners. See: https://www.drupal.org/node/2939892
|
||||
* @covers ::getTestClasses
|
||||
*/
|
||||
public function testHookSimpletestAlter() {
|
||||
$test_discovery = $this->container->get('test_discovery');
|
||||
|
||||
$this->assertEquals(TestDiscovery::class, get_class($test_discovery));
|
||||
|
||||
// The simpletest_test module implements hook_simpletest_alter(), which
|
||||
// should trigger a deprecation error during getTestClasses().
|
||||
$this->assertNotEmpty($test_discovery->getTestClasses());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\simpletest\Unit;
|
||||
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\Core\File\FileSystemInterface;
|
||||
use Drupal\Core\Test\PhpUnitTestRunner;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Tests simpletest_run_phpunit_tests() handles PHPunit fatals correctly.
|
||||
*
|
||||
* We don't extend \Drupal\Tests\UnitTestCase here because its $root property is
|
||||
* not static and we need it to be static here.
|
||||
*
|
||||
* The file simpletest_phpunit_run_command_test.php contains the test class
|
||||
* \Drupal\Tests\simpletest\Unit\SimpletestPhpunitRunCommandTestWillDie which
|
||||
* can be made to exit with result code 2. It lives in a file which won't be
|
||||
* autoloaded, so that it won't fail test runs.
|
||||
*
|
||||
* Here, we run SimpletestPhpunitRunCommandTestWillDie, make it die, and see
|
||||
* what happens.
|
||||
*
|
||||
* @group simpletest
|
||||
* @group legacy
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
class SimpletestPhpunitRunCommandTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Path to the app root.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $root;
|
||||
|
||||
/**
|
||||
* A fixture container.
|
||||
*
|
||||
* @var \Symfony\Component\DependencyInjection\ContainerInterface
|
||||
*/
|
||||
protected $fixtureContainer;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function setUpBeforeClass() {
|
||||
parent::setUpBeforeClass();
|
||||
// Figure out our app root.
|
||||
self::$root = dirname(dirname(dirname(dirname(dirname(dirname(__DIR__))))));
|
||||
// Include the files we need for tests. The stub test we will run is
|
||||
// SimpletestPhpunitRunCommandTestWillDie which is located in
|
||||
// simpletest_phpunit_run_command_test.php.
|
||||
include_once self::$root . '/core/modules/simpletest/tests/fixtures/simpletest_phpunit_run_command_test.php';
|
||||
// Since we're testing simpletest_run_phpunit_tests(), we need to include
|
||||
// simpletest.module.
|
||||
include_once self::$root . '/core/modules/simpletest/simpletest.module';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
// Organize our mock container.
|
||||
$container = new ContainerBuilder();
|
||||
$container->set('app.root', self::$root);
|
||||
$file_system = $this->prophesize(FileSystemInterface::class);
|
||||
// The simpletest directory wrapper will always point to /tmp.
|
||||
$file_system->realpath('public://simpletest')->willReturn(sys_get_temp_dir());
|
||||
$container->set('file_system', $file_system->reveal());
|
||||
\Drupal::setContainer($container);
|
||||
$this->fixtureContainer = $container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testSimpletestPhpUnitRunCommand().
|
||||
*
|
||||
* @return array
|
||||
* Arrays of status codes and the label they're expected to have.
|
||||
*/
|
||||
public function provideStatusCodes() {
|
||||
$data = [
|
||||
[0, 'pass'],
|
||||
[1, 'fail'],
|
||||
[2, 'exception'],
|
||||
];
|
||||
// All status codes 3 and above should be labeled 'error'.
|
||||
// @todo: The valid values here would be 3 to 127. But since the test
|
||||
// touches the file system a lot, we only have 3, 4, and 127 for speed.
|
||||
foreach ([3, 4, 127] as $status) {
|
||||
$data[] = [$status, 'error'];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the round trip for PHPUnit execution status codes.
|
||||
*
|
||||
* Also tests backwards-compatibility of PhpUnitTestRunner::runTests().
|
||||
*
|
||||
* @covers ::simpletest_run_phpunit_tests
|
||||
*
|
||||
* @dataProvider provideStatusCodes
|
||||
*
|
||||
* @expectedDeprecation simpletest_run_phpunit_tests is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\PhpUnitTestRunner::runTests() instead. See https://www.drupal.org/node/2948547
|
||||
* @expectedDeprecation simpletest_phpunit_xml_filepath is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\PhpUnitTestRunner::xmlLogFilepath() instead. See https://www.drupal.org/node/2948547
|
||||
*/
|
||||
public function testSimpletestPhpUnitRunCommand($status, $label) {
|
||||
// Add a default database connection in order for
|
||||
// Database::getConnectionInfoAsUrl() to return valid information.
|
||||
Database::addConnectionInfo('default', 'default', [
|
||||
'driver' => 'mysql',
|
||||
'username' => 'test_user',
|
||||
'password' => 'test_pass',
|
||||
'host' => 'test_host',
|
||||
'database' => 'test_database',
|
||||
'port' => 3306,
|
||||
'namespace' => 'Drupal\Core\Database\Driver\mysql',
|
||||
]
|
||||
);
|
||||
$test_id = basename(tempnam(sys_get_temp_dir(), 'xxx'));
|
||||
putenv('SimpletestPhpunitRunCommandTestWillDie=' . $status);
|
||||
|
||||
// Test against simpletest_run_phpunit_tests().
|
||||
$bc_ret = simpletest_run_phpunit_tests($test_id, [SimpletestPhpunitRunCommandTestWillDie::class]);
|
||||
$this->assertSame($bc_ret[0]['status'], $label);
|
||||
|
||||
// Test against PhpUnitTestRunner::runTests().
|
||||
$runner = PhpUnitTestRunner::create($this->fixtureContainer);
|
||||
$ret = $runner->runTests($test_id, [SimpletestPhpunitRunCommandTestWillDie::class]);
|
||||
$this->assertSame($ret[0]['status'], $label);
|
||||
|
||||
// Unset our environmental variable.
|
||||
putenv('SimpletestPhpunitRunCommandTestWillDie');
|
||||
unlink(simpletest_phpunit_xml_filepath($test_id));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function tearDown() {
|
||||
// We unset the $base_url global, since the test code sets it as a
|
||||
// side-effect.
|
||||
unset($GLOBALS['base_url']);
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?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 [
|
||||
['&"'<>', '&"\'<>'],
|
||||
['<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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,470 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\simpletest\Unit;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @requires extension curl
|
||||
* @coversDefaultClass \Drupal\simpletest\TestBase
|
||||
* @group simpletest
|
||||
* @group TestBase
|
||||
*/
|
||||
class TestBaseTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* Helper method for constructing a mock TestBase object.
|
||||
*
|
||||
* TestBase is abstract, so we have to mock it. We'll also
|
||||
* mock the storeAssertion() method so we don't need the database.
|
||||
*
|
||||
* @param string $test_id
|
||||
* An identifying name for the mocked test.
|
||||
*
|
||||
* @return object
|
||||
* Mock of Drupal\simpletest\TestBase.
|
||||
*/
|
||||
public function getTestBaseForAssertionTests($test_id) {
|
||||
$mock_test_base = $this->getMockBuilder('Drupal\simpletest\TestBase')
|
||||
->setConstructorArgs([$test_id])
|
||||
->setMethods(['storeAssertion'])
|
||||
->getMockForAbstractClass();
|
||||
// Override storeAssertion() so we don't need a database.
|
||||
$mock_test_base->expects($this->any())
|
||||
->method('storeAssertion')
|
||||
->will($this->returnValue(NULL));
|
||||
return $mock_test_base;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke methods that are protected or private.
|
||||
*
|
||||
* @param object $object
|
||||
* Object on which to invoke the method.
|
||||
* @param string $method_name
|
||||
* Name of the method to invoke.
|
||||
* @param array $arguments
|
||||
* Array of arguments to be passed to the method.
|
||||
*
|
||||
* @return mixed
|
||||
* Value returned by the invoked method.
|
||||
*/
|
||||
public function invokeProtectedMethod($object, $method_name, array $arguments) {
|
||||
$ref_method = new \ReflectionMethod($object, $method_name);
|
||||
$ref_method->setAccessible(TRUE);
|
||||
return $ref_method->invokeArgs($object, $arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides data for the random string validation test.
|
||||
*
|
||||
* @return array
|
||||
* - The expected result of the validation.
|
||||
* - The string to validate.
|
||||
*/
|
||||
public function providerRandomStringValidate() {
|
||||
return [
|
||||
[FALSE, ' curry paste'],
|
||||
[FALSE, 'curry paste '],
|
||||
[FALSE, 'curry paste'],
|
||||
[FALSE, 'curry paste'],
|
||||
[TRUE, 'curry paste'],
|
||||
[TRUE, 'thai green curry paste'],
|
||||
[TRUE, '@startswithat'],
|
||||
[TRUE, 'contains@at'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::randomStringValidate
|
||||
* @dataProvider providerRandomStringValidate
|
||||
*/
|
||||
public function testRandomStringValidate($expected, $string) {
|
||||
$mock_test_base = $this->getMockForAbstractClass('Drupal\simpletest\TestBase');
|
||||
$actual = $mock_test_base->randomStringValidate($string);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides data for testRandomString() and others.
|
||||
*
|
||||
* @return array
|
||||
* - The number of items (characters, object properties) we expect any of
|
||||
* the random functions to give us.
|
||||
*/
|
||||
public function providerRandomItems() {
|
||||
return [
|
||||
[NULL],
|
||||
[0],
|
||||
[1],
|
||||
[2],
|
||||
[3],
|
||||
[4],
|
||||
[7],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::randomString
|
||||
* @dataProvider providerRandomItems
|
||||
*/
|
||||
public function testRandomString($length) {
|
||||
$mock_test_base = $this->getMockForAbstractClass('Drupal\simpletest\TestBase');
|
||||
$string = $mock_test_base->randomString($length);
|
||||
$this->assertEquals($length, strlen($string));
|
||||
// randomString() should always include an ampersand ('&') and a
|
||||
// greater than ('>') if $length is greater than 3.
|
||||
if ($length > 4) {
|
||||
$this->assertContains('&', $string);
|
||||
$this->assertContains('>', $string);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::randomObject
|
||||
* @dataProvider providerRandomItems
|
||||
*/
|
||||
public function testRandomObject($size) {
|
||||
$test_base = $this->getTestBaseForAssertionTests('test_id');
|
||||
// Note: count((array)object) works for now, maybe not later.
|
||||
$this->assertEquals($size, count((array) $test_base->randomObject($size)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::checkRequirements
|
||||
*/
|
||||
public function testCheckRequirements() {
|
||||
$test_base = $this->getTestBaseForAssertionTests('test_id');
|
||||
$this->assertInternalType(
|
||||
'array',
|
||||
$this->invokeProtectedMethod($test_base, 'checkRequirements', [])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testAssert().
|
||||
*
|
||||
* @return array
|
||||
* Standard dataProvider array of arrays:
|
||||
* - Expected result from assert().
|
||||
* - Expected status stored in TestBase->assertions.
|
||||
* - Status, passed to assert().
|
||||
* - Message, passed to assert().
|
||||
* - Group, passed to assert().
|
||||
* - Caller, passed to assert().
|
||||
*/
|
||||
public function providerAssert() {
|
||||
return [
|
||||
[TRUE, 'pass', TRUE, 'Yay pass', 'test', []],
|
||||
[FALSE, 'fail', FALSE, 'Boo fail', 'test', []],
|
||||
[TRUE, 'pass', 'pass', 'Yay pass', 'test', []],
|
||||
[FALSE, 'fail', 'fail', 'Boo fail', 'test', []],
|
||||
[FALSE, 'exception', 'exception', 'Boo fail', 'test', []],
|
||||
[FALSE, 'debug', 'debug', 'Boo fail', 'test', []],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::assert
|
||||
* @dataProvider providerAssert
|
||||
*/
|
||||
public function testAssert($expected, $assertion_status, $status, $message, $group, $caller) {
|
||||
$test_id = 'luke_i_am_your_' . $assertion_status;
|
||||
$test_base = $this->getTestBaseForAssertionTests($test_id);
|
||||
|
||||
// Verify some startup values.
|
||||
$this->assertAttributeEmpty('assertions', $test_base);
|
||||
if (is_string($status)) {
|
||||
$this->assertEquals(0, $test_base->results['#' . $status]);
|
||||
}
|
||||
|
||||
// assert() is protected so we have to make it accessible.
|
||||
$ref_assert = new \ReflectionMethod($test_base, 'assert');
|
||||
$ref_assert->setAccessible(TRUE);
|
||||
|
||||
// Call assert() from within our hall of mirrors.
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$ref_assert->invokeArgs($test_base,
|
||||
[$status, $message, $group, $caller]
|
||||
)
|
||||
);
|
||||
|
||||
// Check the side-effects of assert().
|
||||
if (is_string($status)) {
|
||||
$this->assertEquals(1, $test_base->results['#' . $status]);
|
||||
}
|
||||
$this->assertAttributeNotEmpty('assertions', $test_base);
|
||||
// Make a ReflectionProperty for the assertions property,
|
||||
// since it's protected.
|
||||
$ref_assertions = new \ReflectionProperty($test_base, 'assertions');
|
||||
$ref_assertions->setAccessible(TRUE);
|
||||
$assertions = $ref_assertions->getValue($test_base);
|
||||
$assertion = reset($assertions);
|
||||
$this->assertEquals($assertion_status, $assertion['status']);
|
||||
$this->assertEquals($test_id, $assertion['test_id']);
|
||||
$this->assertEquals(get_class($test_base), $assertion['test_class']);
|
||||
$this->assertEquals($message, $assertion['message']);
|
||||
$this->assertEquals($group, $assertion['message_group']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for assertTrue().
|
||||
*/
|
||||
public function providerAssertTrue() {
|
||||
return [
|
||||
[TRUE, TRUE],
|
||||
[FALSE, FALSE],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::assertTrue
|
||||
* @dataProvider providerAssertTrue
|
||||
*/
|
||||
public function testAssertTrue($expected, $value) {
|
||||
$test_base = $this->getTestBaseForAssertionTests('test_id');
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$this->invokeProtectedMethod($test_base, 'assertTrue', [$value])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::assertFalse
|
||||
* @dataProvider providerAssertTrue
|
||||
*/
|
||||
public function testAssertFalse($expected, $value) {
|
||||
$test_base = $this->getTestBaseForAssertionTests('test_id');
|
||||
$this->assertEquals(
|
||||
(!$expected),
|
||||
$this->invokeProtectedMethod($test_base, 'assertFalse', [$value])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for assertNull().
|
||||
*/
|
||||
public function providerAssertNull() {
|
||||
return [
|
||||
[TRUE, NULL],
|
||||
[FALSE, ''],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::assertNull
|
||||
* @dataProvider providerAssertNull
|
||||
*/
|
||||
public function testAssertNull($expected, $value) {
|
||||
$test_base = $this->getTestBaseForAssertionTests('test_id');
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$this->invokeProtectedMethod($test_base, 'assertNull', [$value])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::assertNotNull
|
||||
* @dataProvider providerAssertNull
|
||||
*/
|
||||
public function testAssertNotNull($expected, $value) {
|
||||
$test_base = $this->getTestBaseForAssertionTests('test_id');
|
||||
$this->assertEquals(
|
||||
(!$expected),
|
||||
$this->invokeProtectedMethod($test_base, 'assertNotNull', [$value])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for tests of equality assertions.
|
||||
*
|
||||
* Used by testAssertIdentical(), testAssertEqual(), testAssertNotIdentical(),
|
||||
* and testAssertNotEqual().
|
||||
*
|
||||
* @return
|
||||
* Array of test data.
|
||||
* - Expected assertion value for identical comparison.
|
||||
* - Expected assertion value for equal comparison.
|
||||
* - First value to compare.
|
||||
* - Second value to compare.
|
||||
*/
|
||||
public function providerEqualityAssertions() {
|
||||
return [
|
||||
// Integers and floats.
|
||||
[TRUE, TRUE, 0, 0],
|
||||
[FALSE, TRUE, 0, 0.0],
|
||||
[FALSE, TRUE, '0', 0],
|
||||
[FALSE, TRUE, '0.0', 0.0],
|
||||
[FALSE, FALSE, 23, 77],
|
||||
[TRUE, TRUE, 23.0, 23.0],
|
||||
// Strings.
|
||||
[FALSE, FALSE, 'foof', 'yay'],
|
||||
[TRUE, TRUE, 'yay', 'yay'],
|
||||
// Bools with type conversion.
|
||||
[TRUE, TRUE, TRUE, TRUE],
|
||||
[TRUE, TRUE, FALSE, FALSE],
|
||||
[FALSE, TRUE, NULL, FALSE],
|
||||
[FALSE, TRUE, 'TRUE', TRUE],
|
||||
[FALSE, FALSE, 'FALSE', FALSE],
|
||||
[FALSE, TRUE, 0, FALSE],
|
||||
[FALSE, TRUE, 1, TRUE],
|
||||
[FALSE, TRUE, -1, TRUE],
|
||||
[FALSE, TRUE, '1', TRUE],
|
||||
[FALSE, TRUE, '1.3', TRUE],
|
||||
// Null.
|
||||
[FALSE, FALSE, 'NULL', NULL],
|
||||
[TRUE, TRUE, NULL, NULL],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::assertIdentical
|
||||
* @dataProvider providerEqualityAssertions
|
||||
*/
|
||||
public function testAssertIdentical($expected_identical, $expected_equal, $first, $second) {
|
||||
$test_base = $this->getTestBaseForAssertionTests('test_id');
|
||||
$this->assertEquals(
|
||||
$expected_identical,
|
||||
$this->invokeProtectedMethod($test_base, 'assertIdentical', [$first, $second])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::assertNotIdentical
|
||||
* @dataProvider providerEqualityAssertions
|
||||
*/
|
||||
public function testAssertNotIdentical($expected_identical, $expected_equal, $first, $second) {
|
||||
$test_base = $this->getTestBaseForAssertionTests('test_id');
|
||||
$this->assertEquals(
|
||||
(!$expected_identical),
|
||||
$this->invokeProtectedMethod($test_base, 'assertNotIdentical', [$first, $second])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::assertEqual
|
||||
* @dataProvider providerEqualityAssertions
|
||||
*/
|
||||
public function testAssertEqual($expected_identical, $expected_equal, $first, $second) {
|
||||
$test_base = $this->getTestBaseForAssertionTests('test_id');
|
||||
$this->assertEquals(
|
||||
$expected_equal,
|
||||
$this->invokeProtectedMethod($test_base, 'assertEqual', [$first, $second])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::assertNotEqual
|
||||
* @dataProvider providerEqualityAssertions
|
||||
*/
|
||||
public function testAssertNotEqual($expected_identical, $expected_equal, $first, $second) {
|
||||
$test_base = $this->getTestBaseForAssertionTests('test_id');
|
||||
$this->assertEquals(
|
||||
(!$expected_equal),
|
||||
$this->invokeProtectedMethod($test_base, 'assertNotEqual', [$first, $second])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testAssertIdenticalObject().
|
||||
*/
|
||||
public function providerAssertIdenticalObject() {
|
||||
$obj1 = new \stdClass();
|
||||
$obj1->foof = 'yay';
|
||||
$obj2 = $obj1;
|
||||
$obj3 = clone $obj1;
|
||||
$obj4 = new \stdClass();
|
||||
return [
|
||||
[TRUE, $obj1, $obj2],
|
||||
[TRUE, $obj1, $obj3],
|
||||
[FALSE, $obj1, $obj4],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::assertIdenticalObject
|
||||
* @dataProvider providerAssertIdenticalObject
|
||||
*/
|
||||
public function testAssertIdenticalObject($expected, $first, $second) {
|
||||
$test_base = $this->getTestBaseForAssertionTests('test_id');
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$this->invokeProtectedMethod($test_base, 'assertIdenticalObject', [$first, $second])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::pass
|
||||
*/
|
||||
public function testPass() {
|
||||
$test_base = $this->getTestBaseForAssertionTests('test_id');
|
||||
$this->assertEquals(
|
||||
TRUE,
|
||||
$this->invokeProtectedMethod($test_base, 'pass', [])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::fail
|
||||
*/
|
||||
public function testFail() {
|
||||
$test_base = $this->getTestBaseForAssertionTests('test_id');
|
||||
$this->assertEquals(
|
||||
FALSE,
|
||||
$this->invokeProtectedMethod($test_base, 'fail', [])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testError().
|
||||
*
|
||||
* @return array
|
||||
* - Expected status for assertion.
|
||||
* - Group for use in assert().
|
||||
*/
|
||||
public function providerError() {
|
||||
return [
|
||||
['debug', 'User notice'],
|
||||
['exception', 'Not User notice'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::error
|
||||
* @dataProvider providerError
|
||||
*/
|
||||
public function testError($status, $group) {
|
||||
// Mock up a TestBase object.
|
||||
$mock_test_base = $this->getMockBuilder('Drupal\simpletest\TestBase')
|
||||
->setMethods(['assert'])
|
||||
->getMockForAbstractClass();
|
||||
|
||||
// Set expectations for assert().
|
||||
$mock_test_base->expects($this->once())
|
||||
->method('assert')
|
||||
// The first argument to assert() should be the expected $status. This is
|
||||
// the most important expectation of this test.
|
||||
->with($status)
|
||||
// Arbitrary return value.
|
||||
->willReturn("$status:$group");
|
||||
|
||||
// Invoke error().
|
||||
$this->assertEquals(
|
||||
"$status:$group",
|
||||
$this->invokeProtectedMethod($mock_test_base, 'error', ['msg', $group])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getRandomGenerator
|
||||
*/
|
||||
public function testGetRandomGenerator() {
|
||||
$test_base = $this->getTestBaseForAssertionTests('test_id');
|
||||
$this->assertInstanceOf(
|
||||
'Drupal\Component\Utility\Random',
|
||||
$this->invokeProtectedMethod($test_base, 'getRandomGenerator', [])
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
<?php
|
||||
|
||||
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\TestDiscovery;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use org\bovigo\vfs\vfsStream;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\simpletest\TestDiscovery
|
||||
*
|
||||
* @group simpletest
|
||||
* @group legacy
|
||||
*/
|
||||
class TestDiscoveryTest extends UnitTestCase {
|
||||
|
||||
protected function setupVfsWithTestClasses() {
|
||||
vfsStream::setup('drupal');
|
||||
|
||||
$test_file = <<<EOF
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Test description
|
||||
* @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([
|
||||
'modules' => [
|
||||
'test_module' => [
|
||||
'test_module.info.yml' => $test_module_info,
|
||||
'tests' => [
|
||||
'src' => [
|
||||
'Functional' => [
|
||||
'FunctionalExampleTest.php' => $test_file,
|
||||
'FunctionalExampleTest2.php' => str_replace(['FunctionalExampleTest', '@group example'], ['FunctionalExampleTest2', '@group example2'], $test_file),
|
||||
],
|
||||
'Kernel' => [
|
||||
'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),
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'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),
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock a TestDiscovery object to return specific extension values.
|
||||
*/
|
||||
protected function getTestDiscoveryMock($app_root, $extensions) {
|
||||
$class_loader = $this->prophesize(ClassLoader::class);
|
||||
$module_handler = $this->prophesize(ModuleHandlerInterface::class);
|
||||
|
||||
$test_discovery = $this->getMockBuilder(TestDiscovery::class)
|
||||
->setConstructorArgs([$app_root, $class_loader->reveal(), $module_handler->reveal()])
|
||||
->setMethods(['getExtensions'])
|
||||
->getMock();
|
||||
|
||||
$test_discovery->expects($this->any())
|
||||
->method('getExtensions')
|
||||
->willReturn($extensions);
|
||||
|
||||
return $test_discovery;
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getTestClasses
|
||||
*/
|
||||
public function testGetTestClasses() {
|
||||
$this->setupVfsWithTestClasses();
|
||||
$extensions = [
|
||||
'test_module' => new Extension('vfs://drupal', 'module', 'modules/test_module/test_module.info.yml'),
|
||||
];
|
||||
$test_discovery = $this->getTestDiscoveryMock('vfs://drupal', $extensions);
|
||||
|
||||
$result = $test_discovery->getTestClasses();
|
||||
$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',
|
||||
],
|
||||
],
|
||||
'example2' => [
|
||||
'Drupal\Tests\test_module\Functional\FunctionalExampleTest2' => [
|
||||
'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',
|
||||
],
|
||||
],
|
||||
], $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getTestClasses
|
||||
*/
|
||||
public function testGetTestClassesWithSelectedTypes() {
|
||||
$this->setupVfsWithTestClasses();
|
||||
$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 = $this->getTestDiscoveryMock('vfs://drupal', $extensions);
|
||||
|
||||
$result = $test_discovery->getTestClasses(NULL, ['PHPUnit-Kernel']);
|
||||
$this->assertCount(4, $result);
|
||||
$this->assertEquals([
|
||||
'example' => [],
|
||||
'example2' => [
|
||||
'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',
|
||||
],
|
||||
],
|
||||
'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',
|
||||
],
|
||||
],
|
||||
], $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('test_profile_module', ['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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,236 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\simpletest\Unit;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @requires extension curl
|
||||
* @coversDefaultClass \Drupal\simpletest\WebTestBase
|
||||
* @group simpletest
|
||||
* @group WebTestBase
|
||||
*/
|
||||
class WebTestBaseTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* Provides data for testing the assertFieldByName() helper.
|
||||
*
|
||||
* @return array
|
||||
* An array of values passed to the test method.
|
||||
*/
|
||||
public function providerAssertFieldByName() {
|
||||
$data = [];
|
||||
$data[] = ['select_2nd_selected', 'test', '1', FALSE];
|
||||
$data[] = ['select_2nd_selected', 'test', '2', TRUE];
|
||||
$data[] = ['select_none_selected', 'test', '', FALSE];
|
||||
$data[] = ['select_none_selected', 'test', '1', TRUE];
|
||||
$data[] = ['select_none_selected', 'test', NULL, TRUE];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the assertFieldByName() helper.
|
||||
*
|
||||
* @param string $filename
|
||||
* Name of file containing the output to test.
|
||||
* @param string $name
|
||||
* Name of field to assert.
|
||||
* @param string $value
|
||||
* Value of the field to assert.
|
||||
* @param bool $expected
|
||||
* The expected result of the assert.
|
||||
*
|
||||
* @see \Drupal\simpletest\WebTestBase::assertFieldByName()
|
||||
*
|
||||
* @dataProvider providerAssertFieldByName
|
||||
* @covers ::assertFieldByName
|
||||
*/
|
||||
public function testAssertFieldByName($filename, $name, $value, $expected) {
|
||||
$content = file_get_contents(__DIR__ . '/../../fixtures/' . $filename . '.html');
|
||||
|
||||
$web_test = $this->getMockBuilder('Drupal\simpletest\WebTestBase')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['getRawContent', 'assertTrue', 'pass'])
|
||||
->getMock();
|
||||
|
||||
$web_test->expects($this->any())
|
||||
->method('getRawContent')
|
||||
->will($this->returnValue($content));
|
||||
|
||||
$web_test->expects($this->once())
|
||||
->method('assertTrue')
|
||||
->with($this->identicalTo($expected),
|
||||
$this->identicalTo('message'),
|
||||
$this->identicalTo('Browser'));
|
||||
|
||||
$test_method = new \ReflectionMethod('Drupal\simpletest\WebTestBase', 'assertFieldByName');
|
||||
$test_method->setAccessible(TRUE);
|
||||
$test_method->invokeArgs($web_test, [$name, $value, 'message']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testClickLink().
|
||||
*
|
||||
* In the test method, we mock drupalGet() to return a known string:
|
||||
* 'This Text Returned By drupalGet()'. Since clickLink() can only return
|
||||
* either the value of drupalGet() or FALSE, our expected return value is the
|
||||
* same as this mocked return value when we expect a link to be found.
|
||||
*
|
||||
* @see https://www.drupal.org/node/1452896
|
||||
*
|
||||
* @return array
|
||||
* Array of arrays of test data. Test data is structured as follows:
|
||||
* - Expected return value of clickLink().
|
||||
* - Parameter $label to clickLink().
|
||||
* - Parameter $index to clickLink().
|
||||
* - Test data to be returned by mocked xpath(). Return an empty array here
|
||||
* to mock no link found on the page.
|
||||
*/
|
||||
public function providerTestClickLink() {
|
||||
return [
|
||||
// Test for a non-existent label.
|
||||
[
|
||||
FALSE,
|
||||
'does_not_exist',
|
||||
0,
|
||||
[],
|
||||
],
|
||||
// Test for an existing label.
|
||||
[
|
||||
'This Text Returned By drupalGet()',
|
||||
'exists',
|
||||
0,
|
||||
[0 => ['href' => 'this_is_a_url']],
|
||||
],
|
||||
// Test for an existing label that isn't the first one.
|
||||
[
|
||||
'This Text Returned By drupalGet()',
|
||||
'exists',
|
||||
1,
|
||||
[
|
||||
0 => ['href' => 'this_is_a_url'],
|
||||
1 => ['href' => 'this_is_another_url'],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test WebTestBase::clickLink().
|
||||
*
|
||||
* @param mixed $expected
|
||||
* Expected return value of clickLink().
|
||||
* @param string $label
|
||||
* Parameter $label to clickLink().
|
||||
* @param int $index
|
||||
* Parameter $index to clickLink().
|
||||
* @param array $xpath_data
|
||||
* Test data to be returned by mocked xpath().
|
||||
*
|
||||
* @dataProvider providerTestClickLink
|
||||
* @covers ::clickLink
|
||||
*/
|
||||
public function testClickLink($expected, $label, $index, $xpath_data) {
|
||||
// Mock a WebTestBase object and some of its methods.
|
||||
$web_test = $this->getMockBuilder('Drupal\simpletest\WebTestBase')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods([
|
||||
'pass',
|
||||
'fail',
|
||||
'getUrl',
|
||||
'xpath',
|
||||
'drupalGet',
|
||||
'getAbsoluteUrl',
|
||||
])
|
||||
->getMock();
|
||||
|
||||
// Mocked getUrl() is only used for reporting so we just return a string.
|
||||
$web_test->expects($this->any())
|
||||
->method('getUrl')
|
||||
->will($this->returnValue('url_before'));
|
||||
|
||||
// Mocked xpath() should return our test data.
|
||||
$web_test->expects($this->any())
|
||||
->method('xpath')
|
||||
->will($this->returnValue($xpath_data));
|
||||
|
||||
if ($expected === FALSE) {
|
||||
// If link does not exist clickLink() will not try to do a drupalGet() or
|
||||
// a getAbsoluteUrl()
|
||||
$web_test->expects($this->never())
|
||||
->method('drupalGet');
|
||||
$web_test->expects($this->never())
|
||||
->method('getAbsoluteUrl');
|
||||
// The test should fail and not pass.
|
||||
$web_test->expects($this->never())
|
||||
->method('pass');
|
||||
$web_test->expects($this->once())
|
||||
->method('fail')
|
||||
->will($this->returnValue(NULL));
|
||||
}
|
||||
else {
|
||||
// Mocked getAbsoluteUrl() should return whatever comes in.
|
||||
$web_test->expects($this->once())
|
||||
->method('getAbsoluteUrl')
|
||||
->with($xpath_data[$index]['href'])
|
||||
->will($this->returnArgument(0));
|
||||
// We're only testing clickLink(), so drupalGet() always returns a string.
|
||||
$web_test->expects($this->once())
|
||||
->method('drupalGet')
|
||||
->with($xpath_data[$index]['href'])
|
||||
->will($this->returnValue('This Text Returned By drupalGet()'));
|
||||
// The test should pass and not fail.
|
||||
$web_test->expects($this->never())
|
||||
->method('fail');
|
||||
$web_test->expects($this->once())
|
||||
->method('pass')
|
||||
->will($this->returnValue(NULL));
|
||||
}
|
||||
|
||||
// Set the clickLink() method to public so we can test it.
|
||||
$clicklink_method = new \ReflectionMethod($web_test, 'clickLink');
|
||||
$clicklink_method->setAccessible(TRUE);
|
||||
|
||||
$this->assertSame($expected, $clicklink_method->invoke($web_test, $label, $index));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerTestGetAbsoluteUrl
|
||||
*/
|
||||
public function testGetAbsoluteUrl($href, $expected_absolute_path) {
|
||||
$web_test = $this->getMockBuilder('Drupal\simpletest\WebTestBase')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['getUrl'])
|
||||
->getMock();
|
||||
|
||||
$web_test->expects($this->any())
|
||||
->method('getUrl')
|
||||
->willReturn('http://example.com/drupal/current-path?foo=baz');
|
||||
|
||||
$GLOBALS['base_url'] = 'http://example.com';
|
||||
$GLOBALS['base_path'] = 'drupal';
|
||||
|
||||
$get_absolute_url_method = new \ReflectionMethod($web_test, 'getAbsoluteUrl');
|
||||
$get_absolute_url_method->setAccessible(TRUE);
|
||||
|
||||
$this->assertSame($expected_absolute_path, $get_absolute_url_method->invoke($web_test, $href));
|
||||
unset($GLOBALS['base_url'], $GLOBALS['base_path']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides test data for testGetAbsoluteUrl.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function providerTestGetAbsoluteUrl() {
|
||||
$data = [];
|
||||
$data['host'] = ['http://example.com/drupal/test-example', 'http://example.com/drupal/test-example'];
|
||||
$data['path'] = ['/drupal/test-example', 'http://example.com/drupal/test-example'];
|
||||
$data['path-with-query'] = ['/drupal/test-example?foo=bar', 'http://example.com/drupal/test-example?foo=bar'];
|
||||
$data['just-query'] = ['?foo=bar', 'http://example.com/drupal/current-path?foo=bar'];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user