upgrades core to 8.4.2

This commit is contained in:
Bachir Soussi Chiadmi
2017-11-14 16:09:54 +01:00
parent bd60eff9b3
commit c2b4e25be4
3504 changed files with 140306 additions and 38684 deletions
@@ -0,0 +1,35 @@
<?php
namespace Drupal\Tests;
use Drupal\Component\Render\MarkupInterface;
/**
* Provides helper methods for assertions.
*/
trait AssertHelperTrait {
/**
* Casts MarkupInterface objects into strings.
*
* @param string|array $value
* The value to act on.
*
* @return mixed
* The input value, with MarkupInterface objects casted to string.
*/
protected static function castSafeStrings($value) {
if ($value instanceof MarkupInterface) {
$value = (string) $value;
}
if (is_array($value)) {
array_walk_recursive($value, function (&$item) {
if ($item instanceof MarkupInterface) {
$item = (string) $item;
}
});
}
return $value;
}
}
@@ -0,0 +1,43 @@
<?php
namespace Drupal\Tests;
use Drupal\Core\Render\Markup;
/**
* @coversDefaultClass \Drupal\Tests\AssertHelperTrait
* @group simpletest
* @group Tests
*/
class AssertHelperTraitTest extends UnitTestCase {
/**
* @covers ::castSafeStrings
* @dataProvider providerCastSafeStrings
*/
public function testCastSafeStrings($expected, $value) {
$class = new AssertHelperTestClass();
$this->assertSame($expected, $class->testMethod($value));
}
public function providerCastSafeStrings() {
$safe_string = Markup::create('test safe string');
return [
['test simple string', 'test simple string'],
[['test simple array', 'test simple array'], ['test simple array', 'test simple array']],
['test safe string', $safe_string],
[['test safe string', 'test safe string'], [$safe_string, $safe_string]],
[['test safe string', 'mixed array', 'test safe string'], [$safe_string, 'mixed array', $safe_string]],
];
}
}
class AssertHelperTestClass {
use AssertHelperTrait;
public function testMethod($value) {
return $this->castSafeStrings($value);
}
}
+71 -196
View File
@@ -14,23 +14,19 @@ use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Database\Database;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Session\AnonymousUserSession;
use Drupal\Core\Site\Settings;
use Drupal\Core\StreamWrapper\StreamWrapperInterface;
use Drupal\Core\Test\FunctionalTestSetupTrait;
use Drupal\Core\Test\TestRunnerKernel;
use Drupal\Core\Test\TestSetupTrait;
use Drupal\Core\Url;
use Drupal\Core\Utility\Error;
use Drupal\FunctionalTests\AssertLegacyTrait;
use Drupal\simpletest\AssertHelperTrait;
use Drupal\simpletest\ContentTypeCreationTrait;
use Drupal\simpletest\BlockCreationTrait;
use Drupal\simpletest\NodeCreationTrait;
use Drupal\simpletest\UserCreationTrait;
use Symfony\Component\CssSelector\CssSelectorConverter;
use Symfony\Component\HttpFoundation\Request;
use Drupal\Tests\block\Traits\BlockCreationTrait;
use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
use Drupal\Tests\node\Traits\NodeCreationTrait;
use Drupal\Tests\user\Traits\UserCreationTrait;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Symfony\Component\CssSelector\CssSelectorConverter;
/**
* Provides a test case for functional Drupal tests.
@@ -41,7 +37,7 @@ use Psr\Http\Message\ResponseInterface;
*
* @ingroup testing
*/
abstract class BrowserTestBase extends \PHPUnit_Framework_TestCase {
abstract class BrowserTestBase extends TestCase {
use FunctionalTestSetupTrait;
use TestSetupTrait;
@@ -60,6 +56,7 @@ abstract class BrowserTestBase extends \PHPUnit_Framework_TestCase {
createContentType as drupalCreateContentType;
}
use ConfigTestTrait;
use TestRequirementsTrait;
use UserCreationTrait {
createRole as drupalCreateRole;
createUser as drupalCreateUser;
@@ -260,6 +257,32 @@ abstract class BrowserTestBase extends \PHPUnit_Framework_TestCase {
*/
protected $metaRefreshCount = 0;
/**
* The app root.
*
* @var string
*/
protected $root;
/**
* The original container.
*
* Move this to \Drupal\Core\Test\FunctionalTestSetupTrait once TestBase no
* longer provides the same value.
*
* @var \Symfony\Component\DependencyInjection\ContainerInterface
*/
protected $originalContainer;
/**
* {@inheritdoc}
*/
public function __construct($name = NULL, array $data = [], $dataName = '') {
parent::__construct($name, $data, $dataName);
$this->root = dirname(dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__))));
}
/**
* Initializes Mink sessions.
*/
@@ -343,6 +366,30 @@ abstract class BrowserTestBase extends \PHPUnit_Framework_TestCase {
return $driver;
}
/**
* Creates the directory to store browser output.
*
* Creates the directory to store browser output in if a file to write
* URLs to has been created by \Drupal\Tests\Listeners\HtmlOutputPrinter.
*/
protected function initBrowserOutputFile() {
$browser_output_file = getenv('BROWSERTEST_OUTPUT_FILE');
$this->htmlOutputEnabled = is_file($browser_output_file);
if ($this->htmlOutputEnabled) {
$this->htmlOutputFile = $browser_output_file;
$this->htmlOutputClassName = str_replace("\\", "_", get_called_class());
$this->htmlOutputDirectory = DRUPAL_ROOT . '/sites/simpletest/browser_output';
if (file_prepare_directory($this->htmlOutputDirectory, FILE_CREATE_DIRECTORY) && !file_exists($this->htmlOutputDirectory . '/.htaccess')) {
file_put_contents($this->htmlOutputDirectory . '/.htaccess', "<IfModule mod_expires.c>\nExpiresActive Off\n</IfModule>\n");
}
$this->htmlOutputCounterStorage = $this->htmlOutputDirectory . '/' . $this->htmlOutputClassName . '.counter';
$this->htmlOutputTestId = str_replace('sites/simpletest/', '', $this->siteDirectory);
if (is_file($this->htmlOutputCounterStorage)) {
$this->htmlOutputCounter = max(1, (int) file_get_contents($this->htmlOutputCounterStorage)) + 1;
}
}
}
/**
* Provides a Guzzle middleware handler to log every response received.
*
@@ -399,43 +446,9 @@ abstract class BrowserTestBase extends \PHPUnit_Framework_TestCase {
* {@inheritdoc}
*/
protected function setUp() {
global $base_url;
parent::setUp();
// Get and set the domain of the environment we are running our test
// coverage against.
$base_url = getenv('SIMPLETEST_BASE_URL');
if (!$base_url) {
throw new \Exception(
'You must provide a SIMPLETEST_BASE_URL environment variable to run some PHPUnit based functional tests.'
);
}
// Setup $_SERVER variable.
$parsed_url = parse_url($base_url);
$host = $parsed_url['host'] . (isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '');
$path = isset($parsed_url['path']) ? rtrim(rtrim($parsed_url['path']), '/') : '';
$port = isset($parsed_url['port']) ? $parsed_url['port'] : 80;
$this->baseUrl = $base_url;
// If the passed URL schema is 'https' then setup the $_SERVER variables
// properly so that testing will run under HTTPS.
if ($parsed_url['scheme'] === 'https') {
$_SERVER['HTTPS'] = 'on';
}
$_SERVER['HTTP_HOST'] = $host;
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['SERVER_ADDR'] = '127.0.0.1';
$_SERVER['SERVER_PORT'] = $port;
$_SERVER['SERVER_SOFTWARE'] = NULL;
$_SERVER['SERVER_NAME'] = 'localhost';
$_SERVER['REQUEST_URI'] = $path . '/';
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['SCRIPT_NAME'] = $path . '/index.php';
$_SERVER['SCRIPT_FILENAME'] = $path . '/index.php';
$_SERVER['PHP_SELF'] = $path . '/index.php';
$_SERVER['HTTP_USER_AGENT'] = 'Drupal command line';
$this->setupBaseUrl();
// Install Drupal test site.
$this->prepareEnvironment();
@@ -451,23 +464,8 @@ abstract class BrowserTestBase extends \PHPUnit_Framework_TestCase {
}
}
// Creates the directory to store browser output in if a file to write
// URLs to has been created by \Drupal\Tests\Listeners\HtmlOutputPrinter.
$browser_output_file = getenv('BROWSERTEST_OUTPUT_FILE');
$this->htmlOutputEnabled = is_file($browser_output_file);
if ($this->htmlOutputEnabled) {
$this->htmlOutputFile = $browser_output_file;
$this->htmlOutputClassName = str_replace("\\", "_", get_called_class());
$this->htmlOutputDirectory = DRUPAL_ROOT . '/sites/simpletest/browser_output';
if (file_prepare_directory($this->htmlOutputDirectory, FILE_CREATE_DIRECTORY) && !file_exists($this->htmlOutputDirectory . '/.htaccess')) {
file_put_contents($this->htmlOutputDirectory . '/.htaccess', "<IfModule mod_expires.c>\nExpiresActive Off\n</IfModule>\n");
}
$this->htmlOutputCounterStorage = $this->htmlOutputDirectory . '/' . $this->htmlOutputClassName . '.counter';
$this->htmlOutputTestId = str_replace('sites/simpletest/', '', $this->siteDirectory);
if (is_file($this->htmlOutputCounterStorage)) {
$this->htmlOutputCounter = max(1, (int) file_get_contents($this->htmlOutputCounterStorage)) + 1;
}
}
// Set up the browser test output file.
$this->initBrowserOutputFile();
}
/**
@@ -735,7 +733,6 @@ abstract class BrowserTestBase extends \PHPUnit_Framework_TestCase {
}
$this->drupalGet('user/login');
$this->assertSession()->statusCodeEquals(200);
$this->submitForm([
'name' => $account->getUsername(),
'pass' => $account->passRaw,
@@ -760,7 +757,6 @@ abstract class BrowserTestBase extends \PHPUnit_Framework_TestCase {
// screen.
$assert_session = $this->assertSession();
$this->drupalGet('user/logout', ['query' => ['destination' => 'user']]);
$assert_session->statusCodeEquals(200);
$assert_session->fieldExists('name');
$assert_session->fieldExists('pass');
@@ -919,6 +915,11 @@ abstract class BrowserTestBase extends \PHPUnit_Framework_TestCase {
* POST data.
* @param array $options
* Options to be forwarded to the url generator.
*
* @return string
* (deprecated) The response content after submit form. It is necessary for
* backwards compatibility and will be removed before Drupal 9.0. You should
* just use the webAssert object for your assertions.
*/
protected function drupalPostForm($path, $edit, $submit, array $options = []) {
if (is_object($submit)) {
@@ -937,6 +938,8 @@ abstract class BrowserTestBase extends \PHPUnit_Framework_TestCase {
}
$this->submitForm($edit, $submit);
return $this->getSession()->getPage()->getContent();
}
/**
@@ -978,134 +981,6 @@ abstract class BrowserTestBase extends \PHPUnit_Framework_TestCase {
$this->rebuildAll();
}
/**
* Returns the parameters that will be used when Simpletest installs Drupal.
*
* @see install_drupal()
* @see install_state_defaults()
*/
protected function installParameters() {
$connection_info = Database::getConnectionInfo();
$driver = $connection_info['default']['driver'];
$connection_info['default']['prefix'] = $connection_info['default']['prefix']['default'];
unset($connection_info['default']['driver']);
unset($connection_info['default']['namespace']);
unset($connection_info['default']['pdo']);
unset($connection_info['default']['init_commands']);
$parameters = [
'interactive' => FALSE,
'parameters' => [
'profile' => $this->profile,
'langcode' => 'en',
],
'forms' => [
'install_settings_form' => [
'driver' => $driver,
$driver => $connection_info['default'],
],
'install_configure_form' => [
'site_name' => 'Drupal',
'site_mail' => 'simpletest@example.com',
'account' => [
'name' => $this->rootUser->name,
'mail' => $this->rootUser->getEmail(),
'pass' => [
'pass1' => $this->rootUser->pass_raw,
'pass2' => $this->rootUser->pass_raw,
],
],
// form_type_checkboxes_value() requires NULL instead of FALSE values
// for programmatic form submissions to disable a checkbox.
'enable_update_status_module' => NULL,
'enable_update_status_emails' => NULL,
],
],
];
return $parameters;
}
/**
* Prepares the current environment for running the test.
*
* Also sets up new resources for the testing environment, such as the public
* filesystem and configuration directories.
*
* This method is private as it must only be called once by
* BrowserTestBase::setUp() (multiple invocations for the same test would have
* unpredictable consequences) and it must not be callable or overridable by
* test classes.
*/
protected function prepareEnvironment() {
// Bootstrap Drupal so we can use Drupal's built in functions.
$this->classLoader = require __DIR__ . '/../../../../autoload.php';
$request = Request::createFromGlobals();
$kernel = TestRunnerKernel::createFromRequest($request, $this->classLoader);
// TestRunnerKernel expects the working directory to be DRUPAL_ROOT.
chdir(DRUPAL_ROOT);
$kernel->prepareLegacyRequest($request);
$this->prepareDatabasePrefix();
$this->originalSite = $kernel->findSitePath($request);
// Create test directory ahead of installation so fatal errors and debug
// information can be logged during installation process.
file_prepare_directory($this->siteDirectory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
// Prepare filesystem directory paths.
$this->publicFilesDirectory = $this->siteDirectory . '/files';
$this->privateFilesDirectory = $this->siteDirectory . '/private';
$this->tempFilesDirectory = $this->siteDirectory . '/temp';
$this->translationFilesDirectory = $this->siteDirectory . '/translations';
// Ensure the configImporter is refreshed for each test.
$this->configImporter = NULL;
// Unregister all custom stream wrappers of the parent site.
$wrappers = \Drupal::service('stream_wrapper_manager')->getWrappers(StreamWrapperInterface::ALL);
foreach ($wrappers as $scheme => $info) {
stream_wrapper_unregister($scheme);
}
// Reset statics.
drupal_static_reset();
// Ensure there is no service container.
$this->container = NULL;
\Drupal::unsetContainer();
// Unset globals.
unset($GLOBALS['config_directories']);
unset($GLOBALS['config']);
unset($GLOBALS['conf']);
// Log fatal errors.
ini_set('log_errors', 1);
ini_set('error_log', DRUPAL_ROOT . '/' . $this->siteDirectory . '/error.log');
// Change the database prefix.
$this->changeDatabasePrefix();
// After preparing the environment and changing the database prefix, we are
// in a valid test environment.
drupal_valid_test_ua($this->databasePrefix);
// Reset settings.
new Settings([
// For performance, simply use the database prefix as hash salt.
'hash_salt' => $this->databasePrefix,
]);
drupal_set_time_limit($this->timeLimit);
// Save and clean the shutdown callbacks array because it is static cached
// and will be changed by the test run. Otherwise it will contain callbacks
// from both environments and the testing environment will try to call the
// handlers defined by the original one.
$callbacks = &drupal_register_shutdown_function();
$this->originalShutdownCallbacks = $callbacks;
$callbacks = [];
}
/**
* Returns whether a given user account is logged in.
*
@@ -1195,7 +1070,7 @@ abstract class BrowserTestBase extends \PHPUnit_Framework_TestCase {
* The formatted HTML string.
*/
protected function formatHtmlOutputHeaders(array $headers) {
$flattened_headers = array_map(function($header) {
$flattened_headers = array_map(function ($header) {
if (is_array($header)) {
return implode(';', array_map('trim', $header));
}
@@ -1400,13 +1275,13 @@ abstract class BrowserTestBase extends \PHPUnit_Framework_TestCase {
* Checks for meta refresh tag and if found call drupalGet() recursively.
*
* This function looks for the http-equiv attribute to be set to "Refresh" and
* is case-sensitive.
* is case-insensitive.
*
* @return string|false
* Either the new page content or FALSE.
*/
protected function checkForMetaRefresh() {
$refresh = $this->cssSelect('meta[http-equiv="Refresh"]');
$refresh = $this->cssSelect('meta[http-equiv="Refresh"], meta[http-equiv="refresh"]');
if (!empty($refresh) && (!isset($this->maximumMetaRefreshCount) || $this->metaRefreshCount < $this->maximumMetaRefreshCount)) {
// Parse the content attribute of the meta tag for the format:
// "[delay]: URL=[page_to_redirect_to]".
@@ -6,13 +6,13 @@ use Drupal\Component\Annotation\Plugin;
use Drupal\Component\Annotation\Plugin\Discovery\AnnotationBridgeDecorator;
use Drupal\Component\Plugin\Definition\PluginDefinition;
use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
/**
* @coversDefaultClass \Drupal\Component\Annotation\Plugin\Discovery\AnnotationBridgeDecorator
* @group Plugin
*/
class AnnotationBridgeDecoratorTest extends UnitTestCase {
class AnnotationBridgeDecoratorTest extends TestCase {
/**
* @covers ::getDefinitions
@@ -7,14 +7,14 @@
namespace Drupal\Tests\Component\Assertion;
use PHPUnit_Framework_TestCase;
use PHPUnit\Framework\TestCase;
use Drupal\Component\Assertion\Inspector;
/**
* @coversDefaultClass \Drupal\Component\Assertion\Inspector
* @group Assertion
*/
class InspectorTest extends PHPUnit_Framework_TestCase {
class InspectorTest extends TestCase {
/**
* Tests asserting argument is an array or traversable object.
@@ -157,7 +157,7 @@ class InspectorTest extends PHPUnit_Framework_TestCase {
'strchr',
[$this, 'callMe'],
[__CLASS__, 'callMeStatic'],
function() {
function () {
return TRUE;
}
]));
@@ -166,7 +166,7 @@ class InspectorTest extends PHPUnit_Framework_TestCase {
'strchr',
[$this, 'callMe'],
[__CLASS__, 'callMeStatic'],
function() {
function () {
return TRUE;
},
"I'm not callable"
@@ -3,14 +3,14 @@
namespace Drupal\Tests\Component\Bridge;
use Drupal\Component\Bridge\ZfExtensionManagerSfContainer;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
/**
* @coversDefaultClass \Drupal\Component\Bridge\ZfExtensionManagerSfContainer
* @group Bridge
*/
class ZfExtensionManagerSfContainerTest extends UnitTestCase {
class ZfExtensionManagerSfContainerTest extends TestCase {
/**
* @covers ::setContainer
@@ -4,13 +4,13 @@ namespace Drupal\Tests\Component\ClassFinder;
use Composer\Autoload\ClassLoader;
use Drupal\Component\ClassFinder\ClassFinder;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
/**
* @coversDefaultClass \Drupal\Component\ClassFinder\ClassFinder
* @group ClassFinder
*/
class ClassFinderTest extends UnitTestCase {
class ClassFinderTest extends TestCase {
/**
* @covers ::findFile
@@ -20,7 +20,7 @@ class ClassFinderTest extends UnitTestCase {
// The full path is returned therefore only tests with
// assertStringEndsWith() so the test is portable.
$this->assertStringEndsWith('core/tests/Drupal/Tests/UnitTestCase.php', $finder->findFile(UnitTestCase::class));
$this->assertStringEndsWith('core/tests/Drupal/Tests/Component/ClassFinder/ClassFinderTest.php', $finder->findFile(ClassFinderTest::class));
$class = 'Not\\A\\Class';
$this->assertNull($finder->findFile($class));
@@ -30,7 +30,7 @@ class ClassFinderTest extends UnitTestCase {
$loader->register();
$this->assertEquals(__FILE__, $finder->findFile($class));
// This shouldn't prevent us from finding the original file.
$this->assertStringEndsWith('core/tests/Drupal/Tests/UnitTestCase.php', $finder->findFile(UnitTestCase::class));
$this->assertStringEndsWith('core/tests/Drupal/Tests/Component/ClassFinder/ClassFinderTest.php', $finder->findFile(ClassFinderTest::class));
// Clean up the additional autoloader after the test.
$loader->unregister();
@@ -2,14 +2,14 @@
namespace Drupal\Tests\Component\Datetime;
use Drupal\Tests\UnitTestCase;
use Drupal\Component\Datetime\DateTimePlus;
use PHPUnit\Framework\TestCase;
/**
* @coversDefaultClass \Drupal\Component\Datetime\DateTimePlus
* @group Datetime
*/
class DateTimePlusTest extends UnitTestCase {
class DateTimePlusTest extends TestCase {
/**
* Test creating dates from string and array input.
@@ -293,7 +293,7 @@ class DateTimePlusTest extends UnitTestCase {
* @see DateTimePlusTest::testDates()
*/
public function providerTestDates() {
return [
$dates = [
// String input.
// Create date object from datetime string.
['2009-03-07 10:30', 'America/Chicago', '2009-03-07T10:30:00-06:00'],
@@ -308,6 +308,19 @@ class DateTimePlusTest extends UnitTestCase {
// Same during daylight savings time.
['2009-06-07 10:30', 'Australia/Canberra', '2009-06-07T10:30:00+10:00'],
];
// On 32-bit systems, timestamps are limited to 1901-2038.
if (PHP_INT_SIZE > 4) {
// Create a date object in the distant past.
// @see https://www.drupal.org/node/2795489#comment-12127088
if (version_compare(PHP_VERSION, '5.6.15', '>=')) {
$dates[] = ['1809-02-12 10:30', 'America/Chicago', '1809-02-12T10:30:00-06:00'];
}
// Create a date object in the far future.
$dates[] = ['2345-01-02 02:04', 'UTC', '2345-01-02T02:04:00+00:00'];
}
return $dates;
}
/**
@@ -320,7 +333,7 @@ class DateTimePlusTest extends UnitTestCase {
* @see DateTimePlusTest::testDates()
*/
public function providerTestDateArrays() {
return [
$dates = [
// Array input.
// Create date object from date array, date only.
[['year' => 2010, 'month' => 2, 'day' => 28], 'America/Chicago', '2010-02-28T00:00:00-06:00'],
@@ -331,6 +344,19 @@ class DateTimePlusTest extends UnitTestCase {
// Create date object from date array with hour.
[['year' => 2010, 'month' => 2, 'day' => 28, 'hour' => 10], 'Europe/Berlin', '2010-02-28T10:00:00+01:00'],
];
// On 32-bit systems, timestamps are limited to 1901-2038.
if (PHP_INT_SIZE > 4) {
// Create a date object in the distant past.
// @see https://www.drupal.org/node/2795489#comment-12127088
if (version_compare(PHP_VERSION, '5.6.15', '>=')) {
$dates[] = [['year' => 1809, 'month' => 2, 'day' => 12], 'America/Chicago', '1809-02-12T00:00:00-06:00'];
}
// Create a date object in the far future.
$dates[] = [['year' => 2345, 'month' => 1, 'day' => 2], 'UTC', '2345-01-02T00:00:00+00:00'];
}
return $dates;
}
/**
@@ -778,4 +804,52 @@ class DateTimePlusTest extends UnitTestCase {
$date = DateTimePlus::createFromFormat('Y-m-d H:i:s', '11-03-31 17:44:00', 'UTC', ['validate_format' => TRUE]);
}
/**
* Tests that object methods are chainable.
*
* @covers ::__call
*/
public function testChainable() {
$date = new DateTimePlus('now', 'Australia/Sydney');
$date->setTimestamp(12345678);
$rendered = $date->render();
$this->assertEquals('1970-05-24 07:21:18 Australia/Sydney', $rendered);
$date->setTimestamp(23456789);
$rendered = $date->setTimezone(new \DateTimeZone('America/New_York'))->render();
$this->assertEquals('1970-09-29 07:46:29 America/New_York', $rendered);
$date = DateTimePlus::createFromFormat('Y-m-d H:i:s', '1970-05-24 07:21:18', new \DateTimeZone('Australia/Sydney'))
->setTimezone(new \DateTimeZone('America/New_York'));
$rendered = $date->render();
$this->assertInstanceOf(DateTimePlus::class, $date);
$this->assertEquals(12345678, $date->getTimestamp());
$this->assertEquals('1970-05-23 17:21:18 America/New_York', $rendered);
}
/**
* Tests that non-chainable methods work.
*
* @covers ::__call
*/
public function testChainableNonChainable() {
$datetime1 = new DateTimePlus('2009-10-11 12:00:00');
$datetime2 = new DateTimePlus('2009-10-13 12:00:00');
$interval = $datetime1->diff($datetime2);
$this->assertInstanceOf(\DateInterval::class, $interval);
$this->assertEquals('+2 days', $interval->format('%R%a days'));
}
/**
* Tests that chained calls to non-existent functions throw an exception.
*
* @covers ::__call
*/
public function testChainableNonCallable() {
$this->setExpectedException(\BadMethodCallException::class, 'Call to undefined method Drupal\Component\Datetime\DateTimePlus::nonexistent()');
$date = new DateTimePlus('now', 'Australia/Sydney');
$date->setTimezone(new \DateTimeZone('America/New_York'))->nonexistent();
}
}
@@ -3,7 +3,7 @@
namespace Drupal\Tests\Component\Datetime;
use Drupal\Component\Datetime\Time;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
/**
@@ -15,7 +15,7 @@ use Symfony\Component\HttpFoundation\Request;
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
*/
class TimeTest extends UnitTestCase {
class TimeTest extends TestCase {
/**
* The mocked request stack.
@@ -8,6 +8,7 @@
namespace Drupal\Tests\Component\DependencyInjection;
use Drupal\Component\Utility\Crypt;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\LogicException;
@@ -21,7 +22,7 @@ use Prophecy\Argument;
* @coversDefaultClass \Drupal\Component\DependencyInjection\Container
* @group DependencyInjection
*/
class ContainerTest extends \PHPUnit_Framework_TestCase {
class ContainerTest extends TestCase {
/**
* The tested container.
@@ -516,7 +517,7 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
$configurator = $this->prophesize('\Drupal\Tests\Component\DependencyInjection\MockConfiguratorInterface');
$configurator->configureService(Argument::type('object'))
->shouldBeCalled(1)
->will(function($args) use ($container) {
->will(function ($args) use ($container) {
$args[0]->setContainer($container);
});
$container->set('configurator', $configurator->reveal());
@@ -653,46 +654,6 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
$this->assertTrue($this->container->initialized('late.service_alias'), 'Late service is initialized after it was retrieved once.');
}
/**
* Tests that unsupported methods throw an Exception.
*
* @covers ::enterScope
* @covers ::leaveScope
* @covers ::addScope
* @covers ::hasScope
* @covers ::isScopeActive
*
* @dataProvider scopeExceptionTestProvider
*/
public function testScopeFunctionsWithException($method, $argument) {
$callable = [
$this->container,
$method,
];
$this->setExpectedException(\BadMethodCallException::class);
$callable($argument);
}
/**
* Data provider for scopeExceptionTestProvider().
*
* @return array[]
* Returns per data set an array with:
* - method name to call
* - argument to pass
*/
public function scopeExceptionTestProvider() {
$scope = $this->prophesize('\Symfony\Component\DependencyInjection\ScopeInterface')->reveal();
return [
['enterScope', 'test_scope'],
['leaveScope', 'test_scope'],
['hasScope', 'test_scope'],
['isScopeActive', 'test_scope'],
['addScope', $scope],
];
}
/**
* Tests that Container::getServiceIds() works properly.
*
@@ -754,12 +715,18 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
]),
'properties' => $this->getCollection(['_someProperty' => 'foo']),
'calls' => [
['setContainer', $this->getCollection([
$this->getServiceCall('service_container'),
])],
['setOtherConfigParameter', $this->getCollection([
$this->getParameterCall('some_other_config'),
])],
[
'setContainer',
$this->getCollection([
$this->getServiceCall('service_container'),
]),
],
[
'setOtherConfigParameter',
$this->getCollection([
$this->getParameterCall('some_other_config'),
]),
],
],
'priority' => 0,
];
@@ -811,7 +778,8 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
$services['invalid_argument_service'] = [
'class' => '\Drupal\Tests\Component\DependencyInjection\MockService',
'arguments' => $this->getCollection([
1, // Test passing non-strings, too.
// Test passing non-strings, too.
1,
(object) [
'type' => 'invalid',
],
@@ -863,9 +831,12 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
[NULL, 'bar'],
],
'calls' => [
['setContainer', $this->getCollection([
$this->getServiceCall('service_container'),
])],
[
'setContainer',
$this->getCollection([
$this->getServiceCall('service_container'),
]),
],
],
];
@@ -8,6 +8,7 @@
namespace Drupal\Tests\Component\DependencyInjection\Dumper {
use Drupal\Component\Utility\Crypt;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Parameter;
@@ -21,7 +22,7 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
* @coversDefaultClass \Drupal\Component\DependencyInjection\Dumper\OptimizedPhpArrayDumper
* @group DependencyInjection
*/
class OptimizedPhpArrayDumperTest extends \PHPUnit_Framework_TestCase {
class OptimizedPhpArrayDumperTest extends TestCase {
/**
* The container builder instance.
@@ -211,6 +212,8 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
* @covers ::getParameterCall
*
* @dataProvider getDefinitionsDataProvider
*
* @group legacy
*/
public function testGetServiceDefinitions($services, $definition_services) {
$this->containerDefinition['services'] = $definition_services;
@@ -248,7 +251,6 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
'arguments_count' => 0,
'properties' => [],
'calls' => [],
'scope' => ContainerInterface::SCOPE_CONTAINER,
'shared' => TRUE,
'factory' => FALSE,
'configurator' => FALSE,
@@ -360,11 +362,6 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
'calls' => $calls,
] + $base_service_definition;
$service_definitions[] = [
'scope' => ContainerInterface::SCOPE_PROTOTYPE,
'shared' => FALSE,
] + $base_service_definition;
$service_definitions[] = [
'shared' => FALSE,
] + $base_service_definition;
@@ -407,7 +404,6 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
$definition->getArguments()->willReturn($service_definition['arguments']);
$definition->getProperties()->willReturn($service_definition['properties']);
$definition->getMethodCalls()->willReturn($service_definition['calls']);
$definition->getScope()->willReturn($service_definition['scope']);
$definition->isShared()->willReturn($service_definition['shared']);
$definition->getDecoratedService()->willReturn(NULL);
$definition->getFactory()->willReturn($service_definition['factory']);
@@ -440,9 +436,6 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
}
}
// Remove any remaining scope.
unset($filtered_service_definition['scope']);
if (isset($filtered_service_definition['public']) && $filtered_service_definition['public'] === FALSE) {
$services_provided[] = [
['foo_service' => $definition->reveal()],
@@ -480,27 +473,14 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
];
}
/**
* Tests that the correct InvalidArgumentException is thrown for getScope().
*
* @covers ::getServiceDefinition
*/
public function testGetServiceDefinitionWithInvalidScope() {
$bar_definition = new Definition('\stdClass');
$bar_definition->setScope('foo_scope');
$services['bar'] = $bar_definition;
$this->containerBuilder->getDefinitions()->willReturn($services);
$this->setExpectedException(InvalidArgumentException::class);
$this->dumper->getArray();
}
/**
* Tests that references to aliases work correctly.
*
* @covers ::getReferenceCall
*
* @dataProvider publicPrivateDataProvider
*
* @group legacy
*/
public function testGetServiceDefinitionWithReferenceToAlias($public) {
$bar_definition = new Definition('\stdClass');
@@ -556,6 +536,8 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
* getDecoratedService().
*
* @covers ::getServiceDefinition
*
* @group legacy
*/
public function testGetServiceDefinitionForDecoratedService() {
$bar_definition = new Definition('\stdClass');
@@ -664,6 +646,7 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
* define a dummy, else it cannot be tested.
*/
namespace Symfony\Component\ExpressionLanguage {
if (!class_exists('\Symfony\Component\ExpressionLanguage\Expression')) {
/**
* Dummy class to ensure non-existent Symfony component can be tested.
@@ -4,6 +4,7 @@ namespace Drupal\Tests\Component\Diff;
use Drupal\Component\Diff\Diff;
use Drupal\Component\Diff\DiffFormatter;
use PHPUnit\Framework\TestCase;
/**
* Test DiffFormatter classes.
@@ -12,7 +13,7 @@ use Drupal\Component\Diff\DiffFormatter;
*
* @group Diff
*/
class DiffFormatterTest extends \PHPUnit_Framework_TestCase {
class DiffFormatterTest extends TestCase {
/**
* @return array
@@ -7,6 +7,7 @@ use Drupal\Component\Diff\Engine\DiffOpAdd;
use Drupal\Component\Diff\Engine\DiffOpCopy;
use Drupal\Component\Diff\Engine\DiffOpChange;
use Drupal\Component\Diff\Engine\DiffOpDelete;
use PHPUnit\Framework\TestCase;
/**
* Test DiffEngine class.
@@ -15,7 +16,7 @@ use Drupal\Component\Diff\Engine\DiffOpDelete;
*
* @group Diff
*/
class DiffEngineTest extends \PHPUnit_Framework_TestCase {
class DiffEngineTest extends TestCase {
/**
* @return array
@@ -3,6 +3,7 @@
namespace Drupal\Tests\Component\Diff\Engine;
use Drupal\Component\Diff\Engine\DiffOp;
use PHPUnit\Framework\TestCase;
/**
* Test DiffOp base class.
@@ -15,7 +16,7 @@ use Drupal\Component\Diff\Engine\DiffOp;
*
* @group Diff
*/
class DiffOpTest extends \PHPUnit_Framework_TestCase {
class DiffOpTest extends TestCase {
/**
* DiffOp::reverse() always throws an error.
@@ -3,6 +3,7 @@
namespace Drupal\Tests\Component\Diff\Engine;
use Drupal\Component\Diff\Engine\HWLDFWordAccumulator;
use PHPUnit\Framework\TestCase;
/**
* Test HWLDFWordAccumulator.
@@ -11,7 +12,7 @@ use Drupal\Component\Diff\Engine\HWLDFWordAccumulator;
*
* @group Diff
*/
class HWLDFWordAccumulatorTest extends \PHPUnit_Framework_TestCase {
class HWLDFWordAccumulatorTest extends TestCase {
/**
* Verify that we only get back a NBSP from an empty accumulator.
@@ -4,8 +4,9 @@ namespace Drupal\Tests\Component\Discovery;
use Drupal\Component\Discovery\DiscoveryException;
use Drupal\Component\Discovery\YamlDirectoryDiscovery;
use Drupal\Tests\UnitTestCase;
use Drupal\Component\FileCache\FileCacheFactory;
use org\bovigo\vfs\vfsStream;
use PHPUnit\Framework\TestCase;
/**
* YamlDirectoryDiscoveryTest component unit tests.
@@ -14,7 +15,15 @@ use org\bovigo\vfs\vfsStream;
*
* @group Discovery
*/
class YamlDirectoryDiscoveryTest extends UnitTestCase {
class YamlDirectoryDiscoveryTest extends TestCase {
/**
* {@inheritdoc}
*/
protected function setUp() {
// Ensure that FileCacheFactory has a prefix.
FileCacheFactory::setPrefix('prefix');
}
/**
* Tests YAML directory discovery.
@@ -2,18 +2,27 @@
namespace Drupal\Tests\Component\Discovery;
use Drupal\Tests\UnitTestCase;
use Drupal\Component\Discovery\YamlDiscovery;
use Drupal\Component\FileCache\FileCacheFactory;
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\vfsStreamWrapper;
use org\bovigo\vfs\vfsStreamDirectory;
use PHPUnit\Framework\TestCase;
/**
* YamlDiscovery component unit tests.
*
* @group Discovery
*/
class YamlDiscoveryTest extends UnitTestCase {
class YamlDiscoveryTest extends TestCase {
/**
* {@inheritdoc}
*/
protected function setUp() {
// Ensure that FileCacheFactory has a prefix.
FileCacheFactory::setPrefix('prefix');
}
/**
* Tests the YAML file discovery.
@@ -2,15 +2,15 @@
namespace Drupal\Tests\Component;
use Drupal\Tests\UnitTestCase;
use org\bovigo\vfs\vfsStream;
use PHPUnit\Framework\TestCase;
/**
* General tests for \Drupal\Component that can't go anywhere else.
*
* @group Component
*/
class DrupalComponentTest extends UnitTestCase {
class DrupalComponentTest extends TestCase {
/**
* Tests that classes in Component do not use any Core class.
@@ -64,7 +64,7 @@ class DrupalComponentTest extends UnitTestCase {
protected function assertNoCoreUsage($class_path) {
$contents = file_get_contents($class_path);
preg_match_all('/^.*Drupal\\\Core.*$/m', $contents, $matches);
$matches = array_filter($matches[0], function($line) {
$matches = array_filter($matches[0], function ($line) {
// Filter references to @see as they don't really matter.
return strpos($line, '@see') === FALSE;
});
@@ -6,9 +6,10 @@ namespace Drupal\Tests\Component\EventDispatcher;
use Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\Tests\CallableClass;
use Symfony\Component\EventDispatcher\Tests\TestEventListener;
use Symfony\Component\EventDispatcher\Tests\ContainerAwareEventDispatcherTest as SymfonyContainerAwareEventDispatcherTest;
use Symfony\Component\EventDispatcher\Tests\TestEventListener;
/**
* Unit tests for the ContainerAwareEventDispatcher.
@@ -37,7 +38,7 @@ class ContainerAwareEventDispatcherTest extends SymfonyContainerAwareEventDispat
// When passing in callables exclusively as listeners into the event
// dispatcher constructor, the event dispatcher must not attempt to
// resolve any services.
$container = $this->getMock('Symfony\Component\DependencyInjection\IntrospectableContainerInterface');
$container = $this->getMock(ContainerInterface::class);
$container->expects($this->never())->method($this->anything());
$firstListener = new CallableClass();
@@ -72,7 +73,7 @@ class ContainerAwareEventDispatcherTest extends SymfonyContainerAwareEventDispat
// When passing in callables exclusively as listeners into the event
// dispatcher constructor, the event dispatcher must not attempt to
// resolve any services.
$container = $this->getMock('Symfony\Component\DependencyInjection\IntrospectableContainerInterface');
$container = $this->getMock(ContainerInterface::class);
$container->expects($this->never())->method($this->anything());
$firstListener = new CallableClass();
@@ -5,13 +5,14 @@ namespace Drupal\Tests\Component\FileCache;
use Drupal\Component\FileCache\FileCache;
use Drupal\Component\FileCache\NullFileCache;
use Drupal\Component\FileCache\FileCacheFactory;
use Drupal\Tests\UnitTestCase;
use Drupal\Component\Utility\Random;
use PHPUnit\Framework\TestCase;
/**
* @coversDefaultClass \Drupal\Component\FileCache\FileCacheFactory
* @group FileCache
*/
class FileCacheFactoryTest extends UnitTestCase {
class FileCacheFactoryTest extends TestCase {
/**
* {@inheritdoc}
@@ -104,51 +105,54 @@ class FileCacheFactoryTest extends UnitTestCase {
$class = get_class($file_cache);
// Test fallback configuration.
$data['fallback-configuration'] = [[
], [], FileCache::class];
$data['fallback-configuration'] = [
[],
[],
FileCache::class,
];
// Test default configuration.
$data['default-configuration'] = [[
'default' => [
'class' => $class,
],
], [], $class];
$data['default-configuration'] = [
['default' => ['class' => $class]],
[],
$class,
];
// Test specific per collection setting.
$data['collection-setting'] = [[
'test_foo_settings' => [
'class' => $class,
],
], [], $class];
$data['collection-setting'] = [
['test_foo_settings' => ['class' => $class]],
[],
$class,
];
// Test default configuration plus specific per collection setting.
$data['default-plus-collection-setting'] = [[
'default' => [
'class' => '\stdClass',
$data['default-plus-collection-setting'] = [
[
'default' => ['class' => '\stdClass'],
'test_foo_settings' => ['class' => $class],
],
'test_foo_settings' => [
'class' => $class,
],
], [], $class];
[],
$class,
];
// Test default configuration plus class specific override.
$data['default-plus-class-override'] = [[
'default' => [
'class' => '\stdClass',
],
], [ 'class' => $class ], $class];
$data['default-plus-class-override'] = [
['default' => ['class' => '\stdClass']],
['class' => $class],
$class,
];
// Test default configuration plus class specific override plus specific
// per collection setting.
$data['default-plus-class-plus-collection-setting'] = [[
'default' => [
'class' => '\stdClass',
$data['default-plus-class-plus-collection-setting'] = [
[
'default' => ['class' => '\stdClass'],
'test_foo_settings' => ['class' => $class],
],
'test_foo_settings' => [
'class' => $class,
],
], [ 'class' => '\stdClass'], $class];
['class' => '\stdClass'],
$class,
];
return $data;
}
@@ -170,7 +174,10 @@ class FileCacheFactoryTest extends UnitTestCase {
* @covers ::setPrefix
*/
public function testGetSetPrefix() {
$prefix = $this->randomMachineName();
// Random generator.
$random = new Random();
$prefix = $random->name(8, TRUE);
FileCacheFactory::setPrefix($prefix);
$this->assertEquals($prefix, FileCacheFactory::getPrefix());
}
@@ -3,13 +3,13 @@
namespace Drupal\Tests\Component\FileCache;
use Drupal\Component\FileCache\FileCache;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
/**
* @coversDefaultClass \Drupal\Component\FileCache\FileCache
* @group FileCache
*/
class FileCacheTest extends UnitTestCase {
class FileCacheTest extends TestCase {
/**
* FileCache object used for the tests.
@@ -3,14 +3,14 @@
namespace Drupal\Tests\Component\FileSystem;
use Drupal\Component\FileSystem\RegexDirectoryIterator;
use Drupal\Tests\UnitTestCase;
use org\bovigo\vfs\vfsStream;
use PHPUnit\Framework\TestCase;
/**
* @coversDefaultClass \Drupal\Component\FileSystem\RegexDirectoryIterator
* @group FileSystem
*/
class RegexDirectoryIteratorTest extends UnitTestCase {
class RegexDirectoryIteratorTest extends TestCase {
/**
* @covers ::accept
@@ -21,7 +21,7 @@ class RegexDirectoryIteratorTest extends UnitTestCase {
$iterator = new RegexDirectoryIterator(vfsStream::url('root'), $regex);
// Create an array of filenames to assert against.
$file_list = array_map(function(\SplFileInfo $file) {
$file_list = array_map(function (\SplFileInfo $file) {
return $file->getFilename();
}, array_values(iterator_to_array($iterator)));
@@ -3,7 +3,7 @@
namespace Drupal\Tests\Component\Gettext;
use Drupal\Component\Gettext\PoHeader;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
/**
* Unit tests for the Gettext PO file header handling features.
@@ -12,7 +12,7 @@ use Drupal\Tests\UnitTestCase;
*
* @group Gettext
*/
class PoHeaderTest extends UnitTestCase {
class PoHeaderTest extends TestCase {
/**
* Tests that plural expressions are evaluated correctly.
@@ -279,7 +279,8 @@ class PoHeaderTest extends UnitTestCase {
193 => 1,
194 => 1,
'default' => 2,
], ],
],
],
[
'nplurals=4; plural=(((n==1)||(n==11))?(0):(((n==2)||(n==12))?(1):(((n>2)&&(n<20))?(2):3)));',
[
@@ -3,13 +3,13 @@
namespace Drupal\Tests\Component\Graph;
use Drupal\Component\Graph\Graph;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
/**
* @coversDefaultClass \Drupal\Component\Graph\Graph
* @group Graph
*/
class GraphTest extends UnitTestCase {
class GraphTest extends TestCase {
/**
* Test depth-first-search features.
@@ -8,7 +8,7 @@
namespace Drupal\Tests\Component\HttpFoundation;
use Drupal\Component\HttpFoundation\SecuredRedirectResponse;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\RedirectResponse;
@@ -18,7 +18,7 @@ use Symfony\Component\HttpFoundation\RedirectResponse;
* @group Routing
* @coversDefaultClass \Drupal\Component\HttpFoundation\SecuredRedirectResponse
*/
class SecuredRedirectResponseTest extends UnitTestCase {
class SecuredRedirectResponseTest extends TestCase {
/**
* Test copying of redirect response.
@@ -4,6 +4,7 @@ namespace Drupal\Tests\Component\PhpStorage;
use Drupal\Component\PhpStorage\FileStorage;
use Drupal\Component\PhpStorage\FileReadOnlyStorage;
use Drupal\Component\Utility\Random;
/**
* @coversDefaultClass \Drupal\Component\PhpStorage\FileReadOnlyStorage
@@ -48,8 +49,11 @@ class FileStorageReadOnlyTest extends PhpStorageTestBase {
* Tests writing with one class and reading with another.
*/
public function testReadOnly() {
// Random generator.
$random = new Random();
$php = new FileStorage($this->standardSettings);
$name = $this->randomMachineName() . '/' . $this->randomMachineName() . '.php';
$name = $random->name(8, TRUE) . '/' . $random->name(8, TRUE) . '.php';
// Find a global that doesn't exist.
do {
@@ -85,8 +89,11 @@ class FileStorageReadOnlyTest extends PhpStorageTestBase {
* @covers ::deleteAll
*/
public function testDeleteAll() {
// Random generator.
$random = new Random();
$php = new FileStorage($this->standardSettings);
$name = $this->randomMachineName() . '/' . $this->randomMachineName() . '.php';
$name = $random->name(8, TRUE) . '/' . $random->name(8, TRUE) . '.php';
// Find a global that doesn't exist.
do {
@@ -3,6 +3,7 @@
namespace Drupal\Tests\Component\PhpStorage;
use Drupal\Component\PhpStorage\FileStorage;
use Drupal\Component\Utility\Random;
/**
* @coversDefaultClass \Drupal\Component\PhpStorage\FileStorage
@@ -55,11 +56,13 @@ class FileStorageTest extends PhpStorageTestBase {
* @covers ::deleteAll
*/
public function testDeleteAll() {
// Random generator.
$random_generator = new Random();
// Write out some files.
$php = new FileStorage($this->standardSettings);
$name = $this->randomMachineName() . '/' . $this->randomMachineName() . '.php';
$name = $random_generator->name(8, TRUE) . '/' . $random_generator->name(8, TRUE) . '.php';
// Find a global that doesn't exist.
do {
@@ -3,6 +3,7 @@
namespace Drupal\Tests\Component\PhpStorage;
use Drupal\Component\Utility\Crypt;
use Drupal\Component\Utility\Random;
/**
* Base test class for MTime protected storage.
@@ -36,7 +37,10 @@ abstract class MTimeProtectedFileStorageBase extends PhpStorageTestBase {
protected function setUp() {
parent::setUp();
$this->secret = $this->randomMachineName();
// Random generator.
$random = new Random();
$this->secret = $random->name(8, TRUE);
$this->settings = [
'directory' => $this->directory,
@@ -3,13 +3,14 @@
namespace Drupal\Tests\Component\PhpStorage;
use Drupal\Component\PhpStorage\PhpStorageInterface;
use Drupal\Tests\UnitTestCase;
use Drupal\Component\Utility\Random;
use org\bovigo\vfs\vfsStream;
use PHPUnit\Framework\TestCase;
/**
* Base test for PHP storages.
*/
abstract class PhpStorageTestBase extends UnitTestCase {
abstract class PhpStorageTestBase extends TestCase {
/**
* A unique per test class directory path to test php storage.
@@ -31,7 +32,10 @@ abstract class PhpStorageTestBase extends UnitTestCase {
* Assert that a PHP storage's load/save/delete operations work.
*/
public function assertCRUD($php) {
$name = $this->randomMachineName() . '/' . $this->randomMachineName() . '.php';
// Random generator.
$random_generator = new Random();
$name = $random_generator->name(8, TRUE) . '/' . $random_generator->name(8, TRUE) . '.php';
// Find a global that doesn't exist.
do {
@@ -3,13 +3,13 @@
namespace Drupal\Tests\Component\Plugin\Context;
use Drupal\Component\Plugin\Context\Context;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
/**
* @coversDefaultClass \Drupal\Component\Plugin\Context\Context
* @group Plugin
*/
class ContextTest extends UnitTestCase {
class ContextTest extends TestCase {
/**
* Data provider for testGetContextValue.
@@ -8,13 +8,13 @@ use Drupal\Component\Plugin\Factory\DefaultFactory;
use Drupal\plugin_test\Plugin\plugin_test\fruit\Cherry;
use Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface;
use Drupal\plugin_test\Plugin\plugin_test\fruit\Kale;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
/**
* @coversDefaultClass \Drupal\Component\Plugin\Factory\DefaultFactory
* @group Plugin
*/
class DefaultFactoryTest extends UnitTestCase {
class DefaultFactoryTest extends TestCase {
/**
* Tests getPluginClass() with a valid array plugin definition.
@@ -2,14 +2,14 @@
namespace Drupal\Tests\Component\Plugin\Discovery;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
/**
* @coversDefaultClass \Drupal\Component\Plugin\Discovery\DiscoveryCachedTrait
* @uses \Drupal\Component\Plugin\Discovery\DiscoveryTrait
* @group Plugin
*/
class DiscoveryCachedTraitTest extends UnitTestCase {
class DiscoveryCachedTraitTest extends TestCase {
/**
* Data provider for testGetDefinition().
@@ -46,7 +46,7 @@ class DiscoveryCachedTraitTest extends UnitTestCase {
$trait->expects($this->once())
->method('getDefinitions')
// Use a callback method, so we can perform the side-effects.
->willReturnCallback(function() use ($reflection_definitions, $trait, $get_definitions) {
->willReturnCallback(function () use ($reflection_definitions, $trait, $get_definitions) {
$reflection_definitions->setValue($trait, $get_definitions);
return $get_definitions;
});
@@ -3,13 +3,13 @@
namespace Drupal\Tests\Component\Plugin\Discovery;
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
/**
* @group Plugin
* @coversDefaultClass \Drupal\Component\Plugin\Discovery\DiscoveryTrait
*/
class DiscoveryTraitTest extends UnitTestCase {
class DiscoveryTraitTest extends TestCase {
/**
* Data provider for testDoGetDefinition().
@@ -2,13 +2,13 @@
namespace Drupal\Tests\Component\Plugin\Discovery;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
/**
* @group Plugin
* @coversDefaultClass \Drupal\Component\Plugin\Discovery\StaticDiscoveryDecorator
*/
class StaticDiscoveryDecoratorTest extends UnitTestCase {
class StaticDiscoveryDecoratorTest extends TestCase {
/**
* Helper method to provide a mocked callback object with expectations.
@@ -171,7 +171,7 @@ class StaticDiscoveryDecoratorTest extends UnitTestCase {
// Exercise getDefinitions(). It calls parent::getDefinitions() but in this
// case there will be no side-effects.
$this->assertArrayEquals(
$this->assertEquals(
$definitions,
$mock_decorator->getDefinitions()
);
@@ -220,7 +220,7 @@ class StaticDiscoveryDecoratorTest extends UnitTestCase {
$ref_decorated->setValue($mock_decorator, $mock_decorated);
// Exercise __call.
$this->assertArrayEquals(
$this->assertEquals(
$args,
\call_user_func_array([$mock_decorated, $method], $args)
);
@@ -10,13 +10,13 @@
namespace Drupal\Tests\Component\Plugin\Factory;
use Drupal\Component\Plugin\Factory\ReflectionFactory;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
/**
* @group Plugin
* @coversDefaultClass \Drupal\Component\Plugin\Factory\ReflectionFactory
*/
class ReflectionFactoryTest extends UnitTestCase {
class ReflectionFactoryTest extends TestCase {
/**
* Data provider for testGetInstanceArguments.
@@ -172,9 +172,7 @@ class ArgumentsPluginId {
*/
class ArgumentsMany {
public function __construct(
$configuration, $plugin_definition, $plugin_id, $foo = 'default_value', $what_am_i_doing_here = 'what_default'
) {
public function __construct($configuration, $plugin_definition, $plugin_id, $foo = 'default_value', $what_am_i_doing_here = 'what_default') {
// No-op.
}
@@ -2,13 +2,13 @@
namespace Drupal\Tests\Component\Plugin;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
/**
* @coversDefaultClass \Drupal\Component\Plugin\PluginBase
* @group Plugin
*/
class PluginBaseTest extends UnitTestCase {
class PluginBaseTest extends TestCase {
/**
* @dataProvider providerTestGetPluginId
@@ -3,13 +3,13 @@
namespace Drupal\Tests\Component\Plugin;
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
/**
* @coversDefaultClass \Drupal\Component\Plugin\PluginManagerBase
* @group Plugin
*/
class PluginManagerBaseTest extends UnitTestCase {
class PluginManagerBaseTest extends TestCase {
/**
* A callback method for mocking FactoryInterface objects.
@@ -58,7 +58,7 @@ class PluginManagerBaseTest extends UnitTestCase {
$configuration_array = ['config' => 'something'];
$result = $manager->createInstance('valid', $configuration_array);
$this->assertEquals('valid', $result['plugin_id']);
$this->assertArrayEquals($configuration_array, $result['configuration']);
$this->assertEquals($configuration_array, $result['configuration']);
}
/**
@@ -81,13 +81,13 @@ class PluginManagerBaseTest extends UnitTestCase {
$factory_ref->setValue($manager, $this->getMockFactoryInterface(1));
$no_fallback_result = $manager->createInstance('valid', $configuration_array);
$this->assertEquals('valid', $no_fallback_result['plugin_id']);
$this->assertArrayEquals($configuration_array, $no_fallback_result['configuration']);
$this->assertEquals($configuration_array, $no_fallback_result['configuration']);
// Test with fallback interface and invalid plugin_id.
$factory_ref->setValue($manager, $this->getMockFactoryInterface(2));
$fallback_result = $manager->createInstance('invalid', $configuration_array);
$this->assertEquals('invalid_fallback', $fallback_result['plugin_id']);
$this->assertArrayEquals($configuration_array, $fallback_result['configuration']);
$this->assertEquals($configuration_array, $fallback_result['configuration']);
}
}
@@ -8,13 +8,13 @@
namespace Drupal\Tests\Component\ProxyBuilder;
use Drupal\Component\ProxyBuilder\ProxyBuilder;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
/**
* @coversDefaultClass \Drupal\Component\ProxyBuilder\ProxyBuilder
* @group proxy_builder
*/
class ProxyBuilderTest extends UnitTestCase {
class ProxyBuilderTest extends TestCase {
/**
* The tested proxy builder.
@@ -3,7 +3,7 @@
namespace Drupal\Tests\Component\Render;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
/**
* Tests the TranslatableMarkup class.
@@ -11,7 +11,7 @@ use Drupal\Tests\UnitTestCase;
* @coversDefaultClass \Drupal\Component\Render\FormattableMarkup
* @group utility
*/
class FormattableMarkupTest extends UnitTestCase {
class FormattableMarkupTest extends TestCase {
/**
* The error message of the last error in the error handler.
@@ -4,7 +4,7 @@ namespace Drupal\Tests\Component\Render;
use Drupal\Component\Render\HtmlEscapedText;
use Drupal\Component\Render\MarkupInterface;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
/**
* Tests the HtmlEscapedText class.
@@ -12,7 +12,7 @@ use Drupal\Tests\UnitTestCase;
* @coversDefaultClass \Drupal\Component\Render\HtmlEscapedText
* @group utility
*/
class HtmlEscapedTextTest extends UnitTestCase {
class HtmlEscapedTextTest extends TestCase {
/**
* @covers ::__toString
@@ -5,13 +5,13 @@ namespace Drupal\Tests\Component\Render;
use Drupal\Component\Render\PlainTextOutput;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Component\Render\MarkupInterface;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
/**
* @coversDefaultClass \Drupal\Component\Render\PlainTextOutput
* @group Utility
*/
class PlainTextOutputTest extends UnitTestCase {
class PlainTextOutputTest extends TestCase {
/**
* Tests ::renderFromHtml().
@@ -3,13 +3,13 @@
namespace Drupal\Tests\Component\Serialization;
use Drupal\Component\Serialization\Json;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
/**
* @coversDefaultClass \Drupal\Component\Serialization\Json
* @group Serialization
*/
class JsonTest extends UnitTestCase {
class JsonTest extends TestCase {
/**
* A test string with the full ASCII table.
@@ -7,13 +7,13 @@ use Drupal\Component\Serialization\SerializationInterface;
use Drupal\Component\Serialization\Yaml;
use Drupal\Component\Serialization\YamlPecl;
use Drupal\Component\Serialization\YamlSymfony;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
/**
* @coversDefaultClass \Drupal\Component\Serialization\Yaml
* @group Serialization
*/
class YamlTest extends UnitTestCase {
class YamlTest extends TestCase {
/**
* @var \PHPUnit_Framework_MockObject_MockObject
@@ -2,10 +2,12 @@
namespace Drupal\Tests\Component\Serialization;
use PHPUnit\Framework\TestCase;
/**
* Provides standard data to validate different YAML implementations.
*/
abstract class YamlTestBase extends \PHPUnit_Framework_TestCase {
abstract class YamlTestBase extends TestCase {
/**
* Some data that should be able to be serialized.
@@ -4,8 +4,8 @@ namespace Drupal\Tests\Component\Transliteration;
use Drupal\Component\Transliteration\PhpTransliteration;
use Drupal\Component\Utility\Random;
use Drupal\Tests\UnitTestCase;
use org\bovigo\vfs\vfsStream;
use PHPUnit\Framework\TestCase;
/**
* Tests Transliteration component functionality.
@@ -14,7 +14,7 @@ use org\bovigo\vfs\vfsStream;
*
* @coversDefaultClass \Drupal\Component\Transliteration\PhpTransliteration
*/
class PhpTransliterationTest extends UnitTestCase {
class PhpTransliterationTest extends TestCase {
/**
* Tests the PhpTransliteration::removeDiacritics() function.
@@ -8,13 +8,13 @@
namespace Drupal\Tests\Component\Utility;
use Drupal\Component\Utility\ArgumentsResolver;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
/**
* @coversDefaultClass \Drupal\Component\Utility\ArgumentsResolver
* @group Access
*/
class ArgumentsResolverTest extends UnitTestCase {
class ArgumentsResolverTest extends TestCase {
/**
* {@inheritdoc}
@@ -41,22 +41,22 @@ class ArgumentsResolverTest extends UnitTestCase {
// Test an optional parameter with no provided value.
$data[] = [
function($foo = 'foo') {}, [], [], [] , ['foo'],
function ($foo = 'foo') {}, [], [], [] , ['foo'],
];
// Test an optional parameter with a provided value.
$data[] = [
function($foo = 'foo') {}, ['foo' => 'bar'], [], [], ['bar'],
function ($foo = 'foo') {}, ['foo' => 'bar'], [], [], ['bar'],
];
// Test with a provided value.
$data[] = [
function($foo) {}, ['foo' => 'bar'], [], [], ['bar'],
function ($foo) {}, ['foo' => 'bar'], [], [], ['bar'],
];
// Test with an explicitly NULL value.
$data[] = [
function($foo) {}, [], ['foo' => NULL], [], [NULL],
function ($foo) {}, [], ['foo' => NULL], [], [NULL],
];
// Test with a raw value that overrides the provided upcast value, since
@@ -64,7 +64,7 @@ class ArgumentsResolverTest extends UnitTestCase {
$scalars = ['foo' => 'baz'];
$objects = ['foo' => new \stdClass()];
$data[] = [
function($foo) {}, $scalars, $objects, [], ['baz'],
function ($foo) {}, $scalars, $objects, [], ['baz'],
];
return $data;
@@ -74,7 +74,7 @@ class ArgumentsResolverTest extends UnitTestCase {
* Tests getArgument() with an object.
*/
public function testGetArgumentObject() {
$callable = function(\stdClass $object) {};
$callable = function (\stdClass $object) {};
$object = new \stdClass();
$arguments = (new ArgumentsResolver([], ['object' => $object], []))->getArguments($callable);
@@ -85,7 +85,7 @@ class ArgumentsResolverTest extends UnitTestCase {
* Tests getArgument() with a wildcard object for a parameter with a custom name.
*/
public function testGetWildcardArgument() {
$callable = function(\stdClass $custom_name) {};
$callable = function (\stdClass $custom_name) {};
$object = new \stdClass();
$arguments = (new ArgumentsResolver([], [], [$object]))->getArguments($callable);
@@ -96,9 +96,9 @@ class ArgumentsResolverTest extends UnitTestCase {
* Tests getArgument() with a Route, Request, and Account object.
*/
public function testGetArgumentOrder() {
$a1 = $this->getMock('\Drupal\Tests\Component\Utility\TestInterface1');
$a1 = $this->getMock('\Drupal\Tests\Component\Utility\Test1Interface');
$a2 = $this->getMock('\Drupal\Tests\Component\Utility\TestClass');
$a3 = $this->getMock('\Drupal\Tests\Component\Utility\TestInterface2');
$a3 = $this->getMock('\Drupal\Tests\Component\Utility\Test2Interface');
$objects = [
't1' => $a1,
@@ -107,12 +107,12 @@ class ArgumentsResolverTest extends UnitTestCase {
$wildcards = [$a3];
$resolver = new ArgumentsResolver([], $objects, $wildcards);
$callable = function(TestInterface1 $t1, TestClass $tc, TestInterface2 $t2) {};
$callable = function (Test1Interface $t1, TestClass $tc, Test2Interface $t2) {};
$arguments = $resolver->getArguments($callable);
$this->assertSame([$a1, $a2, $a3], $arguments);
// Test again, but with the arguments in a different order.
$callable = function(TestInterface2 $t2, TestClass $tc, TestInterface1 $t1) {};
$callable = function (Test2Interface $t2, TestClass $tc, Test1Interface $t1) {};
$arguments = $resolver->getArguments($callable);
$this->assertSame([$a3, $a2, $a1], $arguments);
}
@@ -123,11 +123,11 @@ class ArgumentsResolverTest extends UnitTestCase {
* Without the typehint, the wildcard object will not be passed to the callable.
*/
public function testGetWildcardArgumentNoTypehint() {
$a = $this->getMock('\Drupal\Tests\Component\Utility\TestInterface1');
$a = $this->getMock('\Drupal\Tests\Component\Utility\Test1Interface');
$wildcards = [$a];
$resolver = new ArgumentsResolver([], [], $wildcards);
$callable = function($route) {};
$callable = function ($route) {};
$this->setExpectedException(\RuntimeException::class, 'requires a value for the "$route" argument.');
$resolver->getArguments($callable);
}
@@ -142,7 +142,7 @@ class ArgumentsResolverTest extends UnitTestCase {
$scalars = ['route' => 'foo'];
$resolver = new ArgumentsResolver($scalars, [], []);
$callable = function($route) {};
$callable = function ($route) {};
$arguments = $resolver->getArguments($callable);
$this->assertSame(['foo'], $arguments);
}
@@ -155,7 +155,7 @@ class ArgumentsResolverTest extends UnitTestCase {
$scalars = ['foo' => 'baz'];
$resolver = new ArgumentsResolver($scalars, $objects, []);
$callable = function(\stdClass $foo) {};
$callable = function (\stdClass $foo) {};
$this->setExpectedException(\RuntimeException::class, 'requires a value for the "$foo" argument.');
$resolver->getArguments($callable);
}
@@ -176,7 +176,7 @@ class ArgumentsResolverTest extends UnitTestCase {
*/
public function providerTestHandleUnresolvedArgument() {
$data = [];
$data[] = [function($foo) {}];
$data[] = [function ($foo) {}];
$data[] = [[new TestClass(), 'access']];
$data[] = ['Drupal\Tests\Component\Utility\test_access_arguments_resolver_access'];
return $data;
@@ -196,13 +196,13 @@ class TestClass {
/**
* Provides a test interface.
*/
interface TestInterface1 {
interface Test1Interface {
}
/**
* Provides a different test interface.
*/
interface TestInterface2 {
interface Test2Interface {
}
function test_access_arguments_resolver_access($foo) {
@@ -3,7 +3,7 @@
namespace Drupal\Tests\Component\Utility;
use Drupal\Component\Utility\Bytes;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
/**
* Tests bytes size parsing helper methods.
@@ -12,7 +12,7 @@ use Drupal\Tests\UnitTestCase;
*
* @coversDefaultClass \Drupal\Component\Utility\Bytes
*/
class BytesTest extends UnitTestCase {
class BytesTest extends TestCase {
/**
* Tests \Drupal\Component\Utility\Bytes::toInt().
@@ -52,8 +52,10 @@ class BytesTest extends UnitTestCase {
['1 ZB' , pow(Bytes::KILOBYTE, 7)],
['1 YB' , pow(Bytes::KILOBYTE, 8)],
['23476892 bytes', 23476892],
['76MRandomStringThatShouldBeIgnoredByParseSize.', 79691776], // 76 MB
['76.24 Giggabyte', 81862076662], // 76.24 GB (with typo)
// 76 MB.
['76MRandomStringThatShouldBeIgnoredByParseSize.', 79691776],
// 76.24 GB (with typo).
['76.24 Giggabyte', 81862076662],
];
}
@@ -3,14 +3,14 @@
namespace Drupal\Tests\Component\Utility;
use Drupal\Component\Utility\Color;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
/**
* Tests Color utility class conversions.
*
* @group Utility
*/
class ColorTest extends UnitTestCase {
class ColorTest extends TestCase {
/**
* Tests Color::hexToRgb().
@@ -2,8 +2,8 @@
namespace Drupal\Tests\Component\Utility;
use Drupal\Tests\UnitTestCase;
use Drupal\Component\Utility\Crypt;
use PHPUnit\Framework\TestCase;
/**
* Tests random byte generation fallback exception situations.
@@ -14,7 +14,7 @@ use Drupal\Component\Utility\Crypt;
*
* @coversDefaultClass \Drupal\Component\Utility\Crypt
*/
class CryptRandomFallbackTest extends UnitTestCase {
class CryptRandomFallbackTest extends TestCase {
static protected $functionCalled = 0;
@@ -52,7 +52,7 @@ class CryptRandomFallbackTest extends UnitTestCase {
namespace Drupal\Component\Utility;
use \Drupal\Tests\Component\Utility\CryptRandomFallbackTest;
use Drupal\Tests\Component\Utility\CryptRandomFallbackTest;
/**
* Defines a function in same namespace as Drupal\Component\Utility\Crypt.
@@ -2,8 +2,8 @@
namespace Drupal\Tests\Component\Utility;
use Drupal\Tests\UnitTestCase;
use Drupal\Component\Utility\Crypt;
use PHPUnit\Framework\TestCase;
/**
* Tests random byte generation.
@@ -12,7 +12,7 @@ use Drupal\Component\Utility\Crypt;
*
* @coversDefaultClass \Drupal\Component\Utility\Crypt
*/
class CryptTest extends UnitTestCase {
class CryptTest extends TestCase {
/**
* Tests random byte generation.
@@ -3,7 +3,7 @@
namespace Drupal\Tests\Component\Utility;
use Drupal\Component\Utility\Environment;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
/**
* Test PHP Environment helper methods.
@@ -12,7 +12,7 @@ use Drupal\Tests\UnitTestCase;
*
* @coversDefaultClass \Drupal\Component\Utility\Environment
*/
class EnvironmentTest extends UnitTestCase {
class EnvironmentTest extends TestCase {
/**
* Tests \Drupal\Component\Utility\Environment::checkMemoryLimit().
@@ -5,7 +5,8 @@ namespace Drupal\Tests\Component\Utility;
use Drupal\Component\Render\MarkupInterface;
use Drupal\Component\Render\MarkupTrait;
use Drupal\Component\Utility\Html;
use Drupal\Tests\UnitTestCase;
use Drupal\Component\Utility\Random;
use PHPUnit\Framework\TestCase;
/**
* Tests \Drupal\Component\Utility\Html.
@@ -14,7 +15,7 @@ use Drupal\Tests\UnitTestCase;
*
* @coversDefaultClass \Drupal\Component\Utility\Html
*/
class HtmlTest extends UnitTestCase {
class HtmlTest extends TestCase {
/**
* {@inheritdoc}
@@ -354,11 +355,14 @@ class HtmlTest extends UnitTestCase {
public function providerTestTransformRootRelativeUrlsToAbsolute() {
$data = [];
// Random generator.
$random = new Random();
// One random tag name.
$tag_name = strtolower($this->randomMachineName());
$tag_name = strtolower($random->name(8, TRUE));
// A site installed either in the root of a domain or a subdirectory.
$base_paths = ['/', '/subdir/' . $this->randomMachineName() . '/'];
$base_paths = ['/', '/subdir/' . $random->name(8, TRUE) . '/'];
foreach ($base_paths as $base_path) {
// The only attribute that has more than just a URL as its value, is
@@ -3,13 +3,13 @@
namespace Drupal\Tests\Component\Utility;
use Drupal\Component\Utility\Image;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
/**
* @coversDefaultClass \Drupal\Component\Utility\Image
* @group Image
*/
class ImageTest extends UnitTestCase {
class ImageTest extends TestCase {
/**
* Tests all control flow branches in image_dimensions_scale().
@@ -3,13 +3,13 @@
namespace Drupal\Tests\Component\Utility;
use Drupal\Component\Utility\NestedArray;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
/**
* @coversDefaultClass \Drupal\Component\Utility\NestedArray
* @group Utility
*/
class NestedArrayTest extends UnitTestCase {
class NestedArrayTest extends TestCase {
/**
* Form array to check.
@@ -268,13 +268,21 @@ class NestedArrayTest extends UnitTestCase {
[0, 1, '', TRUE], NULL, [1 => 1, 3 => TRUE]
];
$data['1d-array-callable'] = [
[0, 1, '', TRUE], function ($element) { return $element === ''; }, [2 => '']
[0, 1, '', TRUE],
function ($element) {
return $element === '';
},
[2 => ''],
];
$data['2d-array'] = [
[[0, 1, '', TRUE], [0, 1, 2, 3]], NULL, [0 => [1 => 1, 3 => TRUE], 1 => [1 => 1, 2 => 2, 3 => 3]],
];
$data['2d-array-callable'] = [
[[0, 1, '', TRUE], [0, 1, 2, 3]], function ($element) { return is_array($element) || $element === 3; }, [0 => [], 1 => [3 => 3]],
[[0, 1, '', TRUE], [0, 1, 2, 3]],
function ($element) {
return is_array($element) || $element === 3;
},
[0 => [], 1 => [3 => 3]],
];
return $data;
@@ -3,7 +3,7 @@
namespace Drupal\Tests\Component\Utility;
use Drupal\Component\Utility\Number;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
/**
* Tests number manipulation utilities.
@@ -14,7 +14,7 @@ use Drupal\Tests\UnitTestCase;
*
* @see \Drupal\Component\Utility\Number
*/
class NumberTest extends UnitTestCase {
class NumberTest extends TestCase {
/**
* Tests Number::validStep() without offset.
@@ -3,7 +3,7 @@
namespace Drupal\Tests\Component\Utility;
use Drupal\Component\Utility\Random;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
/**
* Tests random data generation.
@@ -12,7 +12,7 @@ use Drupal\Tests\UnitTestCase;
*
* @coversDefaultClass \Drupal\Component\Utility\Random
*/
class RandomTest extends UnitTestCase {
class RandomTest extends TestCase {
/**
* The first random string passed to the test callback.
File diff suppressed because it is too large Load Diff
@@ -12,7 +12,7 @@ use Drupal\Component\Utility\SafeMarkup;
use Drupal\Component\Render\MarkupInterface;
use Drupal\Component\Render\MarkupTrait;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
/**
* Tests marking strings as safe.
@@ -20,7 +20,7 @@ use Drupal\Tests\UnitTestCase;
* @group Utility
* @coversDefaultClass \Drupal\Component\Utility\SafeMarkup
*/
class SafeMarkupTest extends UnitTestCase {
class SafeMarkupTest extends TestCase {
/**
* {@inheritdoc}
@@ -2,8 +2,8 @@
namespace Drupal\Tests\Component\Utility;
use Drupal\Tests\UnitTestCase;
use Drupal\Component\Utility\SortArray;
use PHPUnit\Framework\TestCase;
/**
* Tests the SortArray component.
@@ -12,7 +12,7 @@ use Drupal\Component\Utility\SortArray;
*
* @coversDefaultClass \Drupal\Component\Utility\SortArray
*/
class SortArrayTest extends UnitTestCase {
class SortArrayTest extends TestCase {
/**
* Tests SortArray::sortByWeightElement() input against expected output.
@@ -2,8 +2,8 @@
namespace Drupal\Tests\Component\Utility;
use Drupal\Tests\UnitTestCase;
use Drupal\Component\Utility\Timer;
use PHPUnit\Framework\TestCase;
/**
* Tests the Timer system.
@@ -12,7 +12,7 @@ use Drupal\Component\Utility\Timer;
*
* @coversDefaultClass \Drupal\Component\Utility\Timer
*/
class TimerTest extends UnitTestCase {
class TimerTest extends TestCase {
/**
* Tests Timer::read() time accumulation accuracy across multiple restarts.
@@ -2,8 +2,8 @@
namespace Drupal\Tests\Component\Utility;
use Drupal\Tests\UnitTestCase;
use Drupal\Component\Utility\Unicode;
use PHPUnit\Framework\TestCase;
/**
* Test unicode handling features implemented in Unicode component.
@@ -12,7 +12,7 @@ use Drupal\Component\Utility\Unicode;
*
* @coversDefaultClass \Drupal\Component\Utility\Unicode
*/
class UnicodeTest extends UnitTestCase {
class UnicodeTest extends TestCase {
/**
* {@inheritdoc}
@@ -3,14 +3,14 @@
namespace Drupal\Tests\Component\Utility;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
/**
* @group Utility
*
* @coversDefaultClass \Drupal\Component\Utility\UrlHelper
*/
class UrlHelperTest extends UnitTestCase {
class UrlHelperTest extends TestCase {
/**
* Provides test data for testBuildQuery().
@@ -269,6 +269,14 @@ class UrlHelperTest extends UnitTestCase {
'fragment' => 'footer',
],
],
'absolute fragment, no query' => [
'http://www.example.com/my/path#footer',
[
'path' => 'http://www.example.com/my/path',
'query' => [],
'fragment' => 'footer',
],
],
[
'http://',
[
@@ -295,6 +303,14 @@ class UrlHelperTest extends UnitTestCase {
'fragment' => 'footer',
],
],
'relative fragment, no query' => [
'/my/path#footer',
[
'path' => '/my/path',
'query' => [],
'fragment' => 'footer',
],
],
];
}
@@ -391,11 +407,11 @@ class UrlHelperTest extends UnitTestCase {
* @covers ::filterBadProtocol
*
* @param string $uri
* Protocol URI.
* Protocol URI.
* @param string $expected
* Expected escaped value.
* Expected escaped value.
* @param array $protocols
* Protocols to allow.
* Protocols to allow.
*/
public function testFilterBadProtocol($uri, $expected, $protocols) {
UrlHelper::setAllowedProtocols($protocols);
@@ -430,11 +446,11 @@ class UrlHelperTest extends UnitTestCase {
* @covers ::stripDangerousProtocols
*
* @param string $uri
* Protocol URI.
* Protocol URI.
* @param string $expected
* Expected escaped value.
* Expected escaped value.
* @param array $protocols
* Protocols to allow.
* Protocols to allow.
*/
public function testStripDangerousProtocols($uri, $expected, $protocols) {
UrlHelper::setAllowedProtocols($protocols);
@@ -2,8 +2,9 @@
namespace Drupal\Tests\Component\Utility;
use Drupal\Component\Utility\Random;
use Drupal\Component\Utility\UserAgent;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
/**
* Tests bytes size parsing helper methods.
@@ -12,7 +13,7 @@ use Drupal\Tests\UnitTestCase;
*
* @coversDefaultClass \Drupal\Component\Utility\UserAgent
*/
class UserAgentTest extends UnitTestCase {
class UserAgentTest extends TestCase {
/**
* Helper method to supply language codes to testGetBestMatchingLangcode().
@@ -82,6 +83,9 @@ class UserAgentTest extends UnitTestCase {
* - Expected best matching language code.
*/
public function providerTestGetBestMatchingLangcode() {
// Random generator.
$random = new Random();
return [
// Equal qvalue for each language, choose the site preferred one.
['en,en-US,fr-CA,fr,es-MX', 'en'],
@@ -141,7 +145,7 @@ class UserAgentTest extends UnitTestCase {
['', FALSE],
['de,pl', FALSE],
['iecRswK4eh', FALSE],
[$this->randomMachineName(10), FALSE],
[$random->name(10, TRUE), FALSE],
// Chinese langcodes.
['zh-cn, en-us;q=0.90, en;q=0.80, zh;q=0.70', 'zh-hans'],
@@ -7,8 +7,8 @@
namespace Drupal\Tests\Component\Utility;
use Drupal\Tests\UnitTestCase;
use Drupal\Component\Utility\Variable;
use PHPUnit\Framework\TestCase;
/**
* Test variable export functionality in Variable component.
@@ -18,7 +18,7 @@ use Drupal\Component\Utility\Variable;
*
* @coversDefaultClass \Drupal\Component\Utility\Variable
*/
class VariableTest extends UnitTestCase {
class VariableTest extends TestCase {
/**
* Data provider for testExport().
@@ -5,7 +5,7 @@ namespace Drupal\Tests\Component\Utility;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Component\Utility\Xss;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
/**
* XSS Filtering tests.
@@ -20,7 +20,7 @@ use Drupal\Tests\UnitTestCase;
* - CVE-2002-1806, ~CVE-2005-0682, ~CVE-2005-2106, CVE-2005-3973,
* CVE-2006-1226 (= rev. 1.112?), CVE-2008-0273, CVE-2008-3740.
*/
class XssTest extends UnitTestCase {
class XssTest extends TestCase {
/**
* {@inheritdoc}
File diff suppressed because it is too large Load Diff
@@ -7,14 +7,14 @@ use Drupal\Component\Uuid\UuidInterface;
use Drupal\Component\Uuid\Com;
use Drupal\Component\Uuid\Pecl;
use Drupal\Component\Uuid\Php;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
/**
* Tests the handling of Universally Unique Identifiers (UUIDs).
*
* @group Uuid
*/
class UuidTest extends UnitTestCase {
class UuidTest extends TestCase {
/**
* Tests generating valid UUIDs.
@@ -47,6 +47,7 @@ class ComposerIntegrationTest extends UnitTestCase {
$this->root . '/core/lib/Drupal/Component/Annotation',
$this->root . '/core/lib/Drupal/Component/Assertion',
$this->root . '/core/lib/Drupal/Component/Bridge',
$this->root . '/core/lib/Drupal/Component/ClassFinder',
$this->root . '/core/lib/Drupal/Component/Datetime',
$this->root . '/core/lib/Drupal/Component/DependencyInjection',
$this->root . '/core/lib/Drupal/Component/Diff',
@@ -88,6 +89,51 @@ class ComposerIntegrationTest extends UnitTestCase {
$this->assertSame($content_hash, $lock['content-hash']);
}
/**
* Tests composer.json versions.
*
* @param string $path
* Path to a composer.json to test.
*
* @dataProvider providerTestComposerJson
*/
public function testComposerTilde($path) {
$content = json_decode(file_get_contents($path), TRUE);
$composer_keys = array_intersect(['require', 'require-dev'], array_keys($content));
if (empty($composer_keys)) {
$this->markTestSkipped("$path has no keys to test");
}
foreach ($composer_keys as $composer_key) {
foreach ($content[$composer_key] as $dependency => $version) {
// We allow tildes if the dependency is a Symfony component.
// @see https://www.drupal.org/node/2887000
if (strpos($dependency, 'symfony/') === 0) {
continue;
}
$this->assertFalse(strpos($version, '~'), "Dependency $dependency in $path contains a tilde, use a caret.");
}
}
}
/**
* Data provider for all the composer.json provided by Drupal core.
*
* @return array
*/
public function providerTestComposerJson() {
$root = realpath(__DIR__ . '/../../../../');
$tests = [[$root . '/composer.json']];
$directory = new \RecursiveDirectoryIterator($root . '/core');
$iterator = new \RecursiveIteratorIterator($directory);
/** @var \SplFileInfo $file */
foreach ($iterator as $file) {
if ($file->getFilename() === 'composer.json' && strpos($file->getPath(), 'core/modules/system/tests/fixtures/HtaccessTest') === FALSE) {
$tests[] = [$file->getRealPath()];
}
}
return $tests;
}
/**
* Tests core's composer.json replace section.
*
@@ -698,8 +698,6 @@ class AccessResultTest extends UnitTestCase {
[$neutral_un, 'OR', $forbidden_un, FALSE, NULL],
// Allowed (ct) AND allowed (ct,cf,un).
[$allowed_ct, 'AND', $allowed_ct, TRUE, TRUE],
[$allowed_ct, 'AND', $allowed_cf, TRUE, FALSE],
@@ -859,7 +857,7 @@ class AccessResultTest extends UnitTestCase {
* tested in ::testOrIf().
*/
public function testOrIfCacheabilityMerging() {
$merge_both_directions = function(AccessResult $a, AccessResult $b) {
$merge_both_directions = function (AccessResult $a, AccessResult $b) {
// A globally cacheable access result.
$a->setCacheMaxAge(3600);
// Another access result that is cacheable per permissions.
@@ -142,7 +142,9 @@ class CsrfTokenGeneratorTest extends UnitTestCase {
// The following check might throw PHP fatals and notices, so we disable
// error assertions.
set_error_handler(function () {return TRUE;});
set_error_handler(function () {
return TRUE;
});
$this->assertFalse($this->generator->validate($token, $value));
restore_error_handler();
}
@@ -14,6 +14,7 @@ use PHPUnit_Framework_ExpectationFailedException;
/**
* @coversDefaultClass \Drupal\FunctionalTests\AssertLegacyTrait
* @group Assert
* @group legacy
*/
class AssertLegacyTraitTest extends UnitTestCase {
@@ -164,6 +165,17 @@ class AssertLegacyTraitTest extends UnitTestCase {
$this->assertNoPattern('/.*foo$/');
}
/**
* @covers ::assertNoCacheTag
*/
public function testAssertNoCacheTag() {
$this->webAssert
->responseHeaderNotContains('X-Drupal-Cache-Tags', 'some-cache-tag')
->shouldBeCalled();
$this->assertNoCacheTag('some-cache-tag');
}
/**
* Returns a mocked behat session object.
*
@@ -76,7 +76,7 @@ class CssCollectionRendererUnitTest extends UnitTestCase {
* @see testRender
*/
public function providerTestRender() {
$create_link_element = function($href, $media = 'all', $browsers = []) {
$create_link_element = function ($href, $media = 'all', $browsers = []) {
return [
'#type' => 'html_tag',
'#tag' => 'link',
@@ -88,7 +88,7 @@ class CssCollectionRendererUnitTest extends UnitTestCase {
'#browsers' => $browsers,
];
};
$create_style_element = function($value, $media, $browsers = []) {
$create_style_element = function ($value, $media, $browsers = []) {
$style_element = [
'#type' => 'html_tag',
'#tag' => 'style',
@@ -101,7 +101,7 @@ class CssCollectionRendererUnitTest extends UnitTestCase {
return $style_element;
};
$create_file_css_asset = function($data, $media = 'all', $preprocess = TRUE) {
$create_file_css_asset = function ($data, $media = 'all', $preprocess = TRUE) {
return ['group' => 0, 'type' => 'file', 'media' => $media, 'preprocess' => $preprocess, 'data' => $data, 'browsers' => []];
};
@@ -502,6 +502,47 @@ class LibraryDiscoveryParserTest extends UnitTestCase {
$this->assertEquals($library['license'], $expected_license);
}
/**
* Verifies assertions catch invalid CSS declarations.
*
* @dataProvider providerTestCssAssert
*/
/**
* Verify an assertion fails if CSS declarations have non-existent categories.
*
* @param string $extension
* The css extension to build.
* @param string $exception_message
* The expected exception message.
*
* @dataProvider providerTestCssAssert
*/
public function testCssAssert($extension, $exception_message) {
$this->moduleHandler->expects($this->atLeastOnce())
->method('moduleExists')
->with($extension)
->will($this->returnValue(TRUE));
$path = __DIR__ . '/library_test_files';
$path = substr($path, strlen($this->root) + 1);
$this->libraryDiscoveryParser->setPaths('module', $extension, $path);
$this->setExpectedException(\AssertionError::class, $exception_message);
$this->libraryDiscoveryParser->buildByExtension($extension);
}
/**
* Data provider for testing bad CSS declarations.
*/
public function providerTestCssAssert() {
return [
'css_bad_category' => ['css_bad_category', 'See https://www.drupal.org/node/2274843.'],
'Improper CSS nesting' => ['css_bad_nesting', 'CSS must be nested under a category. See https://www.drupal.org/node/2274843.'],
'Improper CSS nesting array' => ['css_bad_nesting_array', 'CSS files should be specified as key/value pairs, where the values are configuration options. See https://www.drupal.org/node/2274843.'],
];
}
}
/**
@@ -0,0 +1,5 @@
bad_category:
css:
# Non-existent category.
bad_category:
css/styles.css: { minified: true }
@@ -0,0 +1,4 @@
bad_nesting:
css:
# No nesting here will break.
css/styles.css: { minified: true }
@@ -0,0 +1,4 @@
bad_nesting_array:
css:
# Specified as an array will break.
- css/styles.css
@@ -1,6 +1,7 @@
example:
css:
css/example.js: {}
theme:
css/example.css: {}
dependencies:
- external/example_external
- example_module/example
@@ -87,12 +87,12 @@ class CacheableMetadataTest extends UnitTestCase {
public function testAddCacheTags() {
$metadata = new CacheableMetadata();
$add_expected = [
[ [], [] ],
[ ['foo:bar'], ['foo:bar'] ],
[ ['foo:baz'], ['foo:bar', 'foo:baz'] ],
[ ['axx:first', 'foo:baz'], ['axx:first', 'foo:bar', 'foo:baz'] ],
[ [], ['axx:first', 'foo:bar', 'foo:baz'] ],
[ ['axx:first'], ['axx:first', 'foo:bar', 'foo:baz'] ],
[[], []],
[['foo:bar'], ['foo:bar']],
[['foo:baz'], ['foo:bar', 'foo:baz']],
[['axx:first', 'foo:baz'], ['axx:first', 'foo:bar', 'foo:baz']],
[[], ['axx:first', 'foo:bar', 'foo:baz']],
[['axx:first'], ['axx:first', 'foo:bar', 'foo:baz']],
];
foreach ($add_expected as $data) {
@@ -64,7 +64,8 @@ class ChainedFastBackendTest extends UnitTestCase {
public function testFallThroughToConsistentCache() {
$timestamp_item = (object) [
'cid' => ChainedFastBackend::LAST_WRITE_TIMESTAMP_PREFIX . 'cache_foo',
'data' => time() + 60, // Time travel is easy.
// Time travel is easy.
'data' => time() + 60,
];
$cache_item = (object) [
'cid' => 'foo',
@@ -0,0 +1,54 @@
<?php
namespace Drupal\Tests\Core\Cache\Context;
use Drupal\Core\Cache\Context\HeadersCacheContext;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
/**
* @coversDefaultClass \Drupal\Core\Cache\Context\HeadersCacheContext
* @group Cache
*/
class HeadersCacheContextTest extends UnitTestCase {
/**
* @covers ::getContext
*
* @dataProvider providerTestGetContext
*/
public function testGetContext($headers, $header_name, $context) {
$request_stack = new RequestStack();
$request = Request::create('/', 'GET');
// Request defaults could change, so compare with default values instead of
// passed in context value.
$request->headers->replace($headers);
$request_stack->push($request);
$cache_context = new HeadersCacheContext($request_stack);
$this->assertSame($cache_context->getContext($header_name), $context);
}
/**
* Provides a list of headers and expected cache contexts.
*/
public function providerTestGetContext() {
return [
[[], NULL, ''],
[[], 'foo', ''],
// Non-empty headers.
[['llama' => 'rocks', 'alpaca' => '', 'panda' => 'drools', 'z' => '0'], NULL, 'alpaca=&llama=rocks&panda=drools&z=0'],
[['llama' => 'rocks', 'alpaca' => '', 'panda' => 'drools', 'z' => '0'], 'llama', 'rocks'],
[['llama' => 'rocks', 'alpaca' => '', 'panda' => 'drools', 'z' => '0'], 'alpaca', '?valueless?'],
[['llama' => 'rocks', 'alpaca' => '', 'panda' => 'drools', 'z' => '0'], 'panda', 'drools'],
[['llama' => 'rocks', 'alpaca' => '', 'panda' => 'drools', 'z' => '0'], 'z', '0'],
[['llama' => 'rocks', 'alpaca' => '', 'panda' => 'drools', 'z' => '0'], 'chicken', ''],
// Header value could be an array.
[['z' => ['0', '1']], NULL, 'z=0,1'],
// Values are sorted to minimize cache variations.
[['z' => ['1', '0'], 'a' => []], NULL, 'a=&z=0,1'],
[['a' => [], 'z' => ['1', '0']], NULL, 'a=&z=0,1'],
];
}
}
@@ -3,6 +3,7 @@
namespace Drupal\Tests\Core\Cache\Context;
use Drupal\Core\Cache\Context\SessionCacheContext;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
@@ -10,7 +11,14 @@ use Symfony\Component\HttpFoundation\RequestStack;
* @coversDefaultClass \Drupal\Core\Cache\Context\SessionCacheContext
* @group Cache
*/
class SessionCacheContextTest extends \PHPUnit_Framework_TestCase {
class SessionCacheContextTest extends UnitTestCase {
/**
* The request.
*
* @var \Symfony\Component\HttpFoundation\Request
*/
protected $request;
/**
* The request stack.
@@ -26,36 +34,30 @@ class SessionCacheContextTest extends \PHPUnit_Framework_TestCase {
*/
protected $session;
/**
* The session cache context.
*
* @var \Drupal\Core\Cache\Context\SessionCacheContext
*/
protected $cacheContext;
public function setUp() {
$request = new Request();
$this->request = new Request();
$this->requestStack = new RequestStack();
$this->requestStack->push($request);
$this->requestStack->push($this->request);
$this->session = $this->getMock('\Symfony\Component\HttpFoundation\Session\SessionInterface');
$request->setSession($this->session);
$this->cacheContext = new SessionCacheContext($this->requestStack);
$this->session = $this->getMockBuilder('\Symfony\Component\HttpFoundation\Session\SessionInterface')
->getMock();
}
/**
* @covers ::getContext
*/
public function testSameContextForSameSession() {
$this->request->setSession($this->session);
$cache_context = new SessionCacheContext($this->requestStack);
$session_id = 'aSebeZ52bbM6SvADurQP89SFnEpxY6j8';
$this->session->expects($this->exactly(2))
->method('getId')
->will($this->returnValue($session_id));
$context1 = $this->cacheContext->getContext();
$context2 = $this->cacheContext->getContext();
$context1 = $cache_context->getContext();
$context2 = $cache_context->getContext();
$this->assertSame($context1, $context2);
$this->assertSame(FALSE, strpos($context1, $session_id), 'Session ID not contained in cache context');
}
@@ -64,6 +66,9 @@ class SessionCacheContextTest extends \PHPUnit_Framework_TestCase {
* @covers ::getContext
*/
public function testDifferentContextForDifferentSession() {
$this->request->setSession($this->session);
$cache_context = new SessionCacheContext($this->requestStack);
$session1_id = 'pjH_8aSoofyCDQiuVYXJcbfyr-CPtkUY';
$this->session->expects($this->at(0))
->method('getId')
@@ -74,12 +79,21 @@ class SessionCacheContextTest extends \PHPUnit_Framework_TestCase {
->method('getId')
->will($this->returnValue($session2_id));
$context1 = $this->cacheContext->getContext();
$context2 = $this->cacheContext->getContext();
$context1 = $cache_context->getContext();
$context2 = $cache_context->getContext();
$this->assertNotEquals($context1, $context2);
$this->assertSame(FALSE, strpos($context1, $session1_id), 'Session ID not contained in cache context');
$this->assertSame(FALSE, strpos($context2, $session2_id), 'Session ID not contained in cache context');
}
/**
* @covers ::getContext
*/
public function testContextWithoutSessionInRequest() {
$cache_context = new SessionCacheContext($this->requestStack);
$this->assertSame('none', $cache_context->getContext());
}
}
@@ -0,0 +1,112 @@
<?php
namespace Drupal\Tests\Core\Cache;
use Drupal\Core\Cache\CacheTagsChecksumInterface;
use Drupal\Core\Cache\DatabaseBackend;
use Drupal\Core\Cache\DatabaseBackendFactory;
use Drupal\Core\Database\Connection;
use Drupal\Core\Site\Settings;
use Drupal\Tests\UnitTestCase;
/**
* @coversDefaultClass \Drupal\Core\Cache\DatabaseBackendFactory
* @group Cache
*/
class DatabaseBackendFactoryTest extends UnitTestCase {
/**
* @covers ::__construct
* @covers ::get
* @dataProvider getProvider
*/
public function testGet(array $settings, $expected_max_rows_foo, $expected_max_rows_bar) {
$database_backend_factory = new DatabaseBackendFactory(
$this->prophesize(Connection::class)->reveal(),
$this->prophesize(CacheTagsChecksumInterface::class)->reveal(),
new Settings($settings)
);
$this->assertSame($expected_max_rows_foo, $database_backend_factory->get('foo')->getMaxRows());
$this->assertSame($expected_max_rows_bar, $database_backend_factory->get('bar')->getMaxRows());
}
public function getProvider() {
return [
'default' => [
[],
DatabaseBackend::DEFAULT_MAX_ROWS,
DatabaseBackend::DEFAULT_MAX_ROWS,
],
'default overridden' => [
[
'database_cache_max_rows' => [
'default' => 99,
],
],
99,
99,
],
'default + foo bin overridden' => [
[
'database_cache_max_rows' => [
'bins' => [
'foo' => 13,
],
],
],
13,
DatabaseBackend::DEFAULT_MAX_ROWS,
],
'default + bar bin overridden' => [
[
'database_cache_max_rows' => [
'bins' => [
'bar' => 13,
],
],
],
DatabaseBackend::DEFAULT_MAX_ROWS,
13,
],
'default overridden + bar bin overridden' => [
[
'database_cache_max_rows' => [
'default' => 99,
'bins' => [
'bar' => 13,
],
],
],
99,
13,
],
'default + both bins overridden' => [
[
'database_cache_max_rows' => [
'bins' => [
'foo' => 13,
'bar' => 31,
],
],
],
13,
31,
],
'default overridden + both bins overridden' => [
[
'database_cache_max_rows' => [
'default' => 99,
'bins' => [
'foo' => 13,
'bar' => 31,
],
],
],
13,
31,
],
];
}
}
@@ -6,12 +6,13 @@ use Drupal\Core\Config\ConfigCollectionInfo;
use Drupal\Core\Config\ConfigCrudEvent;
use Drupal\Core\Config\ConfigFactoryOverrideBase;
use Drupal\Core\Config\ConfigRenameEvent;
use Drupal\Tests\UnitTestCase;
/**
* @coversDefaultClass \Drupal\Core\Config\ConfigFactoryOverrideBase
* @group config
*/
class ConfigFactoryOverrideBaseTest extends \PHPUnit_Framework_TestCase {
class ConfigFactoryOverrideBaseTest extends UnitTestCase {
/**
* @dataProvider providerTestFilterNestedArray
@@ -553,7 +553,7 @@ class ConfigEntityStorageTest extends UnitTestCase {
$bar_config_object->getName()->willReturn('foo');
$this->configFactory->listAll('the_provider.the_config_prefix.')
->willReturn(['the_provider.the_config_prefix.foo' , 'the_provider.the_config_prefix.bar']);
->willReturn(['the_provider.the_config_prefix.foo', 'the_provider.the_config_prefix.bar']);
$this->configFactory->loadMultiple(['the_provider.the_config_prefix.foo', 'the_provider.the_config_prefix.bar'])
->willReturn([$foo_config_object->reveal(), $bar_config_object->reveal()]);
@@ -70,9 +70,11 @@ class ControllerResolverTest extends UnitTestCase {
*
* @see \Drupal\Core\Controller\ControllerResolver::getArguments()
* @see \Drupal\Core\Controller\ControllerResolver::doGetArguments()
*
* @group legacy
*/
public function testGetArguments() {
$controller = function(EntityInterface $entity, $user, RouteMatchInterface $route_match, ServerRequestInterface $psr_7) {
$controller = function (EntityInterface $entity, $user, RouteMatchInterface $route_match, ServerRequestInterface $psr_7) {
};
$mock_entity = $this->getMockBuilder('Drupal\Core\Entity\Entity')
->disableOriginalConstructor()
@@ -220,6 +222,8 @@ class ControllerResolverTest extends UnitTestCase {
*
* @covers ::getArguments
* @covers ::doGetArguments
*
* @group legacy
*/
public function testGetArgumentsWithRouteMatchAndRequest() {
$request = Request::create('/test');
@@ -233,6 +237,8 @@ class ControllerResolverTest extends UnitTestCase {
*
* @covers ::getArguments
* @covers ::doGetArguments
*
* @group legacy
*/
public function testGetArgumentsWithRouteMatchAndPsr7Request() {
$request = Request::create('/test');
@@ -44,7 +44,7 @@ class ConditionTest extends UnitTestCase {
$query_placeholder = $this->prophesize(PlaceholderInterface::class);
$counter = 0;
$query_placeholder->nextPlaceholder()->will(function() use (&$counter) {
$query_placeholder->nextPlaceholder()->will(function () use (&$counter) {
return $counter++;
});
$query_placeholder->uniqueIdentifier()->willReturn(4);
@@ -85,7 +85,7 @@ class ConditionTest extends UnitTestCase {
$query_placeholder = $this->prophesize(PlaceholderInterface::class);
$counter = 0;
$query_placeholder->nextPlaceholder()->will(function() use (&$counter) {
$query_placeholder->nextPlaceholder()->will(function () use (&$counter) {
return $counter++;
});
$query_placeholder->uniqueIdentifier()->willReturn(4);
@@ -153,7 +153,7 @@ class ConditionTest extends UnitTestCase {
$query_placeholder = $this->prophesize(PlaceholderInterface::class);
$counter = 0;
$query_placeholder->nextPlaceholder()->will(function() use (&$counter) {
$query_placeholder->nextPlaceholder()->will(function () use (&$counter) {
return $counter++;
});
$query_placeholder->uniqueIdentifier()->willReturn(4);
@@ -94,7 +94,7 @@ class UrlConversionTest extends UnitTestCase {
*
* @dataProvider providerGetConnectionInfoAsUrl
*/
public function testGetConnectionInfoAsUrl(Array $info, $expected_url) {
public function testGetConnectionInfoAsUrl(array $info, $expected_url) {
Database::addConnectionInfo('default', 'default', $info);
$url = Database::getConnectionInfoAsUrl();
@@ -29,78 +29,102 @@ class DateHelperTest extends UnitTestCase {
public function providerTestWeekDaysOrdered() {
$data = [];
$data[] = [0, [
0 => 'Sunday',
1 => 'Monday',
2 => 'Tuesday',
3 => 'Wednesday',
4 => 'Thursday',
5 => 'Friday',
6 => 'Saturday',
]];
$data[] = [1, [
1 => 'Monday',
2 => 'Tuesday',
3 => 'Wednesday',
4 => 'Thursday',
5 => 'Friday',
6 => 'Saturday',
0 => 'Sunday',
]];
$data[] = [2, [
2 => 'Tuesday',
3 => 'Wednesday',
4 => 'Thursday',
5 => 'Friday',
6 => 'Saturday',
0 => 'Sunday',
1 => 'Monday',
]];
$data[] = [3, [
3 => 'Wednesday',
4 => 'Thursday',
5 => 'Friday',
6 => 'Saturday',
0 => 'Sunday',
1 => 'Monday',
2 => 'Tuesday',
]];
$data[] = [4, [
4 => 'Thursday',
5 => 'Friday',
6 => 'Saturday',
0 => 'Sunday',
1 => 'Monday',
2 => 'Tuesday',
3 => 'Wednesday',
]];
$data[] = [5, [
5 => 'Friday',
6 => 'Saturday',
0 => 'Sunday',
1 => 'Monday',
2 => 'Tuesday',
3 => 'Wednesday',
4 => 'Thursday',
]];
$data[] = [6, [
6 => 'Saturday',
0 => 'Sunday',
1 => 'Monday',
2 => 'Tuesday',
3 => 'Wednesday',
4 => 'Thursday',
5 => 'Friday',
]];
$data[] = [7, [
0 => 'Sunday',
1 => 'Monday',
2 => 'Tuesday',
3 => 'Wednesday',
4 => 'Thursday',
5 => 'Friday',
6 => 'Saturday',
]];
$data[] = [
0,
[
0 => 'Sunday',
1 => 'Monday',
2 => 'Tuesday',
3 => 'Wednesday',
4 => 'Thursday',
5 => 'Friday',
6 => 'Saturday',
],
];
$data[] = [
1,
[
1 => 'Monday',
2 => 'Tuesday',
3 => 'Wednesday',
4 => 'Thursday',
5 => 'Friday',
6 => 'Saturday',
0 => 'Sunday',
]
];
$data[] = [
2,
[
2 => 'Tuesday',
3 => 'Wednesday',
4 => 'Thursday',
5 => 'Friday',
6 => 'Saturday',
0 => 'Sunday',
1 => 'Monday',
],
];
$data[] = [
3,
[
3 => 'Wednesday',
4 => 'Thursday',
5 => 'Friday',
6 => 'Saturday',
0 => 'Sunday',
1 => 'Monday',
2 => 'Tuesday',
],
];
$data[] = [
4,
[
4 => 'Thursday',
5 => 'Friday',
6 => 'Saturday',
0 => 'Sunday',
1 => 'Monday',
2 => 'Tuesday',
3 => 'Wednesday',
],
];
$data[] = [
5,
[
5 => 'Friday',
6 => 'Saturday',
0 => 'Sunday',
1 => 'Monday',
2 => 'Tuesday',
3 => 'Wednesday',
4 => 'Thursday',
],
];
$data[] = [
6,
[
6 => 'Saturday',
0 => 'Sunday',
1 => 'Monday',
2 => 'Tuesday',
3 => 'Wednesday',
4 => 'Thursday',
5 => 'Friday',
],
];
$data[] = [
7,
[
0 => 'Sunday',
1 => 'Monday',
2 => 'Tuesday',
3 => 'Wednesday',
4 => 'Thursday',
5 => 'Friday',
6 => 'Saturday',
],
];
return $data;
}
@@ -156,4 +156,48 @@ class DrupalDateTimeTest extends UnitTestCase {
];
}
/**
* Tests that object methods are chainable.
*
* @covers ::__call
*/
public function testChainable() {
$tz = new \DateTimeZone(date_default_timezone_get());
$date = new DrupalDateTime('now', $tz, ['langcode' => 'en']);
$date->setTimestamp(12345678);
$rendered = $date->render();
$this->assertEquals('1970-05-24 07:21:18 Australia/Sydney', $rendered);
$date->setTimestamp(23456789);
$rendered = $date->setTimezone(new \DateTimeZone('America/New_York'))->render();
$this->assertEquals('1970-09-29 07:46:29 America/New_York', $rendered);
}
/**
* Tests that non-chainable methods work.
*
* @covers ::__call
*/
public function testChainableNonChainable() {
$tz = new \DateTimeZone(date_default_timezone_get());
$datetime1 = new DrupalDateTime('2009-10-11 12:00:00', $tz, ['langcode' => 'en']);
$datetime2 = new DrupalDateTime('2009-10-13 12:00:00', $tz, ['langcode' => 'en']);
$interval = $datetime1->diff($datetime2);
$this->assertInstanceOf(\DateInterval::class, $interval);
$this->assertEquals('+2 days', $interval->format('%R%a days'));
}
/**
* Tests that chained calls to non-existent functions throw an exception.
*
* @covers ::__call
*/
public function testChainableNonCallable() {
$this->setExpectedException(\BadMethodCallException::class, 'Call to undefined method Drupal\Core\Datetime\DrupalDateTime::nonexistent()');
$tz = new \DateTimeZone(date_default_timezone_get());
$date = new DrupalDateTime('now', $tz, ['langcode' => 'en']);
$date->setTimezone(new \DateTimeZone('America/New_York'))->nonexistent();
}
}
@@ -4,6 +4,7 @@ namespace Drupal\Tests\Core\DependencyInjection\Compiler;
use Drupal\Core\DependencyInjection\Compiler\AuthenticationProviderPass;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\Serializer\Serializer;
@@ -11,7 +12,7 @@ use Symfony\Component\Serializer\Serializer;
* @coversDefaultClass \Drupal\Core\DependencyInjection\Compiler\AuthenticationProviderPass
* @group DependencyInjection
*/
class AuthenticationProviderPassTest extends \PHPUnit_Framework_TestCase {
class AuthenticationProviderPassTest extends UnitTestCase {
/**
* @covers ::process
@@ -60,6 +60,25 @@ class TaggedHandlersPassTest extends UnitTestCase {
$handler_pass->process($container);
}
/**
* Tests a required consumer with no handlers.
*
* @covers ::process
* @covers ::processServiceIdCollectorPass
*/
public function testIdCollectorProcessRequiredHandlers() {
$this->setExpectedException(LogicException::class, "At least one service tagged with 'consumer_id' is required.");
$container = $this->buildContainer();
$container
->register('consumer_id', __NAMESPACE__ . '\ValidConsumer')
->addTag('service_id_collector', [
'required' => TRUE,
]);
$handler_pass = new TaggedHandlersPass();
$handler_pass->process($container);
}
/**
* Tests consumer with missing interface in non-production environment.
*
@@ -104,6 +123,32 @@ class TaggedHandlersPassTest extends UnitTestCase {
$this->assertCount(2, $method_calls);
}
/**
* Tests one consumer and two handlers with service ID collection.
*
* @covers ::process
*/
public function testserviceIdProcess() {
$container = $this->buildContainer();
$container
->register('consumer_id', __NAMESPACE__ . '\ValidConsumer')
->addTag('service_id_collector');
$container
->register('handler1', __NAMESPACE__ . '\ValidHandler')
->addTag('consumer_id');
$container
->register('handler2', __NAMESPACE__ . '\ValidHandler')
->addTag('consumer_id');
$handler_pass = new TaggedHandlersPass();
$handler_pass->process($container);
$arguments = $container->getDefinition('consumer_id')->getArguments();
$this->assertCount(1, $arguments);
$this->assertCount(2, $arguments[0]);
}
/**
* Tests handler priority sorting.
*
@@ -135,6 +180,39 @@ class TaggedHandlersPassTest extends UnitTestCase {
$this->assertEquals(0, $method_calls[1][1][1]);
}
/**
* Tests handler priority sorting for service ID collection.
*
* @covers ::process
*/
public function testserviceIdProcessPriority() {
$container = $this->buildContainer();
$container
->register('consumer_id', __NAMESPACE__ . '\ValidConsumer')
->addTag('service_id_collector');
$container
->register('handler1', __NAMESPACE__ . '\ValidHandler')
->addTag('consumer_id');
$container
->register('handler2', __NAMESPACE__ . '\ValidHandler')
->addTag('consumer_id', [
'priority' => 20,
]);
$container
->register('handler3', __NAMESPACE__ . '\ValidHandler')
->addTag('consumer_id', [
'priority' => 10,
]);
$handler_pass = new TaggedHandlersPass();
$handler_pass->process($container);
$arguments = $container->getDefinition('consumer_id')->getArguments();
$this->assertCount(1, $arguments);
$this->assertSame(['handler2', 'handler3', 'handler1'], $arguments[0]);
}
/**
* Tests consumer method without priority parameter.
*
@@ -44,6 +44,29 @@ class DependencySerializationTest extends UnitTestCase {
$this->assertEmpty($dependencySerialization->getServiceIds());
}
/**
* @covers ::__sleep
* @covers ::__wakeup
*/
public function testSerializationWithMissingService() {
// Create a pseudo service and dependency injected object.
$service = new \stdClass();
$service->_serviceId = 'test_service_not_existing';
$container = new Container();
$container->set('test_service', $service);
$container->set('service_container', $container);
\Drupal::setContainer($container);
$dependencySerialization = new DependencySerializationTestDummy($service);
$dependencySerialization->setContainer($container);
$string = serialize($dependencySerialization);
/** @var \Drupal\Tests\Core\DependencyInjection\DependencySerializationTestDummy $dependencySerialization */
$dependencySerialization = unserialize($string);
$this->assertSame($container, $dependencySerialization->container);
}
}
/**
@@ -5,13 +5,14 @@ namespace Drupal\Tests\Core\DependencyInjection;
use Drupal\Component\FileCache\FileCacheFactory;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\DependencyInjection\YamlFileLoader;
use Drupal\Tests\UnitTestCase;
use org\bovigo\vfs\vfsStream;
/**
* @coversDefaultClass \Drupal\Core\DependencyInjection\YamlFileLoader
* @group DependencyInjection
*/
class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase {
class YamlFileLoaderTest extends UnitTestCase {
/**
* {@inheritdoc}
@@ -52,8 +52,7 @@ class DiscoverServiceProvidersTest extends UnitTestCase {
'app' => [
'core' => 'core/core.services.yml',
],
'site' => [
],
'site' => [],
];
$this->assertAttributeSame($expect, 'serviceYamls', $kernel);
}
@@ -177,12 +177,14 @@ $sites['8888.www.example.org'] = 'example';
EOD;
// Create the expected directory structure.
vfsStream::create(['sites' => [
'sites.php' => $sites_php,
'example' => [
'settings.php' => 'test'
]
]]);
vfsStream::create([
'sites' => [
'sites.php' => $sites_php,
'example' => [
'settings.php' => 'test',
],
],
]);
$request = new Request();
$request->server->set('SERVER_NAME', 'www.example.org');
@@ -241,6 +243,7 @@ EOD;
namespace {
if (!function_exists('drupal_valid_test_ua')) {
function drupal_valid_test_ua($new_prefix = NULL) {
return FALSE;
@@ -194,6 +194,52 @@ class BaseFieldDefinitionTest extends UnitTestCase {
$this->assertEquals([], $definition->getDefaultValue($entity));
}
/**
* Tests field initial value.
*
* @covers ::getInitialValue
* @covers ::setInitialValue
*/
public function testFieldInitialValue() {
$definition = BaseFieldDefinition::create($this->fieldType);
$default_value = [
'value' => $this->randomMachineName(),
];
$expected_default_value = [$default_value];
$definition->setInitialValue($default_value);
$entity = $this->getMockBuilder('Drupal\Core\Entity\ContentEntityBase')
->disableOriginalConstructor()
->getMock();
// Set the field item list class to be used to avoid requiring the typed
// data manager to retrieve it.
$definition->setClass('Drupal\Core\Field\FieldItemList');
$this->assertEquals($expected_default_value, $definition->getInitialValue($entity));
$data_definition = $this->getMockBuilder('Drupal\Core\TypedData\DataDefinition')
->disableOriginalConstructor()
->getMock();
$data_definition->expects($this->any())
->method('getClass')
->will($this->returnValue('Drupal\Core\Field\FieldItemBase'));
$definition->setItemDefinition($data_definition);
// Set default value only with a literal.
$definition->setInitialValue($default_value['value']);
$this->assertEquals($expected_default_value, $definition->getInitialValue($entity));
// Set default value with an indexed array.
$definition->setInitialValue($expected_default_value);
$this->assertEquals($expected_default_value, $definition->getInitialValue($entity));
// Set default value with an empty array.
$definition->setInitialValue([]);
$this->assertEquals([], $definition->getInitialValue($entity));
// Set default value with NULL.
$definition->setInitialValue(NULL);
$this->assertEquals([], $definition->getInitialValue($entity));
}
/**
* Tests field translatable methods.
*
@@ -10,6 +10,7 @@ use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\TypedData\TypedDataManagerInterface;
use Drupal\Tests\UnitTestCase;
use Drupal\Core\Language\Language;
use Symfony\Component\Validator\Validator\ValidatorInterface;
/**
* @coversDefaultClass \Drupal\Core\Entity\ContentEntityBase
@@ -327,7 +328,7 @@ class ContentEntityBaseUnitTest extends UnitTestCase {
* @covers ::validate
*/
public function testValidate() {
$validator = $this->getMock('\Symfony\Component\Validator\ValidatorInterface');
$validator = $this->getMock(ValidatorInterface::class);
/** @var \Symfony\Component\Validator\ConstraintViolationList|\PHPUnit_Framework_MockObject_MockObject $empty_violation_list */
$empty_violation_list = $this->getMockBuilder('\Symfony\Component\Validator\ConstraintViolationList')
->setMethods(NULL)
@@ -360,7 +361,7 @@ class ContentEntityBaseUnitTest extends UnitTestCase {
* @covers ::preSave
*/
public function testRequiredValidation() {
$validator = $this->getMock('\Symfony\Component\Validator\ValidatorInterface');
$validator = $this->getMock(ValidatorInterface::class);
/** @var \Symfony\Component\Validator\ConstraintViolationList|\PHPUnit_Framework_MockObject_MockObject $empty_violation_list */
$empty_violation_list = $this->getMockBuilder('\Symfony\Component\Validator\ConstraintViolationList')
->setMethods(NULL)
@@ -542,6 +542,7 @@ class EntityFieldManagerTest extends UnitTestCase {
$this->entityType->getKeys()->willReturn($entity_keys + ['default_langcode' => 'default_langcode']);
$this->entityType->entityClassImplements(FieldableEntityInterface::class)->willReturn(TRUE);
$this->entityType->isTranslatable()->willReturn(FALSE);
$this->entityType->isRevisionable()->willReturn(FALSE);
$this->entityType->getProvider()->willReturn('the_provider');
$this->entityType->id()->willReturn('the_entity_id');
@@ -651,6 +652,7 @@ class EntityFieldManagerTest extends UnitTestCase {
$entity_type->getKeys()->willReturn(['default_langcode' => 'default_langcode']);
$entity_type->entityClassImplements(FieldableEntityInterface::class)->willReturn(TRUE);
$entity_type->isTranslatable()->shouldBeCalled();
$entity_type->isRevisionable()->shouldBeCalled();
$entity_type->getProvider()->shouldBeCalled();
$non_content_entity_type->entityClassImplements(FieldableEntityInterface::class)->willReturn(FALSE);
@@ -752,6 +754,7 @@ class EntityFieldManagerTest extends UnitTestCase {
$entity_type->getKeys()->willReturn(['default_langcode' => 'default_langcode'])->shouldBeCalled();
$entity_type->entityClassImplements(FieldableEntityInterface::class)->willReturn(TRUE)->shouldBeCalled();
$entity_type->isTranslatable()->shouldBeCalled();
$entity_type->isRevisionable()->shouldBeCalled();
$entity_type->getProvider()->shouldBeCalled();
$override_entity_type->entityClassImplements(FieldableEntityInterface::class)->willReturn(FALSE)->shouldBeCalled();
@@ -73,30 +73,35 @@ class EntityFormTest extends UnitTestCase {
public function providerTestFormIds() {
return [
['node_article_form', [
'entity_type' => 'node',
'bundle' => 'article',
'operation' => 'default',
]],
'entity_type' => 'node',
'bundle' => 'article',
'operation' => 'default',
],
],
['node_article_delete_form', [
'entity_type' => 'node',
'bundle' => 'article',
'operation' => 'delete',
]],
'entity_type' => 'node',
'bundle' => 'article',
'operation' => 'delete',
],
],
['user_user_form', [
'entity_type' => 'user',
'bundle' => 'user',
'operation' => 'default',
]],
'entity_type' => 'user',
'bundle' => 'user',
'operation' => 'default',
],
],
['user_form', [
'entity_type' => 'user',
'bundle' => '',
'operation' => 'default',
]],
'entity_type' => 'user',
'bundle' => '',
'operation' => 'default',
],
],
['user_delete_form', [
'entity_type' => 'user',
'bundle' => '',
'operation' => 'delete',
]],
'entity_type' => 'user',
'bundle' => '',
'operation' => 'delete',
],
],
];
}
@@ -100,7 +100,7 @@ class EntityTypeBundleInfoTest extends UnitTestCase {
$container = $this->prophesize(ContainerInterface::class);
$container->get('cache_tags.invalidator')->willReturn($this->cacheTagsInvalidator->reveal());
//$container->get('typed_data_manager')->willReturn($this->typedDataManager->reveal());
// $container->get('typed_data_manager')->willReturn($this->typedDataManager->reveal());
\Drupal::setContainer($container->reveal());
$this->entityTypeBundleInfo = new EntityTypeBundleInfo($this->entityTypeManager->reveal(), $this->languageManager->reveal(), $this->moduleHandler->reveal(), $this->typedDataManager->reveal(), $this->cacheBackend->reveal());
@@ -136,7 +136,9 @@ class EntityTypeBundleInfoTest extends UnitTestCase {
elseif (!$exception_on_invalid) {
return NULL;
}
else throw new PluginNotFoundException($entity_type_id);
else {
throw new PluginNotFoundException($entity_type_id);
}
});
$this->entityTypeManager->getDefinitions()->willReturn($definitions);
@@ -194,15 +196,13 @@ class EntityTypeBundleInfoTest extends UnitTestCase {
public function providerTestGetBundleInfo() {
return [
['apple', [
'apple' => [
'label' => 'Apple',
'apple' => ['label' => 'Apple'],
],
]],
],
['banana', [
'banana' => [
'label' => 'Banana',
'banana' => ['label' => 'Banana'],
],
]],
],
['pear', []],
];
}

Some files were not shown because too many files have changed in this diff Show More