updated core and modules

This commit is contained in:
Bachir Soussi Chiadmi
2017-09-09 16:27:51 +02:00
parent 027aa99b32
commit 41863f872c
7810 changed files with 318922 additions and 83631 deletions
@@ -0,0 +1,24 @@
<?php
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>');
}
}
@@ -2,22 +2,27 @@
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 {
class SimpletestPhpunitRunCommandTestWillDie extends \PHPUnit_Framework_TestCase {
/**
* Performs the status specified by SimpletestPhpunitRunCommandTestWillDie.
*/
public function testWillDie() {
if (getenv('SimpletestPhpunitRunCommandTestWillDie') === 'fail') {
exit(2);
$status = (int) getenv('SimpletestPhpunitRunCommandTestWillDie');
if ($status == 0) {
$this->assertTrue(TRUE, 'Assertion to ensure test pass');
return;
}
$this->assertTrue(TRUE, 'Assertion to ensure test pass');
exit($status);
}
}
@@ -5,8 +5,8 @@ package: Testing
# version: VERSION
# core: 8.x
# Information added by Drupal.org packaging script on 2016-08-03
version: '8.1.8'
# Information added by Drupal.org packaging script on 2017-08-16
version: '8.3.7'
core: '8.x'
project: 'drupal'
datestamp: 1470233792
datestamp: 1502903957
@@ -7,8 +7,8 @@ package: Testing
dependencies:
- entity_test
# Information added by Drupal.org packaging script on 2016-08-03
version: '8.1.8'
# Information added by Drupal.org packaging script on 2017-08-16
version: '8.3.7'
core: '8.x'
project: 'drupal'
datestamp: 1470233792
datestamp: 1502903957
@@ -12,13 +12,13 @@ use Drupal\entity_test\Entity\EntityTest;
*/
function simpletest_test_install() {
$total = 2;
$operations = array();
$operations = [];
for ($i = 1; $i <= $total; $i++) {
$operations[] = array('_simpletest_test_callback', array($i));
$operations[] = ['_simpletest_test_callback', [$i]];
}
$batch = array(
$batch = [
'operations' => $operations,
);
];
batch_set($batch);
$batch =& batch_get();
$batch['progressive'] = FALSE;
@@ -29,6 +29,6 @@ function simpletest_test_install() {
* Callback for batch operations.
*/
function _simpletest_test_callback($id) {
$entity = EntityTest::create(array('id' => $id));
$entity = EntityTest::create(['id' => $id]);
$entity->save();
}
@@ -0,0 +1,27 @@
<?php
namespace Drupal\Tests\simpletest\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* This test will check SimpleTest's treatment of hook_install during setUp.
* Image module is used for test.
*
* @group simpletest
*/
class FolderTest extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['image'];
public function testFolderSetup() {
$directory = file_default_scheme() . '://styles';
$this->assertTrue(file_prepare_directory($directory, FALSE), 'Directory created.');
}
}
@@ -0,0 +1,82 @@
<?php
namespace Drupal\Tests\simpletest\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\Core\Test\AssertMailTrait;
/**
* Tests the SimpleTest email capturing logic, the assertMail assertion and the
* drupalGetMails function.
*
* @group simpletest
*/
class MailCaptureTest extends BrowserTestBase {
use AssertMailTrait {
getMails as drupalGetMails;
}
/**
* Test to see if the wrapper function is executed correctly.
*/
public function testMailSend() {
// Create an email.
$subject = $this->randomString(64);
$body = $this->randomString(128);
$message = [
'id' => 'drupal_mail_test',
'headers' => ['Content-type' => 'text/html'],
'subject' => $subject,
'to' => 'foobar@example.com',
'body' => $body,
];
// Before we send the email, drupalGetMails should return an empty array.
$captured_emails = $this->drupalGetMails();
$this->assertEqual(count($captured_emails), 0, 'The captured emails queue is empty.', 'Email');
// Send the email.
\Drupal::service('plugin.manager.mail')->getInstance(['module' => 'simpletest', 'key' => 'drupal_mail_test'])->mail($message);
// Ensure that there is one email in the captured emails array.
$captured_emails = $this->drupalGetMails();
$this->assertEqual(count($captured_emails), 1, 'One email was captured.', 'Email');
// Assert that the email was sent by iterating over the message properties
// and ensuring that they are captured intact.
foreach ($message as $field => $value) {
$this->assertMail($field, $value, format_string('The email was sent and the value for property @field is intact.', ['@field' => $field]), 'Email');
}
// Send additional emails so more than one email is captured.
for ($index = 0; $index < 5; $index++) {
$message = [
'id' => 'drupal_mail_test_' . $index,
'headers' => ['Content-type' => 'text/html'],
'subject' => $this->randomString(64),
'to' => $this->randomMachineName(32) . '@example.com',
'body' => $this->randomString(512),
];
\Drupal::service('plugin.manager.mail')->getInstance(['module' => 'drupal_mail_test', 'key' => $index])->mail($message);
}
// There should now be 6 emails captured.
$captured_emails = $this->drupalGetMails();
$this->assertEqual(count($captured_emails), 6, 'All emails were captured.', 'Email');
// Test different ways of getting filtered emails via drupalGetMails().
$captured_emails = $this->drupalGetMails(['id' => 'drupal_mail_test']);
$this->assertEqual(count($captured_emails), 1, 'Only one email is returned when filtering by id.', 'Email');
$captured_emails = $this->drupalGetMails(['id' => 'drupal_mail_test', 'subject' => $subject]);
$this->assertEqual(count($captured_emails), 1, 'Only one email is returned when filtering by id and subject.', 'Email');
$captured_emails = $this->drupalGetMails(['id' => 'drupal_mail_test', 'subject' => $subject, 'from' => 'this_was_not_used@example.com']);
$this->assertEqual(count($captured_emails), 0, 'No emails are returned when querying with an unused from address.', 'Email');
// Send the last email again, so we can confirm that the
// drupalGetMails-filter correctly returns all emails with a given
// property/value.
\Drupal::service('plugin.manager.mail')->getInstance(['module' => 'drupal_mail_test', 'key' => $index])->mail($message);
$captured_emails = $this->drupalGetMails(['id' => 'drupal_mail_test_4']);
$this->assertEqual(count($captured_emails), 2, 'All emails with the same id are returned when filtering by id.', 'Email');
}
}
@@ -0,0 +1,22 @@
<?php
namespace Drupal\Tests\simpletest\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* This test should not load since it requires a module that is not found.
*
* @group simpletest
* @dependencies simpletest_missing_module
*/
class MissingDependentModuleUnitTest extends BrowserTestBase {
/**
* Ensure that this test will not be loaded despite its dependency.
*/
public function testFail() {
$this->fail('Running test with missing required module.');
}
}
@@ -0,0 +1,64 @@
<?php
namespace Drupal\Tests\simpletest\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* Verifies that tests in other installation profiles are found.
*
* @group simpletest
* @see SimpleTestInstallationProfileModuleTestsTestCase
*/
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.
*
* @see \Drupal\simpletest\Tests\InstallationProfileModuleTestsTest
* @see \Drupal\drupal_system_listing_compatible_test\Tests\SystemListingCompatibleTest
*/
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.
*/
public function testOtherInstallationProfile() {
// Assert the existence of a test in a different installation profile than
// the current.
$this->drupalGet('admin/config/development/testing');
$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\drupal_system_listing_compatible_test\Tests\SystemListingCompatibleTest');
}
}
@@ -0,0 +1,23 @@
<?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
*/
class ThroughUITest extends BrowserTestBase {
/**
* This test method must always pass.
*/
public function testThroughUi() {
$this->pass('Success!');
}
}
@@ -0,0 +1,52 @@
<?php
namespace Drupal\Tests\simpletest\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* Tests User related helper methods of WebTestBase.
*
* @group simpletest
*/
class UserHelpersTest extends BrowserTestBase {
/**
* Tests WebTestBase::drupalUserIsLoggedIn().
*/
public function testDrupalUserIsLoggedIn() {
$first_user = $this->drupalCreateUser();
$second_user = $this->drupalCreateUser();
// After logging in, the first user should be logged in, the second not.
$this->drupalLogin($first_user);
$this->assertTrue($this->drupalUserIsLoggedIn($first_user));
$this->assertFalse($this->drupalUserIsLoggedIn($second_user));
// Verify that logged in state is retained across pages.
$this->drupalGet('');
$this->assertTrue($this->drupalUserIsLoggedIn($first_user));
$this->assertFalse($this->drupalUserIsLoggedIn($second_user));
// After logging out, both users should be logged out.
$this->drupalLogout();
$this->assertFalse($this->drupalUserIsLoggedIn($first_user));
$this->assertFalse($this->drupalUserIsLoggedIn($second_user));
// After logging back in, the second user should still be logged out.
$this->drupalLogin($first_user);
$this->assertTrue($this->drupalUserIsLoggedIn($first_user));
$this->assertFalse($this->drupalUserIsLoggedIn($second_user));
// After logging in the second user, the first one should be logged out.
$this->drupalLogin($second_user);
$this->assertTrue($this->drupalUserIsLoggedIn($second_user));
$this->assertFalse($this->drupalUserIsLoggedIn($first_user));
// After logging out, both should be logged out.
$this->drupalLogout();
$this->assertFalse($this->drupalUserIsLoggedIn($first_user));
$this->assertFalse($this->drupalUserIsLoggedIn($second_user));
}
}
@@ -0,0 +1,46 @@
<?php
namespace Drupal\Tests\simpletest\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
/**
* Tests Drupal settings retrieval in JavascriptTestBase tests.
*
* @group javascript
*/
class JavascriptGetDrupalSettingsTest extends JavascriptTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['test_page_test'];
/**
* Tests retrieval of Drupal settings.
*
* @see \Drupal\FunctionalJavascriptTests\JavascriptTestBase::getDrupalSettings()
*/
public function testGetDrupalSettings() {
$this->drupalLogin($this->drupalCreateUser());
$this->drupalGet('test-page');
// Check that we can read the JS settings.
$js_settings = $this->getDrupalSettings();
$this->assertSame('azAZ09();.,\\\/-_{}', $js_settings['test-setting']);
// Dynamically change the setting using Javascript.
$script = <<<EndOfScript
(function () {
drupalSettings['test-setting'] = 'foo';
})();
EndOfScript;
$this->getSession()->evaluateScript($script);
// Check that the setting has been changed.
$js_settings = $this->getDrupalSettings();
$this->assertSame('foo', $js_settings['test-setting']);
}
}
@@ -2,7 +2,7 @@
namespace Drupal\Tests\simpletest\Kernel\Migrate\d6;
use Drupal\config\Tests\SchemaCheckTestTrait;
use Drupal\Tests\SchemaCheckTestTrait;
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
/**
@@ -17,7 +17,7 @@ class MigrateSimpletestConfigsTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
public static $modules = array('simpletest');
public static $modules = ['simpletest'];
/**
* {@inheritdoc}
@@ -0,0 +1,32 @@
<?php
namespace Drupal\Tests\simpletest\Traits;
/**
* A nothing trait, but declared in the Drupal\Tests namespace.
*
* We use this trait to test autoloading of traits outside of the normal test
* suite namespaces.
*
* @see \Drupal\Tests\simpletest\Unit\TraitAccessTest
*/
trait TestTrait {
/**
* Random string for a not very interesting trait.
*
* @var string
*/
protected $stuff = 'stuff';
/**
* Return a test string to a trait user.
*
* @return string
* Just a random sort of string.
*/
protected function getStuff() {
return $this->stuff;
}
}
@@ -3,7 +3,7 @@
namespace Drupal\Tests\simpletest\Unit;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Tests\UnitTestCase;
use Drupal\Core\File\FileSystemInterface;
/**
* Tests simpletest_run_phpunit_tests() handles PHPunit fatals correctly.
@@ -11,27 +11,92 @@ use Drupal\Tests\UnitTestCase;
* @group simpletest
*
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
*/
class SimpletestPhpunitRunCommandTest extends UnitTestCase {
class SimpletestPhpunitRunCommandTest extends \PHPUnit_Framework_TestCase {
function testSimpletestPhpUnitRunCommand() {
include_once __DIR__ . '/../../fixtures/simpletest_phpunit_run_command_test.php';
$app_root = __DIR__ . '/../../../../../..';
include_once "$app_root/core/modules/simpletest/simpletest.module";
/**
* Path to the app root.
*
* @var string
*/
protected static $root;
/**
* {@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', $app_root);
$file_system = $this->prophesize('Drupal\Core\File\FileSystemInterface');
$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);
$test_id = basename(tempnam(sys_get_temp_dir(), 'xxx'));
foreach (['pass', 'fail'] as $status) {
putenv('SimpletestPhpunitRunCommandTestWillDie=' . $status);
$ret = simpletest_run_phpunit_tests($test_id, ['Drupal\Tests\simpletest\Unit\SimpletestPhpunitRunCommandTestWillDie']);
$this->assertSame($ret[0]['status'], $status);
}
/**
* 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.
*
* @covers ::simpletest_run_phpunit_tests
*
* @dataProvider provideStatusCodes
*/
public function testSimpletestPhpUnitRunCommand($status, $label) {
$test_id = basename(tempnam(sys_get_temp_dir(), 'xxx'));
putenv('SimpletestPhpunitRunCommandTestWillDie=' . $status);
$ret = simpletest_run_phpunit_tests($test_id, [SimpletestPhpunitRunCommandTestWillDie::class]);
$this->assertSame($ret[0]['status'], $label);
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();
}
}
@@ -25,13 +25,13 @@ class TestBaseTest extends UnitTestCase {
*/
public function getTestBaseForAssertionTests($test_id) {
$mock_test_base = $this->getMockBuilder('Drupal\simpletest\TestBase')
->setConstructorArgs(array($test_id))
->setMethods(array('storeAssertion'))
->getMockForAbstractClass();
->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));
->method('storeAssertion')
->will($this->returnValue(NULL));
return $mock_test_base;
}
@@ -62,16 +62,16 @@ class TestBaseTest extends UnitTestCase {
* - The string to validate.
*/
public function providerRandomStringValidate() {
return array(
array(FALSE, ' curry paste'),
array(FALSE, 'curry paste '),
array(FALSE, 'curry paste'),
array(FALSE, 'curry paste'),
array(TRUE, 'curry paste'),
array(TRUE, 'thai green curry paste'),
array(TRUE, '@startswithat'),
array(TRUE, 'contains@at'),
);
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'],
];
}
/**
@@ -136,7 +136,7 @@ class TestBaseTest extends UnitTestCase {
$test_base = $this->getTestBaseForAssertionTests('test_id');
$this->assertInternalType(
'array',
$this->invokeProtectedMethod($test_base, 'checkRequirements', array())
$this->invokeProtectedMethod($test_base, 'checkRequirements', [])
);
}
@@ -153,14 +153,14 @@ class TestBaseTest extends UnitTestCase {
* - Caller, passed to assert().
*/
public function providerAssert() {
return array(
array(TRUE, 'pass', TRUE, 'Yay pass', 'test', array()),
array(FALSE, 'fail', FALSE, 'Boo fail', 'test', array()),
array(TRUE, 'pass', 'pass', 'Yay pass', 'test', array()),
array(FALSE, 'fail', 'fail', 'Boo fail', 'test', array()),
array(FALSE, 'exception', 'exception', 'Boo fail', 'test', array()),
array(FALSE, 'debug', 'debug', 'Boo fail', 'test', array()),
);
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', []],
];
}
/**
@@ -185,7 +185,7 @@ class TestBaseTest extends UnitTestCase {
$this->assertEquals(
$expected,
$ref_assert->invokeArgs($test_base,
array($status, $message, $group, $caller)
[$status, $message, $group, $caller]
)
);
@@ -211,10 +211,10 @@ class TestBaseTest extends UnitTestCase {
* Data provider for assertTrue().
*/
public function providerAssertTrue() {
return array(
array(TRUE, TRUE),
array(FALSE, FALSE),
);
return [
[TRUE, TRUE],
[FALSE, FALSE],
];
}
/**
@@ -225,7 +225,7 @@ class TestBaseTest extends UnitTestCase {
$test_base = $this->getTestBaseForAssertionTests('test_id');
$this->assertEquals(
$expected,
$this->invokeProtectedMethod($test_base, 'assertTrue', array($value))
$this->invokeProtectedMethod($test_base, 'assertTrue', [$value])
);
}
@@ -237,7 +237,7 @@ class TestBaseTest extends UnitTestCase {
$test_base = $this->getTestBaseForAssertionTests('test_id');
$this->assertEquals(
(!$expected),
$this->invokeProtectedMethod($test_base, 'assertFalse', array($value))
$this->invokeProtectedMethod($test_base, 'assertFalse', [$value])
);
}
@@ -245,10 +245,10 @@ class TestBaseTest extends UnitTestCase {
* Data provider for assertNull().
*/
public function providerAssertNull() {
return array(
array(TRUE, NULL),
array(FALSE, ''),
);
return [
[TRUE, NULL],
[FALSE, ''],
];
}
/**
@@ -259,7 +259,7 @@ class TestBaseTest extends UnitTestCase {
$test_base = $this->getTestBaseForAssertionTests('test_id');
$this->assertEquals(
$expected,
$this->invokeProtectedMethod($test_base, 'assertNull', array($value))
$this->invokeProtectedMethod($test_base, 'assertNull', [$value])
);
}
@@ -271,7 +271,7 @@ class TestBaseTest extends UnitTestCase {
$test_base = $this->getTestBaseForAssertionTests('test_id');
$this->assertEquals(
(!$expected),
$this->invokeProtectedMethod($test_base, 'assertNotNull', array($value))
$this->invokeProtectedMethod($test_base, 'assertNotNull', [$value])
);
}
@@ -325,7 +325,7 @@ class TestBaseTest extends UnitTestCase {
$test_base = $this->getTestBaseForAssertionTests('test_id');
$this->assertEquals(
$expected_identical,
$this->invokeProtectedMethod($test_base, 'assertIdentical', array($first, $second))
$this->invokeProtectedMethod($test_base, 'assertIdentical', [$first, $second])
);
}
@@ -337,7 +337,7 @@ class TestBaseTest extends UnitTestCase {
$test_base = $this->getTestBaseForAssertionTests('test_id');
$this->assertEquals(
(!$expected_identical),
$this->invokeProtectedMethod($test_base, 'assertNotIdentical', array($first, $second))
$this->invokeProtectedMethod($test_base, 'assertNotIdentical', [$first, $second])
);
}
@@ -349,7 +349,7 @@ class TestBaseTest extends UnitTestCase {
$test_base = $this->getTestBaseForAssertionTests('test_id');
$this->assertEquals(
$expected_equal,
$this->invokeProtectedMethod($test_base, 'assertEqual', array($first, $second))
$this->invokeProtectedMethod($test_base, 'assertEqual', [$first, $second])
);
}
@@ -361,7 +361,7 @@ class TestBaseTest extends UnitTestCase {
$test_base = $this->getTestBaseForAssertionTests('test_id');
$this->assertEquals(
(!$expected_equal),
$this->invokeProtectedMethod($test_base, 'assertNotEqual', array($first, $second))
$this->invokeProtectedMethod($test_base, 'assertNotEqual', [$first, $second])
);
}
@@ -374,11 +374,11 @@ class TestBaseTest extends UnitTestCase {
$obj2 = $obj1;
$obj3 = clone $obj1;
$obj4 = new \stdClass();
return array(
array(TRUE, $obj1, $obj2),
array(TRUE, $obj1, $obj3),
array(FALSE, $obj1, $obj4),
);
return [
[TRUE, $obj1, $obj2],
[TRUE, $obj1, $obj3],
[FALSE, $obj1, $obj4],
];
}
/**
@@ -389,7 +389,7 @@ class TestBaseTest extends UnitTestCase {
$test_base = $this->getTestBaseForAssertionTests('test_id');
$this->assertEquals(
$expected,
$this->invokeProtectedMethod($test_base, 'assertIdenticalObject', array($first, $second))
$this->invokeProtectedMethod($test_base, 'assertIdenticalObject', [$first, $second])
);
}
@@ -400,7 +400,7 @@ class TestBaseTest extends UnitTestCase {
$test_base = $this->getTestBaseForAssertionTests('test_id');
$this->assertEquals(
TRUE,
$this->invokeProtectedMethod($test_base, 'pass', array())
$this->invokeProtectedMethod($test_base, 'pass', [])
);
}
@@ -411,7 +411,7 @@ class TestBaseTest extends UnitTestCase {
$test_base = $this->getTestBaseForAssertionTests('test_id');
$this->assertEquals(
FALSE,
$this->invokeProtectedMethod($test_base, 'fail', array())
$this->invokeProtectedMethod($test_base, 'fail', [])
);
}
@@ -423,10 +423,10 @@ class TestBaseTest extends UnitTestCase {
* - Group for use in assert().
*/
public function providerError() {
return array(
array('debug', 'User notice'),
array('exception', 'Not User notice'),
);
return [
['debug', 'User notice'],
['exception', 'Not User notice'],
];
}
/**
@@ -436,7 +436,7 @@ class TestBaseTest extends UnitTestCase {
public function testError($status, $group) {
// Mock up a TestBase object.
$mock_test_base = $this->getMockBuilder('Drupal\simpletest\TestBase')
->setMethods(array('assert'))
->setMethods(['assert'])
->getMockForAbstractClass();
// Set expectations for assert().
@@ -451,7 +451,7 @@ class TestBaseTest extends UnitTestCase {
// Invoke error().
$this->assertEquals(
"$status:$group",
$this->invokeProtectedMethod($mock_test_base, 'error', array('msg', $group))
$this->invokeProtectedMethod($mock_test_base, 'error', ['msg', $group])
);
}
@@ -462,7 +462,7 @@ class TestBaseTest extends UnitTestCase {
$test_base = $this->getTestBaseForAssertionTests('test_id');
$this->assertInstanceOf(
'Drupal\Component\Utility\Random',
$this->invokeProtectedMethod($test_base, 'getRandomGenerator', array())
$this->invokeProtectedMethod($test_base, 'getRandomGenerator', [])
);
}
@@ -0,0 +1,421 @@
<?php
namespace Drupal\Tests\simpletest\Unit;
use Composer\Autoload\ClassLoader;
use Drupal\Core\Extension\Extension;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\simpletest\Exception\MissingGroupException;
use Drupal\simpletest\TestDiscovery;
use Drupal\Tests\UnitTestCase;
use org\bovigo\vfs\vfsStream;
/**
* @coversDefaultClass \Drupal\simpletest\TestDiscovery
* @group simpletest
*/
class TestDiscoveryTest extends UnitTestCase {
/**
* @covers ::getTestInfo
* @dataProvider infoParserProvider
*/
public function testTestInfoParser($expected, $classname, $doc_comment = NULL) {
$info = TestDiscovery::getTestInfo($classname, $doc_comment);
$this->assertEquals($expected, $info);
}
public function infoParserProvider() {
// A module provided unit test.
$tests[] = [
// Expected result.
[
'name' => 'Drupal\Tests\simpletest\Unit\TestDiscoveryTest',
'group' => 'simpletest',
'description' => 'Tests \Drupal\simpletest\TestDiscovery.',
'type' => 'PHPUnit-Unit',
],
// Classname.
'Drupal\Tests\simpletest\Unit\TestDiscoveryTest',
];
// A core unit test.
$tests[] = [
// Expected result.
[
'name' => 'Drupal\Tests\Core\DrupalTest',
'group' => 'DrupalTest',
'description' => 'Tests \Drupal.',
'type' => 'PHPUnit-Unit',
],
// Classname.
'Drupal\Tests\Core\DrupalTest',
];
// Functional PHPUnit test.
$tests[] = [
// Expected result.
[
'name' => 'Drupal\FunctionalTests\BrowserTestBaseTest',
'group' => 'browsertestbase',
'description' => 'Tests BrowserTestBase functionality.',
'type' => 'PHPUnit-Functional',
],
// Classname.
'Drupal\FunctionalTests\BrowserTestBaseTest',
];
// kernel PHPUnit test.
$tests['phpunit-kernel'] = [
// Expected result.
[
'name' => '\Drupal\Tests\file\Kernel\FileItemValidationTest',
'group' => 'file',
'description' => 'Tests that files referenced in file and image fields are always validated.',
'type' => 'PHPUnit-Kernel',
],
// Classname.
'\Drupal\Tests\file\Kernel\FileItemValidationTest',
];
// Simpletest classes can not be autoloaded in a PHPUnit test, therefore
// provide a docblock.
$tests[] = [
// Expected result.
[
'name' => 'Drupal\simpletest\Tests\ExampleSimpleTest',
'group' => 'simpletest',
'description' => 'Tests the Simpletest UI internal browser.',
'type' => 'Simpletest',
],
// Classname.
'Drupal\simpletest\Tests\ExampleSimpleTest',
// Doc block.
"/**
* Tests the Simpletest UI internal browser.
*
* @group simpletest
*/
",
];
// Test with a different amount of leading spaces.
$tests[] = [
// Expected result.
[
'name' => 'Drupal\simpletest\Tests\ExampleSimpleTest',
'group' => 'simpletest',
'description' => 'Tests the Simpletest UI internal browser.',
'type' => 'Simpletest',
],
// Classname.
'Drupal\simpletest\Tests\ExampleSimpleTest',
// Doc block.
"/**
* Tests the Simpletest UI internal browser.
*
* @group simpletest
*/
*/
",
];
// Make sure that a "* @" inside a string does not get parsed as an
// annotation.
$tests[] = [
// Expected result.
[
'name' => 'Drupal\simpletest\Tests\ExampleSimpleTest',
'group' => 'simpletest',
'description' => 'Tests the Simpletest UI internal browser. * @',
'type' => 'Simpletest',
],
// Classname.
'Drupal\simpletest\Tests\ExampleSimpleTest',
// Doc block.
"/**
* Tests the Simpletest UI internal browser. * @
*
* @group simpletest
*/
",
];
// Multiple @group annotations.
$tests[] = [
// Expected result.
[
'name' => 'Drupal\simpletest\Tests\ExampleSimpleTest',
'group' => 'Test',
'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
*/
",
];
// @dependencies annotation.
$tests[] = [
// Expected result.
[
'name' => 'Drupal\simpletest\Tests\ExampleSimpleTest',
'description' => 'Tests the Simpletest UI internal browser.',
'type' => 'Simpletest',
'requires' => ['module' => ['test']],
'group' => 'simpletest',
],
// Classname.
'Drupal\simpletest\Tests\ExampleSimpleTest',
// Doc block.
"/**
* Tests the Simpletest UI internal browser.
*
* @dependencies test
* @group simpletest
*/
",
];
// Multiple @dependencies annotation.
$tests[] = [
// Expected result.
[
'name' => 'Drupal\simpletest\Tests\ExampleSimpleTest',
'description' => 'Tests the Simpletest UI internal browser.',
'type' => 'Simpletest',
'requires' => ['module' => ['test', 'test1', 'test2']],
'group' => 'simpletest',
],
// Classname.
'Drupal\simpletest\Tests\ExampleSimpleTest',
// Doc block.
"/**
* Tests the Simpletest UI internal browser.
*
* @dependencies test, test1, test2
* @group simpletest
*/
",
];
// Multi-line summary line.
$tests[] = [
// Expected result.
[
'name' => 'Drupal\simpletest\Tests\ExampleSimpleTest',
'description' => 'Tests the Simpletest UI internal browser. And the summary line continues an there is no gap to the annotation.',
'type' => 'Simpletest',
'group' => 'simpletest',
],
// Classname.
'Drupal\simpletest\Tests\ExampleSimpleTest',
// Doc block.
"/**
* Tests the Simpletest UI internal browser. And the summary line continues an
* there is no gap to the annotation.
*
* @group simpletest
*/
",
];
return $tests;
}
/**
* @covers ::getTestInfo
*/
public function testTestInfoParserMissingGroup() {
$classname = 'Drupal\KernelTests\field\BulkDeleteTest';
$doc_comment = <<<EOT
/**
* Bulk delete storages and fields, and clean up afterwards.
*/
EOT;
$this->setExpectedException(MissingGroupException::class, 'Missing @group annotation in Drupal\KernelTests\field\BulkDeleteTest');
TestDiscovery::getTestInfo($classname, $doc_comment);
}
/**
* @covers ::getTestInfo
*/
public function testTestInfoParserMissingSummary() {
$classname = 'Drupal\KernelTests\field\BulkDeleteTest';
$doc_comment = <<<EOT
/**
* @group field
*/
EOT;
$info = TestDiscovery::getTestInfo($classname, $doc_comment);
$this->assertEmpty($info['description']);
}
protected function setupVfsWithTestClasses() {
vfsStream::setup('drupal');
$test_file = <<<EOF
<?php
/**
* Test description
* @group example
*/
class FunctionalExampleTest {}
EOF;
vfsStream::create([
'modules' => [
'test_module' => [
'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'], $test_file),
],
],
],
],
],
]);
}
/**
* @covers ::getTestClasses
*/
public function testGetTestClasses() {
$this->setupVfsWithTestClasses();
$class_loader = $this->prophesize(ClassLoader::class);
$module_handler = $this->prophesize(ModuleHandlerInterface::class);
$test_discovery = new TestTestDiscovery('vfs://drupal', $class_loader->reveal(), $module_handler->reveal());
$extensions = [
'test_module' => new Extension('vfs://drupal', 'module', 'modules/test_module/test_module.info.yml'),
];
$test_discovery->setExtensions($extensions);
$result = $test_discovery->getTestClasses();
$this->assertCount(2, $result);
$this->assertEquals([
'example' => [
'Drupal\Tests\test_module\Functional\FunctionalExampleTest' => [
'name' => 'Drupal\Tests\test_module\Functional\FunctionalExampleTest',
'description' => 'Test description',
'group' => 'example',
'type' => 'PHPUnit-Functional',
],
],
'example2' => [
'Drupal\Tests\test_module\Functional\FunctionalExampleTest2' => [
'name' => 'Drupal\Tests\test_module\Functional\FunctionalExampleTest2',
'description' => 'Test description',
'group' => 'example2',
'type' => 'PHPUnit-Functional',
],
'Drupal\Tests\test_module\Kernel\KernelExampleTest3' => [
'name' => 'Drupal\Tests\test_module\Kernel\KernelExampleTest3',
'description' => 'Test description',
'group' => 'example2',
'type' => 'PHPUnit-Kernel',
],
],
], $result);
}
/**
* @covers ::getTestClasses
*/
public function testGetTestClassesWithSelectedTypes() {
$this->setupVfsWithTestClasses();
$class_loader = $this->prophesize(ClassLoader::class);
$module_handler = $this->prophesize(ModuleHandlerInterface::class);
$test_discovery = new TestTestDiscovery('vfs://drupal', $class_loader->reveal(), $module_handler->reveal());
$extensions = [
'test_module' => new Extension('vfs://drupal', 'module', 'modules/test_module/test_module.info.yml'),
];
$test_discovery->setExtensions($extensions);
$result = $test_discovery->getTestClasses(NULL, ['PHPUnit-Kernel']);
$this->assertCount(2, $result);
$this->assertEquals([
'example' => [
],
'example2' => [
'Drupal\Tests\test_module\Kernel\KernelExampleTest3' => [
'name' => 'Drupal\Tests\test_module\Kernel\KernelExampleTest3',
'description' => 'Test description',
'group' => 'example2',
'type' => 'PHPUnit-Kernel',
],
],
], $result);
}
/**
* @covers ::getPhpunitTestSuite
* @dataProvider providerTestGetPhpunitTestSuite
*/
public function testGetPhpunitTestSuite($classname, $expected) {
$this->assertEquals($expected, TestDiscovery::getPhpunitTestSuite($classname));
}
public function providerTestGetPhpunitTestSuite() {
$data = [];
$data['simpletest-webtest'] = ['\Drupal\rest\Tests\NodeTest', FALSE];
$data['simpletest-kerneltest'] = ['\Drupal\hal\Tests\FileNormalizeTest', FALSE];
$data['module-unittest'] = [static::class, 'Unit'];
$data['module-kerneltest'] = ['\Drupal\KernelTests\Core\Theme\TwigMarkupInterfaceTest', 'Kernel'];
$data['module-functionaltest'] = ['\Drupal\FunctionalTests\BrowserTestBaseTest', 'Functional'];
$data['module-functionaljavascripttest'] = ['\Drupal\Tests\toolbar\FunctionalJavascript\ToolbarIntegrationTest', 'FunctionalJavascript'];
$data['core-unittest'] = ['\Drupal\Tests\ComposerIntegrationTest', 'Unit'];
$data['core-unittest2'] = ['Drupal\Tests\Core\DrupalTest', 'Unit'];
$data['core-kerneltest'] = ['\Drupal\KernelTests\KernelTestBaseTest', 'Kernel'];
$data['core-functionaltest'] = ['\Drupal\FunctionalTests\ExampleTest', 'Functional'];
$data['core-functionaljavascripttest'] = ['\Drupal\FunctionalJavascriptTests\ExampleTest', 'FunctionalJavascript'];
return $data;
}
}
class TestTestDiscovery extends TestDiscovery {
/**
* @var \Drupal\Core\Extension\Extension[]
*/
protected $extensions = [];
public function setExtensions(array $extensions) {
$this->extensions = $extensions;
}
/**
* {@inheritdoc}
*/
protected function getExtensions() {
return $this->extensions;
}
}
namespace Drupal\simpletest\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Tests the Simpletest UI internal browser.
*
* @group simpletest
*/
class ExampleSimpleTest extends WebTestBase {
}
@@ -0,0 +1,25 @@
<?php
namespace Drupal\Tests\simpletest\Unit;
use Drupal\Tests\UnitTestCase;
use Drupal\Tests\simpletest\Traits\TestTrait;
/**
* Test whether traits are autoloaded during PHPUnit discovery time.
*
* @group simpletest
*/
class TraitAccessTest extends UnitTestCase {
use TestTrait;
/**
* @coversNothing
*/
public function testSimpleStuff() {
$stuff = $this->getStuff();
$this->assertSame($stuff, 'stuff', "Same old stuff");
}
}
@@ -18,12 +18,12 @@ class WebTestBaseTest extends UnitTestCase {
* An array of values passed to the test method.
*/
public function providerAssertFieldByName() {
$data = array();
$data[] = array('select_2nd_selected', 'test', '1', FALSE);
$data[] = array('select_2nd_selected', 'test', '2', TRUE);
$data[] = array('select_none_selected', 'test', '', FALSE);
$data[] = array('select_none_selected', 'test', '1', TRUE);
$data[] = array('select_none_selected', 'test', NULL, TRUE);
$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;
}
@@ -50,7 +50,7 @@ class WebTestBaseTest extends UnitTestCase {
$web_test = $this->getMockBuilder('Drupal\simpletest\WebTestBase')
->disableOriginalConstructor()
->setMethods(array('getRawContent', 'assertTrue', 'pass'))
->setMethods(['getRawContent', 'assertTrue', 'pass'])
->getMock();
$web_test->expects($this->any())
@@ -65,7 +65,7 @@ class WebTestBaseTest extends UnitTestCase {
$test_method = new \ReflectionMethod('Drupal\simpletest\WebTestBase', 'assertFieldByName');
$test_method->setAccessible(TRUE);
$test_method->invokeArgs($web_test, array($name, $value, 'message'));
$test_method->invokeArgs($web_test, [$name, $value, 'message']);
}
/**
@@ -87,32 +87,32 @@ class WebTestBaseTest extends UnitTestCase {
* to mock no link found on the page.
*/
public function providerTestClickLink() {
return array(
return [
// Test for a non-existent label.
array(
[
FALSE,
'does_not_exist',
0,
array(),
),
[],
],
// Test for an existing label.
array(
[
'This Text Returned By drupalGet()',
'exists',
0,
array(0 => array('href' => 'this_is_a_url')),
),
[0 => ['href' => 'this_is_a_url']],
],
// Test for an existing label that isn't the first one.
array(
[
'This Text Returned By drupalGet()',
'exists',
1,
array(
0 => array('href' => 'this_is_a_url'),
1 => array('href' => 'this_is_another_url'),
),
),
);
[
0 => ['href' => 'this_is_a_url'],
1 => ['href' => 'this_is_another_url'],
],
],
];
}
/**
@@ -134,14 +134,14 @@ class WebTestBaseTest extends UnitTestCase {
// Mock a WebTestBase object and some of its methods.
$web_test = $this->getMockBuilder('Drupal\simpletest\WebTestBase')
->disableOriginalConstructor()
->setMethods(array(
->setMethods([
'pass',
'fail',
'getUrl',
'xpath',
'drupalGet',
'getAbsoluteUrl',
))
])
->getMock();
// Mocked getUrl() is only used for reporting so we just return a string.