updated core from 8.4 to 8.5 : bug with login_destination
This commit is contained in:
@@ -345,12 +345,12 @@ abstract class BrowserTestBase extends TestCase {
|
||||
* When provided default Mink driver class can't be instantiated.
|
||||
*/
|
||||
protected function getDefaultDriverInstance() {
|
||||
// Get default driver params from environment if availables.
|
||||
if ($arg_json = getenv('MINK_DRIVER_ARGS')) {
|
||||
// Get default driver params from environment if available.
|
||||
if ($arg_json = $this->getMinkDriverArgs()) {
|
||||
$this->minkDefaultDriverArgs = json_decode($arg_json, TRUE);
|
||||
}
|
||||
|
||||
// Get and check default driver class from environment if availables.
|
||||
// Get and check default driver class from environment if available.
|
||||
if ($minkDriverClass = getenv('MINK_DRIVER_CLASS')) {
|
||||
if (class_exists($minkDriverClass)) {
|
||||
$this->minkDefaultDriverClass = $minkDriverClass;
|
||||
@@ -395,6 +395,18 @@ abstract class BrowserTestBase extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Mink driver args from an environment variable, if it is set. Can
|
||||
* be overridden in a derived class so it is possible to use a different
|
||||
* value for a subset of tests, e.g. the JavaScript tests.
|
||||
*
|
||||
* @return string|false
|
||||
* The JSON-encoded argument string. False if it is not set.
|
||||
*/
|
||||
protected function getMinkDriverArgs() {
|
||||
return getenv('MINK_DRIVER_ARGS');
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a Guzzle middleware handler to log every response received.
|
||||
*
|
||||
@@ -485,6 +497,11 @@ abstract class BrowserTestBase extends TestCase {
|
||||
if ($disable_gc) {
|
||||
gc_enable();
|
||||
}
|
||||
|
||||
// Ensure that the test is not marked as risky because of no assertions. In
|
||||
// PHPUnit 6 tests that only make assertions using $this->assertSession()
|
||||
// can be marked as risky.
|
||||
$this->addToAssertionCount(1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\Component\Annotation;
|
||||
|
||||
use Drupal\Component\Annotation\Plugin\Discovery\AnnotatedClassDiscovery;
|
||||
use Drupal\Component\FileCache\FileCacheFactory;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Component\Annotation\Plugin\Discovery\AnnotatedClassDiscovery
|
||||
* @group Annotation
|
||||
*/
|
||||
class AnnotatedClassDiscoveryCachedTest extends TestCase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
// Ensure FileCacheFactory::DISABLE_CACHE is *not* set, since we're testing
|
||||
// integration with the file cache.
|
||||
FileCacheFactory::setConfiguration([]);
|
||||
// Ensure that FileCacheFactory has a prefix.
|
||||
FileCacheFactory::setPrefix('prefix');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that getDefinitions() retrieves the file cache correctly.
|
||||
*
|
||||
* @covers ::getDefinitions
|
||||
*/
|
||||
public function testGetDefinitions() {
|
||||
// Path to the classes which we'll discover and parse annotation.
|
||||
$discovery_path = __DIR__ . '/Fixtures';
|
||||
// File path that should be discovered within that directory.
|
||||
$file_path = $discovery_path . '/PluginNamespace/DiscoveryTest1.php';
|
||||
|
||||
$discovery = new AnnotatedClassDiscovery(['com\example' => [$discovery_path]]);
|
||||
$this->assertEquals([
|
||||
'discovery_test_1' => [
|
||||
'id' => 'discovery_test_1',
|
||||
'class' => 'com\example\PluginNamespace\DiscoveryTest1',
|
||||
],
|
||||
], $discovery->getDefinitions());
|
||||
|
||||
// Gain access to the file cache so we can change it.
|
||||
$ref_file_cache = new \ReflectionProperty($discovery, 'fileCache');
|
||||
$ref_file_cache->setAccessible(TRUE);
|
||||
/* @var $file_cache \Drupal\Component\FileCache\FileCacheInterface */
|
||||
$file_cache = $ref_file_cache->getValue($discovery);
|
||||
// The file cache is keyed by the file path, and we'll add some known
|
||||
// content to test against.
|
||||
$file_cache->set($file_path, [
|
||||
'id' => 'wrong_id',
|
||||
'content' => serialize(['an' => 'array']),
|
||||
]);
|
||||
|
||||
// Now perform the same query and check for the cached results.
|
||||
$this->assertEquals([
|
||||
'wrong_id' => [
|
||||
'an' => 'array',
|
||||
],
|
||||
], $discovery->getDefinitions());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\Component\Annotation;
|
||||
|
||||
use Drupal\Component\Annotation\Plugin;
|
||||
use Drupal\Component\Annotation\Plugin\Discovery\AnnotatedClassDiscovery;
|
||||
use Drupal\Component\FileCache\FileCacheFactory;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Component\Annotation\Plugin\Discovery\AnnotatedClassDiscovery
|
||||
* @group Annotation
|
||||
*/
|
||||
class AnnotatedClassDiscoveryTest extends TestCase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
// Ensure the file cache is disabled.
|
||||
FileCacheFactory::setConfiguration([FileCacheFactory::DISABLE_CACHE => TRUE]);
|
||||
// Ensure that FileCacheFactory has a prefix.
|
||||
FileCacheFactory::setPrefix('prefix');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::__construct
|
||||
* @covers ::getPluginNamespaces
|
||||
*/
|
||||
public function testGetPluginNamespaces() {
|
||||
$discovery = new AnnotatedClassDiscovery(['com/example' => [__DIR__]]);
|
||||
|
||||
$reflection = new \ReflectionMethod($discovery, 'getPluginNamespaces');
|
||||
$reflection->setAccessible(TRUE);
|
||||
|
||||
$result = $reflection->invoke($discovery);
|
||||
$this->assertEquals(['com/example' => [__DIR__]], $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getDefinitions
|
||||
* @covers ::prepareAnnotationDefinition
|
||||
* @covers ::getAnnotationReader
|
||||
*/
|
||||
public function testGetDefinitions() {
|
||||
$discovery = new AnnotatedClassDiscovery(['com\example' => [__DIR__ . '/Fixtures']]);
|
||||
$this->assertEquals([
|
||||
'discovery_test_1' => [
|
||||
'id' => 'discovery_test_1',
|
||||
'class' => 'com\example\PluginNamespace\DiscoveryTest1',
|
||||
],
|
||||
], $discovery->getDefinitions());
|
||||
|
||||
$custom_annotation_discovery = new AnnotatedClassDiscovery(['com\example' => [__DIR__ . '/Fixtures']], CustomPlugin::class, ['Drupal\Tests\Component\Annotation']);
|
||||
$this->assertEquals([
|
||||
'discovery_test_1' => [
|
||||
'id' => 'discovery_test_1',
|
||||
'class' => 'com\example\PluginNamespace\DiscoveryTest1',
|
||||
'title' => 'Discovery test plugin',
|
||||
],
|
||||
], $custom_annotation_discovery->getDefinitions());
|
||||
|
||||
$empty_discovery = new AnnotatedClassDiscovery(['com\example' => [__DIR__ . '/Fixtures']], CustomPlugin2::class, ['Drupal\Tests\Component\Annotation']);
|
||||
$this->assertEquals([], $empty_discovery->getDefinitions());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom plugin annotation.
|
||||
*
|
||||
* @Annotation
|
||||
*/
|
||||
class CustomPlugin extends Plugin {
|
||||
|
||||
/**
|
||||
* The plugin ID.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* The plugin title.
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
* @ingroup plugin_translatable
|
||||
*/
|
||||
public $title = '';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom plugin annotation.
|
||||
*
|
||||
* @Annotation
|
||||
*/
|
||||
class CustomPlugin2 extends Plugin {}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\Component\Annotation;
|
||||
|
||||
use Drupal\Component\Annotation\AnnotationBase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Component\Annotation\AnnotationBase
|
||||
* @group Annotation
|
||||
*/
|
||||
class AnnotationBaseTest extends TestCase {
|
||||
|
||||
/**
|
||||
* @covers ::getProvider
|
||||
* @covers ::setProvider
|
||||
*/
|
||||
public function testSetProvider() {
|
||||
$plugin = new AnnotationBaseStub();
|
||||
$plugin->setProvider('example');
|
||||
$this->assertEquals('example', $plugin->getProvider());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getId
|
||||
*/
|
||||
public function testGetId() {
|
||||
$plugin = new AnnotationBaseStub();
|
||||
// Doctrine sets the public prop directly.
|
||||
$plugin->id = 'example';
|
||||
$this->assertEquals('example', $plugin->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getClass
|
||||
* @covers ::setClass
|
||||
*/
|
||||
public function testSetClass() {
|
||||
$plugin = new AnnotationBaseStub();
|
||||
$plugin->setClass('example');
|
||||
$this->assertEquals('example', $plugin->getClass());
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
class AnnotationBaseStub extends AnnotationBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get() {}
|
||||
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace com\example\PluginNamespace;
|
||||
|
||||
/**
|
||||
* Provides a custom test plugin.
|
||||
*
|
||||
* @Plugin(
|
||||
* id = "discovery_test_1"
|
||||
* )
|
||||
* @CustomPlugin(
|
||||
* id = "discovery_test_1",
|
||||
* title = "Discovery test plugin"
|
||||
* )
|
||||
*/
|
||||
class DiscoveryTest1 {}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
# This should not be loaded by our annotated class discovery.
|
||||
id:discovery_test_2
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\Component\Annotation;
|
||||
|
||||
use Drupal\Component\Annotation\Reflection\MockFileFinder;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Component\Annotation\Reflection\MockFileFinder
|
||||
* @group Annotation
|
||||
*/
|
||||
class MockFileFinderTest extends TestCase {
|
||||
|
||||
/**
|
||||
* @covers ::create
|
||||
* @covers ::findFile
|
||||
*/
|
||||
public function testFindFile() {
|
||||
$tmp = MockFileFinder::create('testfilename.txt');
|
||||
$this->assertEquals('testfilename.txt', $tmp->findFile('n/a'));
|
||||
$this->assertEquals('testfilename.txt', $tmp->findFile('someclass'));
|
||||
}
|
||||
|
||||
}
|
||||
+8
@@ -35,6 +35,9 @@ class AnnotationBridgeDecoratorTest extends TestCase {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
class TestAnnotation extends Plugin {
|
||||
|
||||
/**
|
||||
@@ -45,12 +48,17 @@ class TestAnnotation extends Plugin {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
class ObjectDefinition extends PluginDefinition {
|
||||
|
||||
/**
|
||||
* ObjectDefinition constructor.
|
||||
*
|
||||
* @param array $definition
|
||||
* An array of definition values.
|
||||
*/
|
||||
public function __construct(array $definition) {
|
||||
foreach ($definition as $property => $value) {
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\Component\Annotation;
|
||||
|
||||
use Drupal\Component\Annotation\PluginID;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Component\Annotation\PluginId
|
||||
* @group Annotation
|
||||
*/
|
||||
class PluginIdTest extends TestCase {
|
||||
|
||||
/**
|
||||
* @covers ::get
|
||||
*/
|
||||
public function testGet() {
|
||||
// Assert plugin starts empty regardless of constructor.
|
||||
$plugin = new PluginID([
|
||||
'foo' => 'bar',
|
||||
'biz' => [
|
||||
'baz' => 'boom',
|
||||
],
|
||||
'nestedAnnotation' => new PluginID([
|
||||
'foo' => 'bar',
|
||||
]),
|
||||
'value' => 'biz',
|
||||
]);
|
||||
$this->assertEquals([
|
||||
'id' => NULL,
|
||||
'class' => NULL,
|
||||
'provider' => NULL,
|
||||
], $plugin->get());
|
||||
|
||||
// Set values and ensure we can retrieve them.
|
||||
$plugin->value = 'foo';
|
||||
$plugin->setClass('bar');
|
||||
$plugin->setProvider('baz');
|
||||
$this->assertEquals([
|
||||
'id' => 'foo',
|
||||
'class' => 'bar',
|
||||
'provider' => 'baz',
|
||||
], $plugin->get());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getId
|
||||
*/
|
||||
public function testGetId() {
|
||||
$plugin = new PluginID([]);
|
||||
$plugin->value = 'example';
|
||||
$this->assertEquals('example', $plugin->getId());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\Component\Annotation;
|
||||
|
||||
use Drupal\Component\Annotation\Plugin;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Component\Annotation\Plugin
|
||||
* @group Annotation
|
||||
*/
|
||||
class PluginTest extends TestCase {
|
||||
|
||||
/**
|
||||
* @covers ::__construct
|
||||
* @covers ::parse
|
||||
* @covers ::get
|
||||
*/
|
||||
public function testGet() {
|
||||
// Assert all values are accepted through constructor and default value is
|
||||
// used for non existent but defined property.
|
||||
$plugin = new PluginStub([
|
||||
'foo' => 'bar',
|
||||
'biz' => [
|
||||
'baz' => 'boom',
|
||||
],
|
||||
'nestedAnnotation' => new Plugin([
|
||||
'foo' => 'bar',
|
||||
]),
|
||||
]);
|
||||
$this->assertEquals([
|
||||
// This property wasn't in our definition but is defined as a property on
|
||||
// our plugin class.
|
||||
'defaultProperty' => 'testvalue',
|
||||
'foo' => 'bar',
|
||||
'biz' => [
|
||||
'baz' => 'boom',
|
||||
],
|
||||
'nestedAnnotation' => [
|
||||
'foo' => 'bar',
|
||||
],
|
||||
], $plugin->get());
|
||||
|
||||
// Without default properties, we get a completely empty plugin definition.
|
||||
$plugin = new Plugin([]);
|
||||
$this->assertEquals([], $plugin->get());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getProvider
|
||||
*/
|
||||
public function testGetProvider() {
|
||||
$plugin = new Plugin(['provider' => 'example']);
|
||||
$this->assertEquals('example', $plugin->getProvider());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::setProvider
|
||||
*/
|
||||
public function testSetProvider() {
|
||||
$plugin = new Plugin([]);
|
||||
$plugin->setProvider('example');
|
||||
$this->assertEquals('example', $plugin->getProvider());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getId
|
||||
*/
|
||||
public function testGetId() {
|
||||
$plugin = new Plugin(['id' => 'example']);
|
||||
$this->assertEquals('example', $plugin->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getClass
|
||||
*/
|
||||
public function testGetClass() {
|
||||
$plugin = new Plugin(['class' => 'example']);
|
||||
$this->assertEquals('example', $plugin->getClass());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::setClass
|
||||
*/
|
||||
public function testSetClass() {
|
||||
$plugin = new Plugin([]);
|
||||
$plugin->setClass('example');
|
||||
$this->assertEquals('example', $plugin->getClass());
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
class PluginStub extends Plugin {
|
||||
protected $defaultProperty = 'testvalue';
|
||||
|
||||
}
|
||||
@@ -87,7 +87,13 @@ class DateTimePlusTest extends TestCase {
|
||||
* @dataProvider providerTestInvalidDateDiff
|
||||
*/
|
||||
public function testInvalidDateDiff($input1, $input2, $absolute) {
|
||||
$this->setExpectedException(\BadMethodCallException::class, 'Method Drupal\Component\Datetime\DateTimePlus::diff expects parameter 1 to be a \DateTime or \Drupal\Component\Datetime\DateTimePlus object');
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(\BadMethodCallException::class);
|
||||
$this->expectExceptionMessage('Method Drupal\Component\Datetime\DateTimePlus::diff expects parameter 1 to be a \DateTime or \Drupal\Component\Datetime\DateTimePlus object');
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(\BadMethodCallException::class, 'Method Drupal\Component\Datetime\DateTimePlus::diff expects parameter 1 to be a \DateTime or \Drupal\Component\Datetime\DateTimePlus object');
|
||||
}
|
||||
$interval = $input1->diff($input2, $absolute);
|
||||
}
|
||||
|
||||
@@ -104,7 +110,12 @@ class DateTimePlusTest extends TestCase {
|
||||
* @dataProvider providerTestInvalidDateArrays
|
||||
*/
|
||||
public function testInvalidDateArrays($input, $timezone, $class) {
|
||||
$this->setExpectedException($class);
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException($class);
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException($class);
|
||||
}
|
||||
$this->assertInstanceOf(
|
||||
'\Drupal\Component\DateTimePlus',
|
||||
DateTimePlus::createFromArray($input, $timezone)
|
||||
@@ -242,7 +253,12 @@ class DateTimePlusTest extends TestCase {
|
||||
* @dataProvider providerTestInvalidDates
|
||||
*/
|
||||
public function testInvalidDates($input, $timezone, $format, $message, $class) {
|
||||
$this->setExpectedException($class);
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException($class);
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException($class);
|
||||
}
|
||||
DateTimePlus::createFromFormat($format, $input, $timezone);
|
||||
}
|
||||
|
||||
@@ -800,10 +816,27 @@ class DateTimePlusTest extends TestCase {
|
||||
|
||||
// Parse the same date with ['validate_format' => TRUE] and make sure we
|
||||
// get the expected exception.
|
||||
$this->setExpectedException(\UnexpectedValueException::class);
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(\UnexpectedValueException::class);
|
||||
}
|
||||
$date = DateTimePlus::createFromFormat('Y-m-d H:i:s', '11-03-31 17:44:00', 'UTC', ['validate_format' => TRUE]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests setting the default time for date-only objects.
|
||||
*/
|
||||
public function testDefaultDateTime() {
|
||||
$utc = new \DateTimeZone('UTC');
|
||||
|
||||
$date = DateTimePlus::createFromFormat('Y-m-d H:i:s', '2017-05-23 22:58:00', $utc);
|
||||
$this->assertEquals('22:58:00', $date->format('H:i:s'));
|
||||
$date->setDefaultDateTime();
|
||||
$this->assertEquals('12:00:00', $date->format('H:i:s'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that object methods are chainable.
|
||||
*
|
||||
@@ -847,7 +880,13 @@ class DateTimePlusTest extends TestCase {
|
||||
* @covers ::__call
|
||||
*/
|
||||
public function testChainableNonCallable() {
|
||||
$this->setExpectedException(\BadMethodCallException::class, 'Call to undefined method Drupal\Component\Datetime\DateTimePlus::nonexistent()');
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(\BadMethodCallException::class);
|
||||
$this->expectExceptionMessage('Call to undefined method Drupal\Component\Datetime\DateTimePlus::nonexistent()');
|
||||
}
|
||||
else {
|
||||
$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();
|
||||
}
|
||||
|
||||
@@ -37,8 +37,7 @@ class TimeTest extends TestCase {
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->requestStack = $this->getMock('Symfony\Component\HttpFoundation\RequestStack');
|
||||
|
||||
$this->requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->getMock();
|
||||
$this->time = new Time($this->requestStack);
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,12 @@ class ContainerTest extends TestCase {
|
||||
public function testConstruct() {
|
||||
$container_definition = $this->getMockContainerDefinition();
|
||||
$container_definition['machine_format'] = !$this->machineFormat;
|
||||
$this->setExpectedException(InvalidArgumentException::class);
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(InvalidArgumentException::class);
|
||||
}
|
||||
$container = new $this->containerClass($container_definition);
|
||||
}
|
||||
|
||||
@@ -93,7 +98,12 @@ class ContainerTest extends TestCase {
|
||||
* @covers ::getAlternatives
|
||||
*/
|
||||
public function testGetParameterIfNotFound() {
|
||||
$this->setExpectedException(ParameterNotFoundException::class);
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(ParameterNotFoundException::class);
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(ParameterNotFoundException::class);
|
||||
}
|
||||
$this->container->getParameter('parameter_that_does_not_exist');
|
||||
}
|
||||
|
||||
@@ -103,7 +113,12 @@ class ContainerTest extends TestCase {
|
||||
* @covers ::getParameter
|
||||
*/
|
||||
public function testGetParameterIfNotFoundBecauseNull() {
|
||||
$this->setExpectedException(ParameterNotFoundException::class);
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(ParameterNotFoundException::class);
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(ParameterNotFoundException::class);
|
||||
}
|
||||
$this->container->getParameter(NULL);
|
||||
}
|
||||
|
||||
@@ -137,7 +152,12 @@ class ContainerTest extends TestCase {
|
||||
*/
|
||||
public function testSetParameterWithFrozenContainer() {
|
||||
$this->container = new $this->containerClass($this->containerDefinition);
|
||||
$this->setExpectedException(LogicException::class);
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(LogicException::class);
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(LogicException::class);
|
||||
}
|
||||
$this->container->setParameter('some_config', 'new_value');
|
||||
}
|
||||
|
||||
@@ -242,7 +262,12 @@ class ContainerTest extends TestCase {
|
||||
* @covers ::createService
|
||||
*/
|
||||
public function testGetForCircularServices() {
|
||||
$this->setExpectedException(ServiceCircularReferenceException::class);
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(ServiceCircularReferenceException::class);
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(ServiceCircularReferenceException::class);
|
||||
}
|
||||
$this->container->get('circular_dependency');
|
||||
}
|
||||
|
||||
@@ -255,7 +280,12 @@ class ContainerTest extends TestCase {
|
||||
* @covers ::getServiceAlternatives
|
||||
*/
|
||||
public function testGetForNonExistantService() {
|
||||
$this->setExpectedException(ServiceNotFoundException::class);
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(ServiceNotFoundException::class);
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(ServiceNotFoundException::class);
|
||||
}
|
||||
$this->container->get('service_not_exists');
|
||||
}
|
||||
|
||||
@@ -304,7 +334,12 @@ class ContainerTest extends TestCase {
|
||||
|
||||
// Reset the service.
|
||||
$this->container->set('service_parameter_not_exists', NULL);
|
||||
$this->setExpectedException(InvalidArgumentException::class);
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(InvalidArgumentException::class);
|
||||
}
|
||||
$this->container->get('service_parameter_not_exists');
|
||||
}
|
||||
|
||||
@@ -316,7 +351,12 @@ class ContainerTest extends TestCase {
|
||||
* @covers ::resolveServicesAndParameters
|
||||
*/
|
||||
public function testGetForNonExistantParameterDependencyWithException() {
|
||||
$this->setExpectedException(InvalidArgumentException::class);
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(InvalidArgumentException::class);
|
||||
}
|
||||
$this->container->get('service_parameter_not_exists');
|
||||
}
|
||||
|
||||
@@ -341,7 +381,12 @@ class ContainerTest extends TestCase {
|
||||
* @covers ::getAlternatives
|
||||
*/
|
||||
public function testGetForNonExistantServiceDependencyWithException() {
|
||||
$this->setExpectedException(ServiceNotFoundException::class);
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(ServiceNotFoundException::class);
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(ServiceNotFoundException::class);
|
||||
}
|
||||
$this->container->get('service_dependency_not_exists');
|
||||
}
|
||||
|
||||
@@ -361,7 +406,12 @@ class ContainerTest extends TestCase {
|
||||
* @covers ::createService
|
||||
*/
|
||||
public function testGetForNonExistantNULLService() {
|
||||
$this->setExpectedException(ServiceNotFoundException::class);
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(ServiceNotFoundException::class);
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(ServiceNotFoundException::class);
|
||||
}
|
||||
$this->container->get(NULL);
|
||||
}
|
||||
|
||||
@@ -387,7 +437,12 @@ class ContainerTest extends TestCase {
|
||||
*/
|
||||
public function testGetForNonExistantServiceWithExceptionOnSecondCall() {
|
||||
$this->assertNull($this->container->get('service_not_exists', ContainerInterface::NULL_ON_INVALID_REFERENCE), 'Not found service does nto throw exception.');
|
||||
$this->setExpectedException(ServiceNotFoundException::class);
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(ServiceNotFoundException::class);
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(ServiceNotFoundException::class);
|
||||
}
|
||||
$this->container->get('service_not_exists');
|
||||
}
|
||||
|
||||
@@ -423,7 +478,12 @@ class ContainerTest extends TestCase {
|
||||
* @covers ::createService
|
||||
*/
|
||||
public function testGetForSyntheticServiceWithException() {
|
||||
$this->setExpectedException(RuntimeException::class);
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(RuntimeException::class);
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(RuntimeException::class);
|
||||
}
|
||||
$this->container->get('synthetic');
|
||||
}
|
||||
|
||||
@@ -462,7 +522,12 @@ class ContainerTest extends TestCase {
|
||||
* @covers ::createService
|
||||
*/
|
||||
public function testGetForWrongFactory() {
|
||||
$this->setExpectedException(RuntimeException::class);
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(RuntimeException::class);
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(RuntimeException::class);
|
||||
}
|
||||
$this->container->get('wrong_factory');
|
||||
}
|
||||
|
||||
@@ -500,7 +565,12 @@ class ContainerTest extends TestCase {
|
||||
* @covers ::createService
|
||||
*/
|
||||
public function testGetForConfiguratorWithException() {
|
||||
$this->setExpectedException(InvalidArgumentException::class);
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(InvalidArgumentException::class);
|
||||
}
|
||||
$this->container->get('configurable_service_exception');
|
||||
}
|
||||
|
||||
@@ -598,7 +668,12 @@ class ContainerTest extends TestCase {
|
||||
* @covers ::resolveServicesAndParameters
|
||||
*/
|
||||
public function testResolveServicesAndParametersForInvalidArgument() {
|
||||
$this->setExpectedException(InvalidArgumentException::class);
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(InvalidArgumentException::class);
|
||||
}
|
||||
$this->container->get('invalid_argument_service');
|
||||
}
|
||||
|
||||
@@ -612,7 +687,12 @@ class ContainerTest extends TestCase {
|
||||
public function testResolveServicesAndParametersForInvalidArguments() {
|
||||
// In case the machine-optimized format is not used, we need to simulate the
|
||||
// test failure.
|
||||
$this->setExpectedException(InvalidArgumentException::class);
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(InvalidArgumentException::class);
|
||||
}
|
||||
if (!$this->machineFormat) {
|
||||
throw new InvalidArgumentException('Simulating the test failure.');
|
||||
}
|
||||
|
||||
+26
-6
@@ -68,7 +68,7 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
|
||||
$this->containerBuilder->getAliases()->willReturn([]);
|
||||
$this->containerBuilder->getParameterBag()->willReturn(new ParameterBag());
|
||||
$this->containerBuilder->getDefinitions()->willReturn(NULL);
|
||||
$this->containerBuilder->isFrozen()->willReturn(TRUE);
|
||||
$this->containerBuilder->isCompiled()->willReturn(TRUE);
|
||||
|
||||
$definition = [];
|
||||
$definition['aliases'] = [];
|
||||
@@ -147,7 +147,7 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
|
||||
|
||||
$parameter_bag = new ParameterBag($parameters);
|
||||
$this->containerBuilder->getParameterBag()->willReturn($parameter_bag);
|
||||
$this->containerBuilder->isFrozen()->willReturn($is_frozen);
|
||||
$this->containerBuilder->isCompiled()->willReturn($is_frozen);
|
||||
|
||||
if (isset($parameters['reference'])) {
|
||||
$definition = new Definition('\stdClass');
|
||||
@@ -545,7 +545,12 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
|
||||
$services['bar'] = $bar_definition;
|
||||
|
||||
$this->containerBuilder->getDefinitions()->willReturn($services);
|
||||
$this->setExpectedException(InvalidArgumentException::class);
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(InvalidArgumentException::class);
|
||||
}
|
||||
$this->dumper->getArray();
|
||||
}
|
||||
|
||||
@@ -562,7 +567,12 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
|
||||
$services['bar'] = $bar_definition;
|
||||
|
||||
$this->containerBuilder->getDefinitions()->willReturn($services);
|
||||
$this->setExpectedException(RuntimeException::class);
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(RuntimeException::class);
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(RuntimeException::class);
|
||||
}
|
||||
$this->dumper->getArray();
|
||||
}
|
||||
|
||||
@@ -579,7 +589,12 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
|
||||
$services['bar'] = $bar_definition;
|
||||
|
||||
$this->containerBuilder->getDefinitions()->willReturn($services);
|
||||
$this->setExpectedException(RuntimeException::class);
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(RuntimeException::class);
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(RuntimeException::class);
|
||||
}
|
||||
$this->dumper->getArray();
|
||||
}
|
||||
|
||||
@@ -596,7 +611,12 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
|
||||
$services['bar'] = $bar_definition;
|
||||
|
||||
$this->containerBuilder->getDefinitions()->willReturn($services);
|
||||
$this->setExpectedException(RuntimeException::class);
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(RuntimeException::class);
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(RuntimeException::class);
|
||||
}
|
||||
$this->dumper->getArray();
|
||||
}
|
||||
|
||||
|
||||
@@ -86,4 +86,21 @@ class DiffEngineTest extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that two files can be successfully diffed.
|
||||
*
|
||||
* @covers ::diff
|
||||
*/
|
||||
public function testDiffInfiniteLoop() {
|
||||
$from = explode("\n", file_get_contents(__DIR__ . '/fixtures/file1.txt'));
|
||||
$to = explode("\n", file_get_contents(__DIR__ . '/fixtures/file2.txt'));
|
||||
$diff_engine = new DiffEngine();
|
||||
$diff = $diff_engine->diff($from, $to);
|
||||
$this->assertCount(4, $diff);
|
||||
$this->assertEquals($diff[0], new DiffOpDelete([' - image.style.max_650x650']));
|
||||
$this->assertEquals($diff[1], new DiffOpCopy([' - image.style.max_325x325']));
|
||||
$this->assertEquals($diff[2], new DiffOpAdd([' - image.style.max_650x650', '_core:', ' default_config_hash: 3mjM9p-kQ8syzH7N8T0L9OnCJDSPvHAZoi3q6jcXJKM']));
|
||||
$this->assertEquals($diff[3], new DiffOpCopy(['fallback_image_style: max_325x325', '']));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Drupal\Tests\Component\Diff\Engine;
|
||||
|
||||
use Drupal\Component\Diff\Engine\DiffOp;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit\Framework\Error\Error;
|
||||
|
||||
/**
|
||||
* Test DiffOp base class.
|
||||
@@ -24,7 +25,12 @@ class DiffOpTest extends TestCase {
|
||||
* @covers ::reverse
|
||||
*/
|
||||
public function testReverse() {
|
||||
$this->setExpectedException(\PHPUnit_Framework_Error::class);
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(Error::class);
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(\PHPUnit_Framework_Error::class);
|
||||
}
|
||||
$op = new DiffOp();
|
||||
$result = $op->reverse();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
- image.style.max_650x650
|
||||
- image.style.max_325x325
|
||||
fallback_image_style: max_325x325
|
||||
@@ -0,0 +1,5 @@
|
||||
- image.style.max_325x325
|
||||
- image.style.max_650x650
|
||||
_core:
|
||||
default_config_hash: 3mjM9p-kQ8syzH7N8T0L9OnCJDSPvHAZoi3q6jcXJKM
|
||||
fallback_image_style: max_325x325
|
||||
@@ -124,7 +124,13 @@ class YamlDirectoryDiscoveryTest extends TestCase {
|
||||
* @covers ::getIdentifier
|
||||
*/
|
||||
public function testDiscoveryNoIdException() {
|
||||
$this->setExpectedException(DiscoveryException::class, 'The vfs://modules/test_1/item_1.test.yml contains no data in the identifier key \'id\'');
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(DiscoveryException::class);
|
||||
$this->expectExceptionMessage('The vfs://modules/test_1/item_1.test.yml contains no data in the identifier key \'id\'');
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(DiscoveryException::class, 'The vfs://modules/test_1/item_1.test.yml contains no data in the identifier key \'id\'');
|
||||
}
|
||||
vfsStream::setup('modules', NULL, [
|
||||
'test_1' => [
|
||||
'item_1.test.yml' => "",
|
||||
@@ -144,7 +150,13 @@ class YamlDirectoryDiscoveryTest extends TestCase {
|
||||
* @covers ::findAll
|
||||
*/
|
||||
public function testDiscoveryInvalidYamlException() {
|
||||
$this->setExpectedException(DiscoveryException::class, 'The vfs://modules/test_1/item_1.test.yml contains invalid YAML');
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(DiscoveryException::class);
|
||||
$this->expectExceptionMessage('The vfs://modules/test_1/item_1.test.yml contains invalid YAML');
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(DiscoveryException::class, 'The vfs://modules/test_1/item_1.test.yml contains invalid YAML');
|
||||
}
|
||||
vfsStream::setup('modules', NULL, [
|
||||
'test_1' => [
|
||||
'item_1.test.yml' => "id: invalid\nfoo : [bar}",
|
||||
|
||||
@@ -32,6 +32,34 @@ class DrupalComponentTest extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests LICENSE.txt is present and has the correct content.
|
||||
*
|
||||
* @param $component_path
|
||||
* The path to the component.
|
||||
* @dataProvider \Drupal\Tests\Component\DrupalComponentTest::getComponents
|
||||
*/
|
||||
public function testComponentLicence($component_path) {
|
||||
$this->assertFileExists($component_path . DIRECTORY_SEPARATOR . 'LICENSE.txt');
|
||||
$this->assertSame('e84dac1d9fbb5a4a69e38654ce644cea769aa76b', hash_file('sha1', $component_path . DIRECTORY_SEPARATOR . 'LICENSE.txt'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getComponents() {
|
||||
$root_component_path = dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__))) . '/lib/Drupal/Component';
|
||||
$component_paths = [];
|
||||
foreach (new \DirectoryIterator($root_component_path) as $file) {
|
||||
if ($file->isDir() && !$file->isDot()) {
|
||||
$component_paths[$file->getBasename()] = [$file->getPathname()];
|
||||
}
|
||||
}
|
||||
return $component_paths;
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches a directory recursively for PHP classes.
|
||||
*
|
||||
|
||||
+57
-2
@@ -38,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(ContainerInterface::class);
|
||||
$container = $this->getMockBuilder(ContainerInterface::class)->getMock();
|
||||
$container->expects($this->never())->method($this->anything());
|
||||
|
||||
$firstListener = new CallableClass();
|
||||
@@ -73,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(ContainerInterface::class);
|
||||
$container = $this->getMockBuilder(ContainerInterface::class)->getMock();
|
||||
$container->expects($this->never())->method($this->anything());
|
||||
|
||||
$firstListener = new CallableClass();
|
||||
@@ -193,4 +193,59 @@ class ContainerAwareEventDispatcherTest extends SymfonyContainerAwareEventDispat
|
||||
$this->assertSame(5, $actualPriority);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedDeprecation The Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher class is deprecated since Symfony 3.3 and will be removed in 4.0. Use EventDispatcher with closure factories instead.
|
||||
* @group legacy
|
||||
*/
|
||||
public function testAddAListenerService() {
|
||||
parent::testAddAListenerService();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedDeprecation The Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher class is deprecated since Symfony 3.3 and will be removed in 4.0. Use EventDispatcher with closure factories instead.
|
||||
* @group legacy
|
||||
*/
|
||||
public function testPreventDuplicateListenerService() {
|
||||
parent::testPreventDuplicateListenerService();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedDeprecation The Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher class is deprecated since Symfony 3.3 and will be removed in 4.0. Use EventDispatcher with closure factories instead.
|
||||
* @group legacy
|
||||
*/
|
||||
public function testAddASubscriberService() {
|
||||
parent::testAddASubscriberService();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedDeprecation The Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher class is deprecated since Symfony 3.3 and will be removed in 4.0. Use EventDispatcher with closure factories instead.
|
||||
* @group legacy
|
||||
*/
|
||||
public function testHasListenersOnLazyLoad() {
|
||||
parent::testHasListenersOnLazyLoad();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedDeprecation The Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher class is deprecated since Symfony 3.3 and will be removed in 4.0. Use EventDispatcher with closure factories instead.
|
||||
* @group legacy
|
||||
*/
|
||||
public function testGetListenersOnLazyLoad() {
|
||||
parent::testGetListenersOnLazyLoad();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedDeprecation The Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher class is deprecated since Symfony 3.3 and will be removed in 4.0. Use EventDispatcher with closure factories instead.
|
||||
* @group legacy
|
||||
*/
|
||||
public function testRemoveAfterDispatch() {
|
||||
parent::testRemoveAfterDispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedDeprecation The Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher class is deprecated since Symfony 3.3 and will be removed in 4.0. Use EventDispatcher with closure factories instead.
|
||||
* @group legacy
|
||||
*/
|
||||
public function testRemoveBeforeDispatch() {
|
||||
parent::testRemoveBeforeDispatch();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,13 @@ class FileCacheFactoryTest extends TestCase {
|
||||
*/
|
||||
public function testGetNoPrefix() {
|
||||
FileCacheFactory::setPrefix(NULL);
|
||||
$this->setExpectedException(\InvalidArgumentException::class, 'Required prefix configuration is missing');
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Required prefix configuration is missing');
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(\InvalidArgumentException::class, 'Required prefix configuration is missing');
|
||||
}
|
||||
FileCacheFactory::get('test_foo_settings', []);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\Component\Gettext;
|
||||
|
||||
use Drupal\Component\Gettext\PoItem;
|
||||
use Drupal\Component\Gettext\PoStreamWriter;
|
||||
use org\bovigo\vfs\vfsStream;
|
||||
use org\bovigo\vfs\vfsStreamFile;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Component\Gettext\PoStreamWriter
|
||||
* @group Gettext
|
||||
*/
|
||||
class PoStreamWriterTest extends TestCase {
|
||||
|
||||
/**
|
||||
* The PO writer object under test.
|
||||
*
|
||||
* @var \Drupal\Component\Gettext\PoStreamWriter
|
||||
*/
|
||||
protected $poWriter;
|
||||
|
||||
/**
|
||||
* The mock po file.
|
||||
*
|
||||
* @var \org\bovigo\vfs\vfsStreamFile
|
||||
*/
|
||||
protected $poFile;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->poWriter = new PoStreamWriter();
|
||||
|
||||
$root = vfsStream::setup();
|
||||
$this->poFile = new vfsStreamFile('powriter.po');
|
||||
$root->addChild($this->poFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getURI
|
||||
*/
|
||||
public function testGetUriException() {
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(\Exception::class, 'No URI set.');
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(\Exception::class, 'No URI set.');
|
||||
}
|
||||
|
||||
$this->poWriter->getURI();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::writeItem
|
||||
* @dataProvider providerWriteData
|
||||
*/
|
||||
public function testWriteItem($poContent, $expected, $long) {
|
||||
if ($long) {
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(\Exception::class, 'Unable to write data:');
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(\Exception::class, 'Unable to write data:');
|
||||
}
|
||||
}
|
||||
|
||||
// Limit the file system quota to make the write fail on long strings.
|
||||
vfsStream::setQuota(10);
|
||||
|
||||
$this->poWriter->setURI($this->poFile->url());
|
||||
$this->poWriter->open();
|
||||
|
||||
$poItem = $this->prophesize(PoItem::class);
|
||||
$poItem->__toString()->willReturn($poContent);
|
||||
|
||||
$this->poWriter->writeItem($poItem->reveal());
|
||||
$this->poWriter->close();
|
||||
$this->assertEquals(file_get_contents($this->poFile->url()), $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* - Content to write.
|
||||
* - Written content.
|
||||
* - Content longer than 10 bytes.
|
||||
*/
|
||||
public function providerWriteData() {
|
||||
return [
|
||||
['', '', FALSE],
|
||||
["\r\n", "\r\n", FALSE],
|
||||
['write this if you can', 'write this', TRUE],
|
||||
['éáíó>&', 'éáíó>&', FALSE],
|
||||
['éáíó>&<', 'éáíó>&', TRUE],
|
||||
['中文 890', '中文 890', FALSE],
|
||||
['中文 89012', '中文 890', TRUE],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::close
|
||||
*/
|
||||
public function testCloseException() {
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(\Exception::class, 'Cannot close stream that is not open.');
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(\Exception::class, 'Cannot close stream that is not open.');
|
||||
}
|
||||
|
||||
$this->poWriter->close();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -63,14 +63,14 @@ class FileStorageReadOnlyTest extends PhpStorageTestBase {
|
||||
// Write out a PHP file and ensure it's successfully loaded.
|
||||
$code = "<?php\n\$GLOBALS[$random] = TRUE;";
|
||||
$success = $php->save($name, $code);
|
||||
$this->assertSame($success, TRUE);
|
||||
$this->assertSame(TRUE, $success);
|
||||
$php_read = new FileReadOnlyStorage($this->readonlyStorage);
|
||||
$php_read->load($name);
|
||||
$this->assertTrue($GLOBALS[$random]);
|
||||
|
||||
// If the file was successfully loaded, it must also exist, but ensure the
|
||||
// exists() method returns that correctly.
|
||||
$this->assertSame($php_read->exists($name), TRUE);
|
||||
$this->assertSame(TRUE, $php_read->exists($name));
|
||||
// Saving and deleting should always fail.
|
||||
$this->assertFalse($php_read->save($name, $code));
|
||||
$this->assertFalse($php_read->delete($name));
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Drupal\Tests\Component\PhpStorage;
|
||||
use Drupal\Component\PhpStorage\FileStorage;
|
||||
use Drupal\Component\Utility\Random;
|
||||
use org\bovigo\vfs\vfsStreamDirectory;
|
||||
use PHPUnit_Framework_Error_Warning;
|
||||
use PHPUnit\Framework\Error\Warning;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Component\PhpStorage\FileStorage
|
||||
@@ -99,7 +99,13 @@ class FileStorageTest extends PhpStorageTestBase {
|
||||
'bin' => 'test',
|
||||
]);
|
||||
$code = "<?php\n echo 'here';";
|
||||
$this->setExpectedException(PHPUnit_Framework_Error_Warning::class, 'mkdir(): Permission Denied');
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(Warning::class);
|
||||
$this->expectExceptionMessage('mkdir(): Permission Denied');
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(\PHPUnit_Framework_Error_Warning::class, 'mkdir(): Permission Denied');
|
||||
}
|
||||
$storage->save('subdirectory/foo.php', $code);
|
||||
}
|
||||
|
||||
|
||||
@@ -89,8 +89,8 @@ abstract class MTimeProtectedFileStorageBase extends PhpStorageTestBase {
|
||||
// minimal permissions. fileperms() can return high bits unrelated to
|
||||
// permissions, so mask with 0777.
|
||||
$this->assertTrue(file_exists($expected_filename));
|
||||
$this->assertSame(fileperms($expected_filename) & 0777, 0444);
|
||||
$this->assertSame(fileperms($expected_directory) & 0777, 0777);
|
||||
$this->assertSame(0444, fileperms($expected_filename) & 0777);
|
||||
$this->assertSame(0777, fileperms($expected_directory) & 0777);
|
||||
|
||||
// Ensure the root directory for the bin has a .htaccess file denying web
|
||||
// access.
|
||||
@@ -121,9 +121,9 @@ abstract class MTimeProtectedFileStorageBase extends PhpStorageTestBase {
|
||||
chmod($expected_filename, 0400);
|
||||
chmod($expected_directory, 0100);
|
||||
$this->assertSame(file_get_contents($expected_filename), $untrusted_code);
|
||||
$this->assertSame($php->exists($name), $this->expected[$i]);
|
||||
$this->assertSame($php->load($name), $this->expected[$i]);
|
||||
$this->assertSame($GLOBALS['hacked'], $this->expected[$i]);
|
||||
$this->assertSame($this->expected[$i], $php->exists($name));
|
||||
$this->assertSame($this->expected[$i], $php->load($name));
|
||||
$this->assertSame($this->expected[$i], $GLOBALS['hacked']);
|
||||
}
|
||||
unset($GLOBALS['hacked']);
|
||||
}
|
||||
|
||||
@@ -71,10 +71,16 @@ class ContextTest extends TestCase {
|
||||
|
||||
// Set expectation for exception.
|
||||
if ($is_required) {
|
||||
$this->setExpectedException(
|
||||
'Drupal\Component\Plugin\Exception\ContextException',
|
||||
sprintf("The %s context is required and not present.", $data_type)
|
||||
);
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException('Drupal\Component\Plugin\Exception\ContextException');
|
||||
$this->expectExceptionMessage(sprintf("The %s context is required and not present.", $data_type));
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(
|
||||
'Drupal\Component\Plugin\Exception\ContextException',
|
||||
sprintf("The %s context is required and not present.", $data_type)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Exercise getContextValue().
|
||||
|
||||
@@ -5,9 +5,9 @@ namespace Drupal\Tests\Component\Plugin;
|
||||
use Drupal\Component\Plugin\Definition\PluginDefinitionInterface;
|
||||
use Drupal\Component\Plugin\Exception\PluginException;
|
||||
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\Component\Plugin\Fixtures\vegetable\Broccoli;
|
||||
use Drupal\Tests\Component\Plugin\Fixtures\vegetable\Corn;
|
||||
use Drupal\Tests\Component\Plugin\Fixtures\vegetable\VegetableInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
@@ -22,8 +22,8 @@ class DefaultFactoryTest extends TestCase {
|
||||
* @covers ::getPluginClass
|
||||
*/
|
||||
public function testGetPluginClassWithValidArrayPluginDefinition() {
|
||||
$plugin_class = Cherry::class;
|
||||
$class = DefaultFactory::getPluginClass('cherry', ['class' => $plugin_class]);
|
||||
$plugin_class = Corn::class;
|
||||
$class = DefaultFactory::getPluginClass('corn', ['class' => $plugin_class]);
|
||||
|
||||
$this->assertEquals($plugin_class, $class);
|
||||
}
|
||||
@@ -34,12 +34,12 @@ class DefaultFactoryTest extends TestCase {
|
||||
* @covers ::getPluginClass
|
||||
*/
|
||||
public function testGetPluginClassWithValidObjectPluginDefinition() {
|
||||
$plugin_class = Cherry::class;
|
||||
$plugin_definition = $this->getMock(PluginDefinitionInterface::class);
|
||||
$plugin_class = Corn::class;
|
||||
$plugin_definition = $this->getMockBuilder(PluginDefinitionInterface::class)->getMock();
|
||||
$plugin_definition->expects($this->atLeastOnce())
|
||||
->method('getClass')
|
||||
->willReturn($plugin_class);
|
||||
$class = DefaultFactory::getPluginClass('cherry', $plugin_definition);
|
||||
$class = DefaultFactory::getPluginClass('corn', $plugin_definition);
|
||||
|
||||
$this->assertEquals($plugin_class, $class);
|
||||
}
|
||||
@@ -50,8 +50,14 @@ class DefaultFactoryTest extends TestCase {
|
||||
* @covers ::getPluginClass
|
||||
*/
|
||||
public function testGetPluginClassWithMissingClassWithArrayPluginDefinition() {
|
||||
$this->setExpectedException(PluginException::class, 'The plugin (cherry) did not specify an instance class.');
|
||||
DefaultFactory::getPluginClass('cherry', []);
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(PluginException::class);
|
||||
$this->expectExceptionMessage('The plugin (corn) did not specify an instance class.');
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(PluginException::class, 'The plugin (corn) did not specify an instance class.');
|
||||
}
|
||||
DefaultFactory::getPluginClass('corn', []);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,9 +66,15 @@ class DefaultFactoryTest extends TestCase {
|
||||
* @covers ::getPluginClass
|
||||
*/
|
||||
public function testGetPluginClassWithMissingClassWithObjectPluginDefinition() {
|
||||
$plugin_definition = $this->getMock(PluginDefinitionInterface::class);
|
||||
$this->setExpectedException(PluginException::class, 'The plugin (cherry) did not specify an instance class.');
|
||||
DefaultFactory::getPluginClass('cherry', $plugin_definition);
|
||||
$plugin_definition = $this->getMockBuilder(PluginDefinitionInterface::class)->getMock();
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(PluginException::class);
|
||||
$this->expectExceptionMessage('The plugin (corn) did not specify an instance class.');
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(PluginException::class, 'The plugin (corn) did not specify an instance class.');
|
||||
}
|
||||
DefaultFactory::getPluginClass('corn', $plugin_definition);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,8 +83,14 @@ class DefaultFactoryTest extends TestCase {
|
||||
* @covers ::getPluginClass
|
||||
*/
|
||||
public function testGetPluginClassWithNotExistingClassWithArrayPluginDefinition() {
|
||||
$this->setExpectedException(PluginException::class, 'Plugin (kiwifruit) instance class "\Drupal\plugin_test\Plugin\plugin_test\fruit\Kiwifruit" does not exist.');
|
||||
DefaultFactory::getPluginClass('kiwifruit', ['class' => '\Drupal\plugin_test\Plugin\plugin_test\fruit\Kiwifruit']);
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(PluginException::class);
|
||||
$this->expectExceptionMessage('Plugin (carrot) instance class "Drupal\Tests\Component\Plugin\Fixtures\vegetable\Carrot" does not exist.');
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(PluginException::class, 'Plugin (carrot) instance class "Drupal\Tests\Component\Plugin\Fixtures\vegetable\Carrot" does not exist.');
|
||||
}
|
||||
DefaultFactory::getPluginClass('carrot', ['class' => 'Drupal\Tests\Component\Plugin\Fixtures\vegetable\Carrot']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,13 +99,18 @@ class DefaultFactoryTest extends TestCase {
|
||||
* @covers ::getPluginClass
|
||||
*/
|
||||
public function testGetPluginClassWithNotExistingClassWithObjectPluginDefinition() {
|
||||
$plugin_class = '\Drupal\plugin_test\Plugin\plugin_test\fruit\Kiwifruit';
|
||||
$plugin_definition = $this->getMock(PluginDefinitionInterface::class);
|
||||
$plugin_class = 'Drupal\Tests\Component\Plugin\Fixtures\vegetable\Carrot';
|
||||
$plugin_definition = $this->getMockBuilder(PluginDefinitionInterface::class)->getMock();
|
||||
$plugin_definition->expects($this->atLeastOnce())
|
||||
->method('getClass')
|
||||
->willReturn($plugin_class);
|
||||
$this->setExpectedException(PluginException::class);
|
||||
DefaultFactory::getPluginClass('kiwifruit', $plugin_definition);
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(PluginException::class);
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(PluginException::class);
|
||||
}
|
||||
DefaultFactory::getPluginClass('carrot', $plugin_definition);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,8 +119,8 @@ class DefaultFactoryTest extends TestCase {
|
||||
* @covers ::getPluginClass
|
||||
*/
|
||||
public function testGetPluginClassWithInterfaceWithArrayPluginDefinition() {
|
||||
$plugin_class = Cherry::class;
|
||||
$class = DefaultFactory::getPluginClass('cherry', ['class' => $plugin_class], FruitInterface::class);
|
||||
$plugin_class = Corn::class;
|
||||
$class = DefaultFactory::getPluginClass('corn', ['class' => $plugin_class], VegetableInterface::class);
|
||||
|
||||
$this->assertEquals($plugin_class, $class);
|
||||
}
|
||||
@@ -108,12 +131,12 @@ class DefaultFactoryTest extends TestCase {
|
||||
* @covers ::getPluginClass
|
||||
*/
|
||||
public function testGetPluginClassWithInterfaceWithObjectPluginDefinition() {
|
||||
$plugin_class = Cherry::class;
|
||||
$plugin_definition = $this->getMock(PluginDefinitionInterface::class);
|
||||
$plugin_class = Corn::class;
|
||||
$plugin_definition = $this->getMockBuilder(PluginDefinitionInterface::class)->getMock();
|
||||
$plugin_definition->expects($this->atLeastOnce())
|
||||
->method('getClass')
|
||||
->willReturn($plugin_class);
|
||||
$class = DefaultFactory::getPluginClass('cherry', $plugin_definition, FruitInterface::class);
|
||||
$class = DefaultFactory::getPluginClass('corn', $plugin_definition, VegetableInterface::class);
|
||||
|
||||
$this->assertEquals($plugin_class, $class);
|
||||
}
|
||||
@@ -124,9 +147,14 @@ class DefaultFactoryTest extends TestCase {
|
||||
* @covers ::getPluginClass
|
||||
*/
|
||||
public function testGetPluginClassWithInterfaceAndInvalidClassWithArrayPluginDefinition() {
|
||||
$plugin_class = Kale::class;
|
||||
$this->setExpectedException(PluginException::class, 'Plugin "cherry" (Drupal\plugin_test\Plugin\plugin_test\fruit\Kale) must implement interface Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface.');
|
||||
DefaultFactory::getPluginClass('cherry', ['class' => $plugin_class, 'provider' => 'core'], FruitInterface::class);
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(PluginException::class);
|
||||
$this->expectExceptionMessage('Plugin "corn" (Drupal\Tests\Component\Plugin\Fixtures\vegetable\Broccoli) must implement interface Drupal\Tests\Component\Plugin\Fixtures\vegetable\VegetableInterface.');
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(PluginException::class, 'Plugin "corn" (Drupal\Tests\Component\Plugin\Fixtures\vegetable\Broccoli) must implement interface Drupal\Tests\Component\Plugin\Fixtures\vegetable\VegetableInterface.');
|
||||
}
|
||||
DefaultFactory::getPluginClass('corn', ['class' => Broccoli::class], VegetableInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,13 +163,18 @@ class DefaultFactoryTest extends TestCase {
|
||||
* @covers ::getPluginClass
|
||||
*/
|
||||
public function testGetPluginClassWithInterfaceAndInvalidClassWithObjectPluginDefinition() {
|
||||
$plugin_class = Kale::class;
|
||||
$plugin_definition = $this->getMock(PluginDefinitionInterface::class);
|
||||
$plugin_class = Broccoli::class;
|
||||
$plugin_definition = $this->getMockBuilder(PluginDefinitionInterface::class)->getMock();
|
||||
$plugin_definition->expects($this->atLeastOnce())
|
||||
->method('getClass')
|
||||
->willReturn($plugin_class);
|
||||
$this->setExpectedException(PluginException::class);
|
||||
DefaultFactory::getPluginClass('cherry', $plugin_definition, FruitInterface::class);
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(PluginException::class);
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(PluginException::class);
|
||||
}
|
||||
DefaultFactory::getPluginClass('corn', $plugin_definition, VegetableInterface::class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -69,7 +69,12 @@ class DiscoveryTraitTest extends TestCase {
|
||||
$method_ref = new \ReflectionMethod($trait, 'doGetDefinition');
|
||||
$method_ref->setAccessible(TRUE);
|
||||
// Call doGetDefinition, with $exception_on_invalid always TRUE.
|
||||
$this->setExpectedException(PluginNotFoundException::class);
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(PluginNotFoundException::class);
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(PluginNotFoundException::class);
|
||||
}
|
||||
$method_ref->invoke($trait, $definitions, $plugin_id, TRUE);
|
||||
}
|
||||
|
||||
@@ -106,7 +111,12 @@ class DiscoveryTraitTest extends TestCase {
|
||||
->method('getDefinitions')
|
||||
->willReturn($definitions);
|
||||
// Call getDefinition(), with $exception_on_invalid always TRUE.
|
||||
$this->setExpectedException(PluginNotFoundException::class);
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(PluginNotFoundException::class);
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(PluginNotFoundException::class);
|
||||
}
|
||||
$trait->getDefinition($plugin_id, TRUE);
|
||||
}
|
||||
|
||||
|
||||
@@ -100,7 +100,12 @@ class StaticDiscoveryDecoratorTest extends TestCase {
|
||||
$ref_decorated->setValue($mock_decorator, $mock_decorated);
|
||||
|
||||
if ($exception_on_invalid) {
|
||||
$this->setExpectedException('Drupal\Component\Plugin\Exception\PluginNotFoundException');
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException('Drupal\Component\Plugin\Exception\PluginNotFoundException');
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException('Drupal\Component\Plugin\Exception\PluginNotFoundException');
|
||||
}
|
||||
}
|
||||
|
||||
// Exercise getDefinition(). It calls parent::getDefinition().
|
||||
|
||||
@@ -123,7 +123,12 @@ class ReflectionFactoryTest extends TestCase {
|
||||
// us to use one data set for this test method as well as
|
||||
// testCreateInstance().
|
||||
if ($plugin_id == 'arguments_no_constructor') {
|
||||
$this->setExpectedException('\ReflectionException');
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException('\ReflectionException');
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException('\ReflectionException');
|
||||
}
|
||||
}
|
||||
|
||||
// Finally invoke getInstanceArguments() on our mocked factory.
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\Component\Plugin\Fixtures\vegetable;
|
||||
|
||||
/**
|
||||
* @Plugin(
|
||||
* id = "broccoli",
|
||||
* label = "Broccoli",
|
||||
* color = "green"
|
||||
* )
|
||||
*/
|
||||
class Broccoli {}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\Component\Plugin\Fixtures\vegetable;
|
||||
|
||||
/**
|
||||
* @Plugin(
|
||||
* id = "corn",
|
||||
* label = "Corn",
|
||||
* color = "yellow"
|
||||
* )
|
||||
*/
|
||||
class Corn implements VegetableInterface {}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\Component\Plugin\Fixtures\vegetable;
|
||||
|
||||
/**
|
||||
* Provides an interface for test plugins.
|
||||
*/
|
||||
interface VegetableInterface {}
|
||||
@@ -58,7 +58,7 @@ class JsonTest extends TestCase {
|
||||
*/
|
||||
public function testEncodingAscii() {
|
||||
// Verify there aren't character encoding problems with the source string.
|
||||
$this->assertSame(strlen($this->string), 127, 'A string with the full ASCII table has the correct length.');
|
||||
$this->assertSame(127, strlen($this->string), 'A string with the full ASCII table has the correct length.');
|
||||
foreach ($this->htmlUnsafe as $char) {
|
||||
$this->assertTrue(strpos($this->string, $char) > 0, sprintf('A string with the full ASCII table includes %s.', $char));
|
||||
}
|
||||
|
||||
@@ -87,7 +87,12 @@ foo:
|
||||
* @covers ::errorHandler
|
||||
*/
|
||||
public function testError() {
|
||||
$this->setExpectedException(InvalidDataTypeException::class);
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(InvalidDataTypeException::class);
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(InvalidDataTypeException::class);
|
||||
}
|
||||
YamlPecl::decode('foo: [ads');
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,12 @@ class YamlSymfonyTest extends YamlTestBase {
|
||||
* @covers ::decode
|
||||
*/
|
||||
public function testError() {
|
||||
$this->setExpectedException(InvalidDataTypeException::class);
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(InvalidDataTypeException::class);
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(InvalidDataTypeException::class);
|
||||
}
|
||||
YamlSymfony::decode('foo: [ads');
|
||||
}
|
||||
|
||||
@@ -69,7 +74,13 @@ class YamlSymfonyTest extends YamlTestBase {
|
||||
* @covers ::encode
|
||||
*/
|
||||
public function testObjectSupportDisabled() {
|
||||
$this->setExpectedException(InvalidDataTypeException::class, 'Object support when dumping a YAML file has been disabled.');
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(InvalidDataTypeException::class);
|
||||
$this->expectExceptionMessage('Object support when dumping a YAML file has been disabled.');
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(InvalidDataTypeException::class, 'Object support when dumping a YAML file has been disabled.');
|
||||
}
|
||||
$object = new \stdClass();
|
||||
$object->foo = 'bar';
|
||||
YamlSymfony::encode([$object]);
|
||||
|
||||
@@ -77,20 +77,46 @@ class YamlTest extends TestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that decoding php objects is similar for PECL and Symfony.
|
||||
* Ensures that decoding php objects does not work in PECL.
|
||||
*
|
||||
* @requires extension yaml
|
||||
*
|
||||
* @see \Drupal\Tests\Component\Serialization\YamlTest::testObjectSupportDisabledSymfony()
|
||||
*/
|
||||
public function testObjectSupportDisabled() {
|
||||
public function testObjectSupportDisabledPecl() {
|
||||
$object = new \stdClass();
|
||||
$object->foo = 'bar';
|
||||
// In core all Yaml encoding is done via Symfony and it does not support
|
||||
// objects so in order to encode an object we hace to use the PECL
|
||||
// objects so in order to encode an object we have to use the PECL
|
||||
// extension.
|
||||
// @see \Drupal\Component\Serialization\Yaml::encode()
|
||||
$yaml = YamlPecl::encode([$object]);
|
||||
$this->assertEquals(['O:8:"stdClass":1:{s:3:"foo";s:3:"bar";}'], YamlPecl::decode($yaml));
|
||||
$this->assertEquals(['!php/object "O:8:\"stdClass\":1:{s:3:\"foo\";s:3:\"bar\";}"'], YamlSymfony::decode($yaml));
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that decoding php objects does not work in Symfony.
|
||||
*
|
||||
* @requires extension yaml
|
||||
*
|
||||
* @see \Drupal\Tests\Component\Serialization\YamlTest::testObjectSupportDisabledPecl()
|
||||
*/
|
||||
public function testObjectSupportDisabledSymfony() {
|
||||
if (method_exists($this, 'setExpectedExceptionRegExp')) {
|
||||
$this->setExpectedExceptionRegExp(InvalidDataTypeException::class, '/^Object support when parsing a YAML file has been disabled/');
|
||||
}
|
||||
else {
|
||||
$this->expectException(InvalidDataTypeException::class);
|
||||
$this->expectExceptionMessageRegExp('/^Object support when parsing a YAML file has been disabled/');
|
||||
}
|
||||
$object = new \stdClass();
|
||||
$object->foo = 'bar';
|
||||
// In core all Yaml encoding is done via Symfony and it does not support
|
||||
// objects so in order to encode an object we have to use the PECL
|
||||
// extension.
|
||||
// @see \Drupal\Component\Serialization\Yaml::encode()
|
||||
$yaml = YamlPecl::encode([$object]);
|
||||
YamlSymfony::decode($yaml);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,8 +127,8 @@ class YamlTest extends TestCase {
|
||||
$dirs = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(__DIR__ . '/../../../../../', \RecursiveDirectoryIterator::FOLLOW_SYMLINKS));
|
||||
foreach ($dirs as $dir) {
|
||||
$pathname = $dir->getPathname();
|
||||
// Exclude vendor.
|
||||
if ($dir->getExtension() == 'yml' && strpos($pathname, '/../../../../../vendor') === FALSE) {
|
||||
// Exclude core/node_modules.
|
||||
if ($dir->getExtension() == 'yml' && strpos($pathname, '/../../../../../node_modules') === FALSE) {
|
||||
if (strpos($dir->getRealPath(), 'invalid_file') !== FALSE) {
|
||||
// There are some intentionally invalid files provided for testing
|
||||
// library API behaviours, ignore them.
|
||||
|
||||
@@ -182,7 +182,7 @@ class PhpTransliterationTest extends TestCase {
|
||||
]);
|
||||
$transliteration = new PhpTransliteration(vfsStream::url('transliteration/dir'));
|
||||
$transliterated = $transliteration->transliterate(chr(0xC2) . chr(0x82), '../index');
|
||||
$this->assertSame($transliterated, 'safe');
|
||||
$this->assertSame('safe', $transliterated);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -96,9 +96,9 @@ class ArgumentsResolverTest extends TestCase {
|
||||
* Tests getArgument() with a Route, Request, and Account object.
|
||||
*/
|
||||
public function testGetArgumentOrder() {
|
||||
$a1 = $this->getMock('\Drupal\Tests\Component\Utility\Test1Interface');
|
||||
$a2 = $this->getMock('\Drupal\Tests\Component\Utility\TestClass');
|
||||
$a3 = $this->getMock('\Drupal\Tests\Component\Utility\Test2Interface');
|
||||
$a1 = $this->getMockBuilder('\Drupal\Tests\Component\Utility\Test1Interface')->getMock();
|
||||
$a2 = $this->getMockBuilder('\Drupal\Tests\Component\Utility\TestClass')->getMock();
|
||||
$a3 = $this->getMockBuilder('\Drupal\Tests\Component\Utility\Test2Interface')->getMock();
|
||||
|
||||
$objects = [
|
||||
't1' => $a1,
|
||||
@@ -123,12 +123,18 @@ class ArgumentsResolverTest extends TestCase {
|
||||
* Without the typehint, the wildcard object will not be passed to the callable.
|
||||
*/
|
||||
public function testGetWildcardArgumentNoTypehint() {
|
||||
$a = $this->getMock('\Drupal\Tests\Component\Utility\Test1Interface');
|
||||
$a = $this->getMockBuilder('\Drupal\Tests\Component\Utility\Test1Interface')->getMock();
|
||||
$wildcards = [$a];
|
||||
$resolver = new ArgumentsResolver([], [], $wildcards);
|
||||
|
||||
$callable = function ($route) {};
|
||||
$this->setExpectedException(\RuntimeException::class, 'requires a value for the "$route" argument.');
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(\RuntimeException::class);
|
||||
$this->expectExceptionMessage('requires a value for the "$route" argument.');
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(\RuntimeException::class, 'requires a value for the "$route" argument.');
|
||||
}
|
||||
$resolver->getArguments($callable);
|
||||
}
|
||||
|
||||
@@ -156,7 +162,13 @@ class ArgumentsResolverTest extends TestCase {
|
||||
$resolver = new ArgumentsResolver($scalars, $objects, []);
|
||||
|
||||
$callable = function (\stdClass $foo) {};
|
||||
$this->setExpectedException(\RuntimeException::class, 'requires a value for the "$foo" argument.');
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(\RuntimeException::class);
|
||||
$this->expectExceptionMessage('requires a value for the "$foo" argument.');
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(\RuntimeException::class, 'requires a value for the "$foo" argument.');
|
||||
}
|
||||
$resolver->getArguments($callable);
|
||||
}
|
||||
|
||||
@@ -167,7 +179,13 @@ class ArgumentsResolverTest extends TestCase {
|
||||
*/
|
||||
public function testHandleUnresolvedArgument($callable) {
|
||||
$resolver = new ArgumentsResolver([], [], []);
|
||||
$this->setExpectedException(\RuntimeException::class, 'requires a value for the "$foo" argument.');
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(\RuntimeException::class);
|
||||
$this->expectExceptionMessage('requires a value for the "$foo" argument.');
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(\RuntimeException::class, 'requires a value for the "$foo" argument.');
|
||||
}
|
||||
$resolver->getArguments($callable);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,12 @@ class ColorTest extends TestCase {
|
||||
*/
|
||||
public function testHexToRgb($value, $expected, $invalid = FALSE) {
|
||||
if ($invalid) {
|
||||
$this->setExpectedException('InvalidArgumentException');
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException('InvalidArgumentException');
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException('InvalidArgumentException');
|
||||
}
|
||||
}
|
||||
$this->assertSame($expected, Color::hexToRgb($value));
|
||||
}
|
||||
@@ -118,4 +123,42 @@ class ColorTest extends TestCase {
|
||||
return $tests;
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testNormalizeHexLength().
|
||||
*
|
||||
* @see testNormalizeHexLength()
|
||||
*
|
||||
* @return array
|
||||
* An array of arrays containing:
|
||||
* - The hex color value.
|
||||
* - The 6 character length hex color value.
|
||||
*/
|
||||
public function providerTestNormalizeHexLength() {
|
||||
$data = [
|
||||
['#000', '#000000'],
|
||||
['#FFF', '#FFFFFF'],
|
||||
['#abc', '#aabbcc'],
|
||||
['cba', '#ccbbaa'],
|
||||
['#000000', '#000000'],
|
||||
['ffffff', '#ffffff'],
|
||||
['#010203', '#010203'],
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests Color::normalizeHexLength().
|
||||
*
|
||||
* @param string $value
|
||||
* The input hex color value.
|
||||
* @param string $expected
|
||||
* The expected normalized hex color value.
|
||||
*
|
||||
* @dataProvider providerTestNormalizeHexLength
|
||||
*/
|
||||
public function testNormalizeHexLength($value, $expected) {
|
||||
$this->assertSame($expected, Color::normalizeHexLength($value));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -77,7 +77,12 @@ class CryptTest extends TestCase {
|
||||
* Key to use in hashing process.
|
||||
*/
|
||||
public function testHmacBase64Invalid($data, $key) {
|
||||
$this->setExpectedException(\InvalidArgumentException::class);
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException('InvalidArgumentException');
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException('InvalidArgumentException');
|
||||
}
|
||||
Crypt::hmacBase64($data, $key);
|
||||
}
|
||||
|
||||
|
||||
@@ -343,7 +343,12 @@ class HtmlTest extends TestCase {
|
||||
* @dataProvider providerTestTransformRootRelativeUrlsToAbsoluteAssertion
|
||||
*/
|
||||
public function testTransformRootRelativeUrlsToAbsoluteAssertion($scheme_and_host) {
|
||||
$this->setExpectedException(\AssertionError::class);
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(\AssertionError::class);
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(\AssertionError::class);
|
||||
}
|
||||
Html::transformRootRelativeUrlsToAbsolute('', $scheme_and_host);
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,12 @@ class RandomTest extends TestCase {
|
||||
// There are fewer than 100 possibilities so an exception should occur to
|
||||
// prevent infinite loops.
|
||||
$random = new Random();
|
||||
$this->setExpectedException(\RuntimeException::class);
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(\RuntimeException::class);
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(\RuntimeException::class);
|
||||
}
|
||||
for ($i = 0; $i <= 100; $i++) {
|
||||
$str = $random->name(1, TRUE);
|
||||
$names[$str] = TRUE;
|
||||
@@ -78,7 +83,12 @@ class RandomTest extends TestCase {
|
||||
// There are fewer than 100 possibilities so an exception should occur to
|
||||
// prevent infinite loops.
|
||||
$random = new Random();
|
||||
$this->setExpectedException(\RuntimeException::class);
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(\RuntimeException::class);
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(\RuntimeException::class);
|
||||
}
|
||||
for ($i = 0; $i <= 100; $i++) {
|
||||
$str = $random->string(1, TRUE);
|
||||
$names[$str] = TRUE;
|
||||
|
||||
@@ -17,7 +17,12 @@ class RectangleTest extends TestCase {
|
||||
* @covers ::rotate
|
||||
*/
|
||||
public function testWrongWidth() {
|
||||
$this->setExpectedException(\InvalidArgumentException::class);
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(\InvalidArgumentException::class);
|
||||
}
|
||||
$rect = new Rectangle(-40, 20);
|
||||
}
|
||||
|
||||
@@ -27,7 +32,12 @@ class RectangleTest extends TestCase {
|
||||
* @covers ::rotate
|
||||
*/
|
||||
public function testWrongHeight() {
|
||||
$this->setExpectedException(\InvalidArgumentException::class);
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(\InvalidArgumentException::class);
|
||||
}
|
||||
$rect = new Rectangle(40, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ class SafeMarkupTest extends TestCase {
|
||||
* @covers ::isSafe
|
||||
*/
|
||||
public function testIsSafe() {
|
||||
$safe_string = $this->getMock('\Drupal\Component\Render\MarkupInterface');
|
||||
$safe_string = $this->getMockBuilder('\Drupal\Component\Render\MarkupInterface')->getMock();
|
||||
$this->assertTrue(SafeMarkup::isSafe($safe_string));
|
||||
$string_object = new SafeMarkupTestString('test');
|
||||
$this->assertFalse(SafeMarkup::isSafe($string_object));
|
||||
|
||||
@@ -33,7 +33,12 @@ class UnicodeTest extends TestCase {
|
||||
*/
|
||||
public function testStatus($value, $expected, $invalid = FALSE) {
|
||||
if ($invalid) {
|
||||
$this->setExpectedException('InvalidArgumentException');
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException('InvalidArgumentException');
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException('InvalidArgumentException');
|
||||
}
|
||||
}
|
||||
Unicode::setStatus($value);
|
||||
$this->assertEquals($expected, Unicode::getStatus());
|
||||
@@ -371,7 +376,7 @@ class UnicodeTest extends TestCase {
|
||||
* - (optional) Boolean for the $add_ellipsis flag. Defaults to FALSE.
|
||||
*/
|
||||
public function providerTruncate() {
|
||||
return [
|
||||
$tests = [
|
||||
['frànçAIS is über-åwesome', 24, 'frànçAIS is über-åwesome'],
|
||||
['frànçAIS is über-åwesome', 23, 'frànçAIS is über-åwesom'],
|
||||
['frànçAIS is über-åwesome', 17, 'frànçAIS is über-'],
|
||||
@@ -417,6 +422,24 @@ class UnicodeTest extends TestCase {
|
||||
['Help! Help! Help!', 3, 'He…', TRUE, TRUE],
|
||||
['Help! Help! Help!', 2, 'H…', TRUE, TRUE],
|
||||
];
|
||||
|
||||
// Test truncate on text with multiple lines.
|
||||
$multi_line = <<<EOF
|
||||
This is a text that spans multiple lines.
|
||||
Line 2 goes here.
|
||||
EOF;
|
||||
$multi_line_wordsafe = <<<EOF
|
||||
This is a text that spans multiple lines.
|
||||
Line 2
|
||||
EOF;
|
||||
$multi_line_non_wordsafe = <<<EOF
|
||||
This is a text that spans multiple lines.
|
||||
Line 2 go
|
||||
EOF;
|
||||
$tests[] = [$multi_line, 51, $multi_line_wordsafe, TRUE];
|
||||
$tests[] = [$multi_line, 51, $multi_line_non_wordsafe, FALSE];
|
||||
|
||||
return $tests;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -578,7 +578,12 @@ class UrlHelperTest extends TestCase {
|
||||
* @dataProvider providerTestExternalIsLocalInvalid
|
||||
*/
|
||||
public function testExternalIsLocalInvalid($url, $base_url) {
|
||||
$this->setExpectedException(\InvalidArgumentException::class);
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(\InvalidArgumentException::class);
|
||||
}
|
||||
UrlHelper::externalIsLocal($url, $base_url);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Drupal\Tests;
|
||||
|
||||
use Composer\Semver\Semver;
|
||||
|
||||
/**
|
||||
* Tests Composer integration.
|
||||
*
|
||||
@@ -9,6 +11,15 @@ namespace Drupal\Tests;
|
||||
*/
|
||||
class ComposerIntegrationTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* The minimum PHP version supported by Drupal.
|
||||
*
|
||||
* @see https://www.drupal.org/docs/8/system-requirements/web-server
|
||||
*
|
||||
* @todo Remove as part of https://www.drupal.org/node/2908079
|
||||
*/
|
||||
const MIN_PHP_VERSION = '5.5.9';
|
||||
|
||||
/**
|
||||
* Gets human-readable JSON error messages.
|
||||
*
|
||||
@@ -171,6 +182,34 @@ class ComposerIntegrationTest extends UnitTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests package requirements for the minimum supported PHP version by Drupal.
|
||||
*
|
||||
* @todo This can be removed when DrupalCI supports dependency regression
|
||||
* testing in https://www.drupal.org/node/2874198
|
||||
*/
|
||||
public function testMinPHPVersion() {
|
||||
// Check for lockfile in the application root. If the lockfile does not
|
||||
// exist, then skip this test.
|
||||
$lockfile = $this->root . '/composer.lock';
|
||||
if (!file_exists($lockfile)) {
|
||||
$this->markTestSkipped('/composer.lock is not available.');
|
||||
}
|
||||
|
||||
$lock = json_decode(file_get_contents($lockfile), TRUE);
|
||||
|
||||
// Check the PHP version for each installed non-development package. The
|
||||
// testing infrastructure uses the uses the development packages, and may
|
||||
// update them for particular environment configurations. In particular,
|
||||
// PHP 7.2+ require an updated version of phpunit, which is incompatible
|
||||
// with Drupal's minimum PHP requirement.
|
||||
foreach ($lock['packages'] as $package) {
|
||||
if (isset($package['require']['php'])) {
|
||||
$this->assertTrue(Semver::satisfies(static::MIN_PHP_VERSION, $package['require']['php']), $package['name'] . ' has a PHP dependency requirement of "' . $package['require']['php'] . '"');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
/**
|
||||
* The following method is copied from \Composer\Package\Locker.
|
||||
|
||||
@@ -128,6 +128,9 @@ class AccessResultTest extends UnitTestCase {
|
||||
$reason = $this->getRandomGenerator()->string();
|
||||
$b = AccessResult::forbidden($reason);
|
||||
$verify($b, $reason);
|
||||
|
||||
$b = AccessResult::forbiddenIf(TRUE, $reason);
|
||||
$verify($b, $reason);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -52,9 +52,9 @@ class AjaxResponseTest extends UnitTestCase {
|
||||
|
||||
// Ensure that the added commands are in the right order.
|
||||
$commands =& $this->ajaxResponse->getCommands();
|
||||
$this->assertSame($commands[1], ['command' => 'one']);
|
||||
$this->assertSame($commands[2], ['command' => 'two']);
|
||||
$this->assertSame($commands[0], ['command' => 'three']);
|
||||
$this->assertSame(['command' => 'one'], $commands[1]);
|
||||
$this->assertSame(['command' => 'two'], $commands[2]);
|
||||
$this->assertSame(['command' => 'three'], $commands[0]);
|
||||
|
||||
// Remove one and change one element from commands and ensure the reference
|
||||
// worked as expected.
|
||||
@@ -62,9 +62,9 @@ class AjaxResponseTest extends UnitTestCase {
|
||||
$commands[0]['class'] = 'test-class';
|
||||
|
||||
$commands = $this->ajaxResponse->getCommands();
|
||||
$this->assertSame($commands[1], ['command' => 'one']);
|
||||
$this->assertSame(['command' => 'one'], $commands[1]);
|
||||
$this->assertFalse(isset($commands[2]));
|
||||
$this->assertSame($commands[0], ['command' => 'three', 'class' => 'test-class']);
|
||||
$this->assertSame(['command' => 'three', 'class' => 'test-class'], $commands[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\Core\Ajax;
|
||||
|
||||
use Drupal\Core\Ajax\OpenOffCanvasDialogCommand;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Core\Ajax\OpenOffCanvasDialogCommand
|
||||
* @group Ajax
|
||||
*/
|
||||
class OpenOffCanvasDialogCommandTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @covers ::render
|
||||
*/
|
||||
public function testRender() {
|
||||
$command = new OpenOffCanvasDialogCommand('Title', '<p>Text!</p>', ['url' => 'example']);
|
||||
|
||||
$expected = [
|
||||
'command' => 'openDialog',
|
||||
'selector' => '#drupal-off-canvas',
|
||||
'settings' => NULL,
|
||||
'data' => '<p>Text!</p>',
|
||||
'dialogOptions' => [
|
||||
'url' => 'example',
|
||||
'title' => 'Title',
|
||||
'modal' => FALSE,
|
||||
'autoResize' => FALSE,
|
||||
'resizable' => 'w',
|
||||
'draggable' => FALSE,
|
||||
'drupalAutoButtons' => FALSE,
|
||||
'buttons' => [],
|
||||
'dialogClass' => 'ui-dialog-off-canvas',
|
||||
'width' => 300,
|
||||
],
|
||||
'effect' => 'fade',
|
||||
'speed' => 1000,
|
||||
];
|
||||
$this->assertEquals($expected, $command->render());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -104,52 +104,52 @@ class CssCollectionGrouperUnitTest extends UnitTestCase {
|
||||
|
||||
$groups = $this->grouper->group($css_assets);
|
||||
|
||||
$this->assertSame(count($groups), 5, "5 groups created.");
|
||||
$this->assertSame(5, count($groups), "5 groups created.");
|
||||
|
||||
// Check group 1.
|
||||
$group = $groups[0];
|
||||
$this->assertSame($group['group'], -100);
|
||||
$this->assertSame($group['type'], 'file');
|
||||
$this->assertSame($group['media'], 'all');
|
||||
$this->assertSame($group['preprocess'], TRUE);
|
||||
$this->assertSame(count($group['items']), 3);
|
||||
$this->assertSame(-100, $group['group']);
|
||||
$this->assertSame('file', $group['type']);
|
||||
$this->assertSame('all', $group['media']);
|
||||
$this->assertSame(TRUE, $group['preprocess']);
|
||||
$this->assertSame(3, count($group['items']));
|
||||
$this->assertContains($css_assets['system.base.css'], $group['items']);
|
||||
$this->assertContains($css_assets['js.module.css'], $group['items']);
|
||||
|
||||
// Check group 2.
|
||||
$group = $groups[1];
|
||||
$this->assertSame($group['group'], 0);
|
||||
$this->assertSame($group['type'], 'file');
|
||||
$this->assertSame($group['media'], 'all');
|
||||
$this->assertSame($group['preprocess'], TRUE);
|
||||
$this->assertSame(count($group['items']), 1);
|
||||
$this->assertSame(0, $group['group']);
|
||||
$this->assertSame('file', $group['type']);
|
||||
$this->assertSame('all', $group['media']);
|
||||
$this->assertSame(TRUE, $group['preprocess']);
|
||||
$this->assertSame(1, count($group['items']));
|
||||
$this->assertContains($css_assets['field.css'], $group['items']);
|
||||
|
||||
// Check group 3.
|
||||
$group = $groups[2];
|
||||
$this->assertSame($group['group'], 0);
|
||||
$this->assertSame($group['type'], 'external');
|
||||
$this->assertSame($group['media'], 'all');
|
||||
$this->assertSame($group['preprocess'], TRUE);
|
||||
$this->assertSame(count($group['items']), 1);
|
||||
$this->assertSame(0, $group['group']);
|
||||
$this->assertSame('external', $group['type']);
|
||||
$this->assertSame('all', $group['media']);
|
||||
$this->assertSame(TRUE, $group['preprocess']);
|
||||
$this->assertSame(1, count($group['items']));
|
||||
$this->assertContains($css_assets['external.css'], $group['items']);
|
||||
|
||||
// Check group 4.
|
||||
$group = $groups[3];
|
||||
$this->assertSame($group['group'], 100);
|
||||
$this->assertSame($group['type'], 'file');
|
||||
$this->assertSame($group['media'], 'all');
|
||||
$this->assertSame($group['preprocess'], TRUE);
|
||||
$this->assertSame(count($group['items']), 1);
|
||||
$this->assertSame(100, $group['group']);
|
||||
$this->assertSame('file', $group['type']);
|
||||
$this->assertSame('all', $group['media']);
|
||||
$this->assertSame(TRUE, $group['preprocess']);
|
||||
$this->assertSame(1, count($group['items']));
|
||||
$this->assertContains($css_assets['elements.css'], $group['items']);
|
||||
|
||||
// Check group 5.
|
||||
$group = $groups[4];
|
||||
$this->assertSame($group['group'], 100);
|
||||
$this->assertSame($group['type'], 'file');
|
||||
$this->assertSame($group['media'], 'print');
|
||||
$this->assertSame($group['preprocess'], TRUE);
|
||||
$this->assertSame(count($group['items']), 1);
|
||||
$this->assertSame(100, $group['group']);
|
||||
$this->assertSame('file', $group['type']);
|
||||
$this->assertSame('print', $group['media']);
|
||||
$this->assertSame(TRUE, $group['preprocess']);
|
||||
$this->assertSame(1, count($group['items']));
|
||||
$this->assertContains($css_assets['print.css'], $group['items']);
|
||||
}
|
||||
|
||||
|
||||
@@ -78,8 +78,8 @@ class AttributesTest extends UnitTestCase {
|
||||
$attributes['selected'] = $original_attributes['checked'];
|
||||
$attributes['id'] = $original_attributes['id'];
|
||||
$attributes = new Attribute($attributes);
|
||||
$this->assertSame((string) $original_attributes, ' checked class="who is on" id="first"', 'Original boolean value used with original name.');
|
||||
$this->assertSame((string) $attributes, ' selected id="first"', 'Original boolean value used with new name.');
|
||||
$this->assertSame(' checked class="who is on" id="first"', (string) $original_attributes, 'Original boolean value used with original name.');
|
||||
$this->assertSame(' selected id="first"', (string) $attributes, 'Original boolean value used with new name.');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ class DiffArrayTest extends UnitTestCase {
|
||||
'new' => 'new',
|
||||
];
|
||||
|
||||
$this->assertSame(DiffArray::diffAssocRecursive($this->array1, $this->array2), $expected);
|
||||
$this->assertSame($expected, DiffArray::diffAssocRecursive($this->array1, $this->array2));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -173,6 +173,7 @@ class ConfigTest extends UnitTestCase {
|
||||
* @covers ::setModuleOverride
|
||||
* @covers ::setSettingsOverride
|
||||
* @covers ::getOriginal
|
||||
* @covers ::hasOverrides
|
||||
* @dataProvider overrideDataProvider
|
||||
*/
|
||||
public function testOverrideData($data, $module_data, $setting_data) {
|
||||
@@ -184,26 +185,40 @@ class ConfigTest extends UnitTestCase {
|
||||
|
||||
// Save so that the original data is stored.
|
||||
$this->config->save();
|
||||
$this->assertFalse($this->config->hasOverrides());
|
||||
$this->assertOverriddenKeys($data, []);
|
||||
|
||||
// Set module override data and check value before and after save.
|
||||
$this->config->setModuleOverride($module_data);
|
||||
$this->assertConfigDataEquals($module_data);
|
||||
$this->assertOverriddenKeys($data, $module_data);
|
||||
|
||||
$this->config->save();
|
||||
$this->assertConfigDataEquals($module_data);
|
||||
$this->assertOverriddenKeys($data, $module_data);
|
||||
|
||||
// Reset the module overrides.
|
||||
$this->config->setModuleOverride([]);
|
||||
$this->assertOverriddenKeys($data, []);
|
||||
|
||||
// Set setting override data and check value before and after save.
|
||||
$this->config->setSettingsOverride($setting_data);
|
||||
$this->assertConfigDataEquals($setting_data);
|
||||
$this->assertOverriddenKeys($data, $setting_data);
|
||||
$this->config->save();
|
||||
$this->assertConfigDataEquals($setting_data);
|
||||
$this->assertOverriddenKeys($data, $setting_data);
|
||||
|
||||
// Set module overrides again to ensure override order is correct.
|
||||
$this->config->setModuleOverride($module_data);
|
||||
$merged_overrides = array_merge($module_data, $setting_data);
|
||||
|
||||
// Setting data should be overriding module data.
|
||||
$this->assertConfigDataEquals($setting_data);
|
||||
$this->assertOverriddenKeys($data, $merged_overrides);
|
||||
$this->config->save();
|
||||
$this->assertConfigDataEquals($setting_data);
|
||||
$this->assertOverriddenKeys($data, $merged_overrides);
|
||||
|
||||
// Check original data has not changed.
|
||||
$this->assertOriginalConfigDataEquals($data, FALSE);
|
||||
@@ -216,6 +231,15 @@ class ConfigTest extends UnitTestCase {
|
||||
$config_value = $this->config->getOriginal($key);
|
||||
$this->assertEquals($value, $config_value);
|
||||
}
|
||||
|
||||
// Check that the overrides can be completely reset.
|
||||
$this->config->setModuleOverride([]);
|
||||
$this->config->setSettingsOverride([]);
|
||||
$this->assertConfigDataEquals($data);
|
||||
$this->assertOverriddenKeys($data, []);
|
||||
$this->config->save();
|
||||
$this->assertConfigDataEquals($data);
|
||||
$this->assertOverriddenKeys($data, []);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -434,7 +458,7 @@ class ConfigTest extends UnitTestCase {
|
||||
* @see \Drupal\Tests\Core\Config\ConfigTest::testDelete()
|
||||
*/
|
||||
public function overrideDataProvider() {
|
||||
return [
|
||||
$test_cases = [
|
||||
[
|
||||
// Original data.
|
||||
[
|
||||
@@ -449,7 +473,57 @@ class ConfigTest extends UnitTestCase {
|
||||
'a' => 'settingValue',
|
||||
],
|
||||
],
|
||||
[
|
||||
// Original data.
|
||||
[
|
||||
'a' => 'originalValue',
|
||||
'b' => 'originalValue',
|
||||
'c' => 'originalValue',
|
||||
],
|
||||
// Module overrides.
|
||||
[
|
||||
'a' => 'moduleValue',
|
||||
'b' => 'moduleValue',
|
||||
],
|
||||
// Setting overrides.
|
||||
[
|
||||
'a' => 'settingValue',
|
||||
],
|
||||
],
|
||||
[
|
||||
// Original data.
|
||||
[
|
||||
'a' => 'allTheSameValue',
|
||||
],
|
||||
// Module overrides.
|
||||
[
|
||||
'a' => 'allTheSameValue',
|
||||
],
|
||||
// Setting overrides.
|
||||
[
|
||||
'a' => 'allTheSameValue',
|
||||
],
|
||||
],
|
||||
];
|
||||
// For each of the above test cases create duplicate test case except with
|
||||
// config values nested.
|
||||
foreach ($test_cases as $test_key => $test_case) {
|
||||
foreach ($test_case as $parameter) {
|
||||
$nested_parameter = [];
|
||||
foreach ($parameter as $config_key => $value) {
|
||||
// Nest config value 5 levels.
|
||||
$nested_value = $value;
|
||||
for ($i = 5; $i >= 0; $i--) {
|
||||
$nested_value = [
|
||||
$i => $nested_value,
|
||||
];
|
||||
}
|
||||
$nested_parameter[$config_key] = $nested_value;
|
||||
}
|
||||
$test_cases["nested:$test_key"][] = $nested_parameter;
|
||||
}
|
||||
}
|
||||
return $test_cases;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -545,4 +619,49 @@ class ConfigTest extends UnitTestCase {
|
||||
$this->assertSame($safe_string, $this->config->get('bar'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the correct keys are overridden.
|
||||
*
|
||||
* @param array $data
|
||||
* The original data.
|
||||
* @param array $overridden_data
|
||||
* The overridden data.
|
||||
*/
|
||||
protected function assertOverriddenKeys(array $data, array $overridden_data) {
|
||||
if (empty($overridden_data)) {
|
||||
$this->assertFalse($this->config->hasOverrides());
|
||||
}
|
||||
else {
|
||||
$this->assertTrue($this->config->hasOverrides());
|
||||
foreach ($overridden_data as $key => $value) {
|
||||
// If there are nested overrides test a keys at every level.
|
||||
if (is_array($value)) {
|
||||
$nested_key = $key;
|
||||
$nested_value = $overridden_data[$key];
|
||||
while (is_array($nested_value)) {
|
||||
$nested_key .= '.' . key($nested_value);
|
||||
$this->assertTrue($this->config->hasOverrides($nested_key));
|
||||
$nested_value = array_pop($nested_value);
|
||||
}
|
||||
}
|
||||
$this->assertTrue($this->config->hasOverrides($key));
|
||||
}
|
||||
}
|
||||
|
||||
$non_overridden_keys = array_diff(array_keys($data), array_keys($overridden_data));
|
||||
foreach ($non_overridden_keys as $non_overridden_key) {
|
||||
$this->assertFalse($this->config->hasOverrides($non_overridden_key));
|
||||
// If there are nested overrides test keys at every level.
|
||||
if (is_array($data[$non_overridden_key])) {
|
||||
$nested_key = $non_overridden_key;
|
||||
$nested_value = $data[$non_overridden_key];
|
||||
while (is_array($nested_value)) {
|
||||
$nested_key .= '.' . key($nested_value);
|
||||
$this->assertFalse($this->config->hasOverrides($nested_key));
|
||||
$nested_value = array_pop($nested_value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace Drupal\Tests\Core\Config\Entity;
|
||||
use Drupal\Component\Plugin\PluginManagerInterface;
|
||||
use Drupal\Core\Config\Schema\SchemaIncompleteException;
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Language\Language;
|
||||
use Drupal\Core\Plugin\DefaultLazyPluginCollection;
|
||||
use Drupal\Tests\Core\Config\Entity\Fixtures\ConfigEntityBaseWithPluginCollections;
|
||||
@@ -37,11 +38,11 @@ class ConfigEntityBaseUnitTest extends UnitTestCase {
|
||||
protected $entityType;
|
||||
|
||||
/**
|
||||
* The entity manager used for testing.
|
||||
* The entity type manager used for testing.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $entityManager;
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* The ID of the type of the entity under test.
|
||||
@@ -112,8 +113,8 @@ class ConfigEntityBaseUnitTest extends UnitTestCase {
|
||||
->method('getConfigPrefix')
|
||||
->willReturn('test_provider.' . $this->entityTypeId);
|
||||
|
||||
$this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface');
|
||||
$this->entityManager->expects($this->any())
|
||||
$this->entityTypeManager = $this->getMock(EntityTypeManagerInterface::class);
|
||||
$this->entityTypeManager->expects($this->any())
|
||||
->method('getDefinition')
|
||||
->with($this->entityTypeId)
|
||||
->will($this->returnValue($this->entityType));
|
||||
@@ -131,7 +132,7 @@ class ConfigEntityBaseUnitTest extends UnitTestCase {
|
||||
$this->typedConfigManager = $this->getMock('Drupal\Core\Config\TypedConfigManagerInterface');
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
$container->set('entity.manager', $this->entityManager);
|
||||
$container->set('entity_type.manager', $this->entityTypeManager);
|
||||
$container->set('uuid', $this->uuid);
|
||||
$container->set('language_manager', $this->languageManager);
|
||||
$container->set('cache_tags.invalidator', $this->cacheTagsInvalidator);
|
||||
@@ -468,7 +469,7 @@ class ConfigEntityBaseUnitTest extends UnitTestCase {
|
||||
* @covers ::sort
|
||||
*/
|
||||
public function testSort() {
|
||||
$this->entityManager->expects($this->any())
|
||||
$this->entityTypeManager->expects($this->any())
|
||||
->method('getDefinition')
|
||||
->with($this->entityTypeId)
|
||||
->will($this->returnValue([
|
||||
|
||||
@@ -17,8 +17,8 @@ use Drupal\Core\Config\ImmutableConfig;
|
||||
use Drupal\Core\Config\TypedConfigManagerInterface;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityMalformedException;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Entity\EntityStorageException;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Entity\Query\QueryFactoryInterface;
|
||||
use Drupal\Core\Entity\Query\QueryInterface;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
@@ -136,8 +136,8 @@ class ConfigEntityStorageTest extends UnitTestCase {
|
||||
$this->entityStorage = new ConfigEntityStorage($entity_type, $this->configFactory->reveal(), $this->uuidService->reveal(), $this->languageManager->reveal());
|
||||
$this->entityStorage->setModuleHandler($this->moduleHandler->reveal());
|
||||
|
||||
$entity_manager = $this->prophesize(EntityManagerInterface::class);
|
||||
$entity_manager->getDefinition('test_entity_type')->willReturn($entity_type);
|
||||
$entity_type_manager = $this->prophesize(EntityTypeManagerInterface::class);
|
||||
$entity_type_manager->getDefinition('test_entity_type')->willReturn($entity_type);
|
||||
|
||||
$this->cacheTagsInvalidator = $this->prophesize(CacheTagsInvalidatorInterface::class);
|
||||
|
||||
@@ -149,7 +149,7 @@ class ConfigEntityStorageTest extends UnitTestCase {
|
||||
$this->configManager = $this->prophesize(ConfigManagerInterface::class);
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
$container->set('entity.manager', $entity_manager->reveal());
|
||||
$container->set('entity_type.manager', $entity_type_manager->reveal());
|
||||
$container->set('entity.query.config', $entity_query_factory->reveal());
|
||||
$container->set('config.typed', $typed_config_manager->reveal());
|
||||
$container->set('cache_tags.invalidator', $this->cacheTagsInvalidator->reveal());
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
namespace Drupal\Tests\Core\Config\Entity;
|
||||
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\Core\Entity\EntityManager;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
@@ -32,6 +34,13 @@ class EntityDisplayModeBaseUnitTest extends UnitTestCase {
|
||||
*/
|
||||
protected $entityManager;
|
||||
|
||||
/**
|
||||
* The entity type manager used for testing.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* The ID of the type of the entity under test.
|
||||
*
|
||||
@@ -57,13 +66,21 @@ class EntityDisplayModeBaseUnitTest extends UnitTestCase {
|
||||
->method('getProvider')
|
||||
->will($this->returnValue('entity'));
|
||||
|
||||
$this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface');
|
||||
$this->entityTypeManager = $this->getMock(EntityTypeManagerInterface::class);
|
||||
|
||||
$this->entityManager = new EntityManager();
|
||||
|
||||
$this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface');
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
$container->set('entity.manager', $this->entityManager);
|
||||
$container->set('entity_type.manager', $this->entityTypeManager);
|
||||
$container->set('uuid', $this->uuid);
|
||||
|
||||
// Inject the container into entity.manager so it can defer to
|
||||
// entity_type.manager.
|
||||
$this->entityManager->setContainer($container);
|
||||
|
||||
\Drupal::setContainer($container);
|
||||
}
|
||||
|
||||
@@ -79,11 +96,11 @@ class EntityDisplayModeBaseUnitTest extends UnitTestCase {
|
||||
->will($this->returnValue('test_module'));
|
||||
$values = ['targetEntityType' => $target_entity_type_id];
|
||||
|
||||
$this->entityManager->expects($this->at(0))
|
||||
$this->entityTypeManager->expects($this->at(0))
|
||||
->method('getDefinition')
|
||||
->with($target_entity_type_id)
|
||||
->will($this->returnValue($target_entity_type));
|
||||
$this->entityManager->expects($this->at(1))
|
||||
$this->entityTypeManager->expects($this->at(1))
|
||||
->method('getDefinition')
|
||||
->with($this->entityType)
|
||||
->will($this->returnValue($this->entityInfo));
|
||||
|
||||
@@ -156,6 +156,18 @@ class DrupalDateTimeTest extends UnitTestCase {
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests setting the default time for date-only objects.
|
||||
*/
|
||||
public function testDefaultDateTime() {
|
||||
$utc = new \DateTimeZone('UTC');
|
||||
|
||||
$date = DrupalDateTime::createFromFormat('Y-m-d H:i:s', '2017-05-23 22:58:00', $utc, ['langcode' => 'en']);
|
||||
$this->assertEquals('22:58:00', $date->format('H:i:s'));
|
||||
$date->setDefaultDateTime();
|
||||
$this->assertEquals('12:00:00', $date->format('H:i:s'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that object methods are chainable.
|
||||
*
|
||||
|
||||
@@ -39,7 +39,7 @@ class ProxyServicesPassTest extends UnitTestCase {
|
||||
|
||||
$this->proxyServicesPass->process($container);
|
||||
|
||||
$this->assertCount(1, $container->getDefinitions());
|
||||
$this->assertCount(2, $container->getDefinitions());
|
||||
$this->assertEquals('Drupal\Core\Plugin\CachedDiscoveryClearer', $container->getDefinition('plugin_cache_clearer')->getClass());
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ class ProxyServicesPassTest extends UnitTestCase {
|
||||
|
||||
$this->proxyServicesPass->process($container);
|
||||
|
||||
$this->assertCount(2, $container->getDefinitions());
|
||||
$this->assertCount(3, $container->getDefinitions());
|
||||
|
||||
$non_proxy_definition = $container->getDefinition('drupal.proxy_original_service.plugin_cache_clearer');
|
||||
$this->assertEquals('Drupal\Core\Plugin\CachedDiscoveryClearer', $non_proxy_definition->getClass());
|
||||
|
||||
@@ -51,12 +51,12 @@ class StackedKernelPassTest extends UnitTestCase {
|
||||
$stacked_kernel_args = $this->containerBuilder->getDefinition('http_kernel')->getArguments();
|
||||
|
||||
// Check the stacked kernel args.
|
||||
$this->assertSame((string) $stacked_kernel_args[0], 'http_kernel.one');
|
||||
$this->assertSame('http_kernel.one', (string) $stacked_kernel_args[0]);
|
||||
$this->assertCount(4, $stacked_kernel_args[1]);
|
||||
$this->assertSame((string) $stacked_kernel_args[1][0], 'http_kernel.one');
|
||||
$this->assertSame((string) $stacked_kernel_args[1][1], 'http_kernel.two');
|
||||
$this->assertSame((string) $stacked_kernel_args[1][2], 'http_kernel.three');
|
||||
$this->assertSame((string) $stacked_kernel_args[1][3], 'http_kernel.basic');
|
||||
$this->assertSame('http_kernel.one', (string) $stacked_kernel_args[1][0]);
|
||||
$this->assertSame('http_kernel.two', (string) $stacked_kernel_args[1][1]);
|
||||
$this->assertSame('http_kernel.three', (string) $stacked_kernel_args[1][2]);
|
||||
$this->assertSame('http_kernel.basic', (string) $stacked_kernel_args[1][3]);
|
||||
|
||||
// Check the modified definitions.
|
||||
$definition = $this->containerBuilder->getDefinition('http_kernel.one');
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ class TaggedHandlersPassTest extends UnitTestCase {
|
||||
$handler_pass = new TaggedHandlersPass();
|
||||
$handler_pass->process($container);
|
||||
|
||||
$this->assertCount(1, $container->getDefinitions());
|
||||
$this->assertCount(2, $container->getDefinitions());
|
||||
$this->assertFalse($container->getDefinition('consumer_id')->hasMethodCall('addHandler'));
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace Drupal\Tests\Core\DependencyInjection;
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\Tests\Core\DependencyInjection\Fixture\BarClass;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Core\DependencyInjection\ContainerBuilder
|
||||
@@ -61,6 +62,53 @@ class ContainerBuilderTest extends UnitTestCase {
|
||||
$container->register('Bar');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::register
|
||||
*/
|
||||
public function testRegister() {
|
||||
$container = new ContainerBuilder();
|
||||
$service = $container->register('bar');
|
||||
$this->assertTrue($service->isPublic());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::setDefinition
|
||||
*/
|
||||
public function testSetDefinition() {
|
||||
// Test a service with defaults.
|
||||
$container = new ContainerBuilder();
|
||||
$definition = new Definition();
|
||||
$service = $container->setDefinition('foo', $definition);
|
||||
$this->assertTrue($service->isPublic());
|
||||
$this->assertFalse($service->isPrivate());
|
||||
|
||||
// Test a service with public set to false.
|
||||
$definition = new Definition();
|
||||
$definition->setPublic(FALSE);
|
||||
$service = $container->setDefinition('foo', $definition);
|
||||
$this->assertFalse($service->isPublic());
|
||||
$this->assertFalse($service->isPrivate());
|
||||
|
||||
// Test a service with private set to true. Drupal does not support this.
|
||||
// We only support using setPublic() to make things not available outside
|
||||
// the container.
|
||||
$definition = new Definition();
|
||||
$definition->setPrivate(TRUE);
|
||||
$service = $container->setDefinition('foo', $definition);
|
||||
$this->assertTrue($service->isPublic());
|
||||
$this->assertFalse($service->isPrivate());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::setAlias
|
||||
*/
|
||||
public function testSetAlias() {
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('bar');
|
||||
$alias = $container->setAlias('foo', 'bar');
|
||||
$this->assertTrue($alias->isPublic());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests serialization.
|
||||
*/
|
||||
@@ -70,4 +118,27 @@ class ContainerBuilderTest extends UnitTestCase {
|
||||
serialize($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests constructor and resource tracking disabling.
|
||||
*
|
||||
* This test runs in a separate process to ensure the aliased class does not
|
||||
* affect any other tests.
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
public function testConstructor() {
|
||||
class_alias(testInterface::class, 'Symfony\Component\Config\Resource\ResourceInterface');
|
||||
$container = new ContainerBuilder();
|
||||
$this->assertFalse($container->isTrackingResources());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A test interface for testing ContainerBuilder::__construct().
|
||||
*
|
||||
* @see \Drupal\Tests\Core\DependencyInjection\ContainerBuilderTest::testConstructor()
|
||||
*/
|
||||
interface testInterface {
|
||||
}
|
||||
|
||||
@@ -28,6 +28,9 @@ class YamlFileLoaderTest extends UnitTestCase {
|
||||
services:
|
||||
example_service:
|
||||
class: \Drupal\Core\ExampleClass
|
||||
example_private_service:
|
||||
class: \Drupal\Core\ExampleClass
|
||||
public: false
|
||||
YAML;
|
||||
|
||||
vfsStream::setup('drupal', NULL, [
|
||||
@@ -39,6 +42,11 @@ YAML;
|
||||
$yaml_file_loader->load('vfs://drupal/modules/example/example.yml');
|
||||
|
||||
$this->assertEquals(['_provider' => [['provider' => 'example']]], $builder->getDefinition('example_service')->getTags());
|
||||
$this->assertTrue($builder->getDefinition('example_service')->isPublic());
|
||||
$this->assertFalse($builder->getDefinition('example_private_service')->isPublic());
|
||||
$builder->compile();
|
||||
$this->assertTrue($builder->has('example_service'));
|
||||
$this->assertFalse($builder->has('example_private_service'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,20 +30,16 @@ class EntityRevisionRouteEnhancerTest extends UnitTestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::applies
|
||||
* @dataProvider providerTestApplies
|
||||
* @covers ::enhance
|
||||
*/
|
||||
public function testApplies(Route $route, $expected) {
|
||||
$this->assertEquals($expected, $this->routeEnhancer->applies($route));
|
||||
}
|
||||
public function testEnhanceWithoutParameter() {
|
||||
$route = new Route('/test-path/{entity_test}');
|
||||
|
||||
public function providerTestApplies() {
|
||||
$data = [];
|
||||
$data['no-parameter'] = [new Route('/test-path'), FALSE];
|
||||
$data['none-revision-parameters'] = [new Route('/test-path/{entity_test}', [], [], ['parameters' => ['entity_test' => ['type' => 'entity:entity_test']]]), FALSE];
|
||||
$data['with-revision-parameter'] = [new Route('/test-path/{entity_test_revision}', [], [], ['parameters' => ['entity_test_revision' => ['type' => 'entity_revision:entity_test']]]), TRUE];
|
||||
$request = Request::create('/test-path');
|
||||
|
||||
return $data;
|
||||
$defaults = [];
|
||||
$defaults[RouteObjectInterface::ROUTE_OBJECT] = $route;
|
||||
$this->assertEquals($defaults, $this->routeEnhancer->enhance($defaults, $request));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+240
@@ -0,0 +1,240 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\Core\Entity\Access;
|
||||
|
||||
use Drupal\Component\Plugin\PluginManagerInterface;
|
||||
use Drupal\Component\Uuid\UuidInterface;
|
||||
use Drupal\Core\Cache\Context\CacheContextsManager;
|
||||
use Drupal\Core\Config\Entity\ConfigEntityTypeInterface;
|
||||
use Drupal\Core\DependencyInjection\Container;
|
||||
use Drupal\Core\Entity\Entity\Access\EntityFormDisplayAccessControlHandler;
|
||||
use Drupal\Core\Entity\Entity\EntityFormDisplay;
|
||||
use Drupal\Core\Entity\EntityFieldManagerInterface;
|
||||
use Drupal\Core\Entity\EntityManager;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Field\FieldTypePluginManagerInterface;
|
||||
use Drupal\Core\Field\FormatterPluginManager;
|
||||
use Drupal\Core\Language\LanguageManagerInterface;
|
||||
use Drupal\Core\Render\RendererInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Core\Entity\Entity\Access\EntityFormDisplayAccessControlHandler
|
||||
* @group Entity
|
||||
*/
|
||||
class EntityFormDisplayAccessControlHandlerTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* The field storage config access controller to test.
|
||||
*
|
||||
* @var \Drupal\field\FieldStorageConfigAccessControlHandler
|
||||
*/
|
||||
protected $accessControlHandler;
|
||||
|
||||
/**
|
||||
* The mock module handler.
|
||||
*
|
||||
* @var \Drupal\Core\Extension\ModuleHandlerInterface
|
||||
*/
|
||||
protected $moduleHandler;
|
||||
|
||||
/**
|
||||
* The mock account without field storage config access.
|
||||
*
|
||||
* @var \Drupal\Core\Session\AccountInterface
|
||||
*/
|
||||
protected $anon;
|
||||
|
||||
/**
|
||||
* The mock account with EntityFormDisplay access.
|
||||
*
|
||||
* @var \Drupal\Core\Session\AccountInterface
|
||||
*/
|
||||
protected $member;
|
||||
|
||||
/**
|
||||
* The mock account with EntityFormDisplay access via parent access check.
|
||||
*
|
||||
* @var \Drupal\Core\Session\AccountInterface
|
||||
*/
|
||||
protected $parent_member;
|
||||
|
||||
/**
|
||||
* The EntityFormDisplay entity used for testing.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface
|
||||
*/
|
||||
protected $entity;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a mock Entity Type Manager.
|
||||
*
|
||||
* @return \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
* The mocked entity type manager.
|
||||
*/
|
||||
protected function getEntityTypeManager() {
|
||||
$entity_type_manager = $this->prophesize(EntityTypeManagerInterface::class);
|
||||
return $entity_type_manager->reveal();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->anon = $this->getMock(AccountInterface::class);
|
||||
$this->anon
|
||||
->expects($this->any())
|
||||
->method('hasPermission')
|
||||
->will($this->returnValue(FALSE));
|
||||
$this->anon
|
||||
->expects($this->any())
|
||||
->method('id')
|
||||
->will($this->returnValue(0));
|
||||
|
||||
$this->member = $this->getMock(AccountInterface::class);
|
||||
$this->member
|
||||
->expects($this->any())
|
||||
->method('hasPermission')
|
||||
->will($this->returnValueMap([
|
||||
['administer foobar form display', TRUE],
|
||||
]));
|
||||
$this->member
|
||||
->expects($this->any())
|
||||
->method('id')
|
||||
->will($this->returnValue(2));
|
||||
|
||||
$this->parent_member = $this->getMock(AccountInterface::class);
|
||||
$this->parent_member
|
||||
->expects($this->any())
|
||||
->method('hasPermission')
|
||||
->will($this->returnValueMap([
|
||||
['Llama', TRUE],
|
||||
]));
|
||||
$this->parent_member
|
||||
->expects($this->any())
|
||||
->method('id')
|
||||
->will($this->returnValue(3));
|
||||
|
||||
$entity_form_display_entity_type = $this->getMock(ConfigEntityTypeInterface::class);
|
||||
$entity_form_display_entity_type->expects($this->any())
|
||||
->method('getAdminPermission')
|
||||
->will($this->returnValue('Llama'));
|
||||
$entity_form_display_entity_type
|
||||
->expects($this->any())
|
||||
->method('getKey')
|
||||
->will($this->returnValueMap([
|
||||
['langcode', 'langcode'],
|
||||
]));
|
||||
$entity_form_display_entity_type->expects($this->any())
|
||||
->method('entityClassImplements')
|
||||
->will($this->returnValue(TRUE));
|
||||
$entity_form_display_entity_type->expects($this->any())
|
||||
->method('getConfigPrefix')
|
||||
->willReturn('');
|
||||
|
||||
$this->moduleHandler = $this->getMock(ModuleHandlerInterface::class);
|
||||
$this->moduleHandler
|
||||
->expects($this->any())
|
||||
->method('getImplementations')
|
||||
->will($this->returnValue([]));
|
||||
$this->moduleHandler
|
||||
->expects($this->any())
|
||||
->method('invokeAll')
|
||||
->will($this->returnValue([]));
|
||||
|
||||
$storage_access_control_handler = new EntityFormDisplayAccessControlHandler($entity_form_display_entity_type);
|
||||
$storage_access_control_handler->setModuleHandler($this->moduleHandler);
|
||||
|
||||
$entity_type_manager = $this->getMock(EntityTypeManagerInterface::class);
|
||||
$entity_type_manager
|
||||
->expects($this->any())
|
||||
->method('getStorage')
|
||||
->willReturnMap([
|
||||
['entity_display', $this->getMock(EntityStorageInterface::class)],
|
||||
]);
|
||||
$entity_type_manager
|
||||
->expects($this->any())
|
||||
->method('getAccessControlHandler')
|
||||
->willReturnMap([
|
||||
['entity_display', $storage_access_control_handler],
|
||||
]);
|
||||
$entity_type_manager
|
||||
->expects($this->any())
|
||||
->method('getDefinition')
|
||||
->will($this->returnValue($entity_form_display_entity_type));
|
||||
|
||||
$entity_field_manager = $this->getMock(EntityFieldManagerInterface::class);
|
||||
$entity_field_manager->expects($this->any())
|
||||
->method('getFieldDefinitions')
|
||||
->will($this->returnValue([]));
|
||||
|
||||
$entity_manager = new EntityManager();
|
||||
$container = new Container();
|
||||
$container->set('entity.manager', $entity_manager);
|
||||
$container->set('entity_type.manager', $entity_type_manager);
|
||||
$container->set('entity_field.manager', $entity_field_manager);
|
||||
$container->set('language_manager', $this->getMock(LanguageManagerInterface::class));
|
||||
$container->set('plugin.manager.field.widget', $this->prophesize(PluginManagerInterface::class));
|
||||
$container->set('plugin.manager.field.field_type', $this->getMock(FieldTypePluginManagerInterface::class));
|
||||
$container->set('plugin.manager.field.formatter', $this->prophesize(FormatterPluginManager::class));
|
||||
$container->set('uuid', $this->getMock(UuidInterface::class));
|
||||
$container->set('renderer', $this->getMock(RendererInterface::class));
|
||||
$container->set('cache_contexts_manager', $this->prophesize(CacheContextsManager::class));
|
||||
// Inject the container into entity.manager so it can defer to
|
||||
// entity_type.manager.
|
||||
$entity_manager->setContainer($container);
|
||||
\Drupal::setContainer($container);
|
||||
|
||||
$this->entity = new EntityFormDisplay([
|
||||
'targetEntityType' => 'foobar',
|
||||
'bundle' => 'bazqux',
|
||||
'mode' => 'default',
|
||||
'id' => 'foobar.bazqux.default',
|
||||
'uuid' => '6f2f259a-f3c7-42ea-bdd5-111ad1f85ed1',
|
||||
], 'entity_display');
|
||||
|
||||
$this->accessControlHandler = $storage_access_control_handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert method to verify the access by operations.
|
||||
*
|
||||
* @param array $allow_operations
|
||||
* A list of allowed operations.
|
||||
* @param \Drupal\Core\Session\AccountInterface $user
|
||||
* The account to use for get access.
|
||||
*/
|
||||
public function assertAllowOperations(array $allow_operations, AccountInterface $user) {
|
||||
foreach (['view', 'update', 'delete'] as $operation) {
|
||||
$expected = in_array($operation, $allow_operations);
|
||||
$actual = $this->accessControlHandler->access($this->entity, $operation, $user);
|
||||
$this->assertSame($expected, $actual, "Access problem with '$operation' operation.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::access
|
||||
* @covers ::checkAccess
|
||||
*/
|
||||
public function testAccess() {
|
||||
$this->assertAllowOperations([], $this->anon);
|
||||
$this->assertAllowOperations(['view', 'update', 'delete'], $this->member);
|
||||
$this->assertAllowOperations(['view', 'update', 'delete'], $this->parent_member);
|
||||
|
||||
$this->entity->enforceIsNew(TRUE)->save();
|
||||
// Unfortunately, EntityAccessControlHandler has a static cache, which we
|
||||
// therefore must reset manually.
|
||||
$this->accessControlHandler->resetCache();
|
||||
|
||||
$this->assertAllowOperations([], $this->anon);
|
||||
$this->assertAllowOperations(['view', 'update'], $this->member);
|
||||
$this->assertAllowOperations(['view', 'update'], $this->parent_member);
|
||||
}
|
||||
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\Core\Entity\Access;
|
||||
|
||||
use Drupal\Core\Entity\Entity\Access\EntityViewDisplayAccessControlHandler;
|
||||
use Drupal\Core\Entity\Entity\EntityViewDisplay;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Core\Entity\Entity\Access\EntityViewDisplayAccessControlHandler
|
||||
* @group Entity
|
||||
*/
|
||||
class EntityViewDisplayAccessControlHandlerTest extends EntityFormDisplayAccessControlHandlerTest {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->member = $this->getMock(AccountInterface::class);
|
||||
$this->member
|
||||
->expects($this->any())
|
||||
->method('hasPermission')
|
||||
->will($this->returnValueMap([
|
||||
['administer foobar display', TRUE],
|
||||
]));
|
||||
$this->member
|
||||
->expects($this->any())
|
||||
->method('id')
|
||||
->will($this->returnValue(2));
|
||||
|
||||
$this->entity = new EntityViewDisplay([
|
||||
'targetEntityType' => 'foobar',
|
||||
'bundle' => 'bazqux',
|
||||
'mode' => 'default',
|
||||
'id' => 'foobar.bazqux.default',
|
||||
'uuid' => '6f2f259a-f3c7-42ea-bdd5-111ad1f85ed1',
|
||||
], 'entity_display');
|
||||
$this->accessControlHandler = new EntityViewDisplayAccessControlHandler($this->entity->getEntityType());
|
||||
$this->accessControlHandler->setModuleHandler($this->moduleHandler);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,7 +4,12 @@ namespace Drupal\Tests\Core\Entity;
|
||||
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\Core\Entity\ContentEntityBase;
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\EntityFieldManagerInterface;
|
||||
use Drupal\Core\Entity\EntityManager;
|
||||
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\Core\TypedData\TypedDataManagerInterface;
|
||||
@@ -54,6 +59,27 @@ class ContentEntityBaseUnitTest extends UnitTestCase {
|
||||
*/
|
||||
protected $entityManager;
|
||||
|
||||
/**
|
||||
* The entity field manager used for testing.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityFieldManagerInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $entityFieldManager;
|
||||
|
||||
/**
|
||||
* The entity type bundle manager used for testing.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $entityTypeBundleInfo;
|
||||
|
||||
/**
|
||||
* The entity type manager used for testing.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* The type ID of the entity under test.
|
||||
*
|
||||
@@ -124,12 +150,18 @@ class ContentEntityBaseUnitTest extends UnitTestCase {
|
||||
'uuid' => 'uuid',
|
||||
]));
|
||||
|
||||
$this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface');
|
||||
$this->entityManager->expects($this->any())
|
||||
$this->entityManager = new EntityManager();
|
||||
|
||||
$this->entityTypeManager = $this->getMock(EntityTypeManagerInterface::class);
|
||||
$this->entityTypeManager->expects($this->any())
|
||||
->method('getDefinition')
|
||||
->with($this->entityTypeId)
|
||||
->will($this->returnValue($this->entityType));
|
||||
|
||||
$this->entityFieldManager = $this->getMock(EntityFieldManagerInterface::class);
|
||||
|
||||
$this->entityTypeBundleInfo = $this->getMock(EntityTypeBundleInfoInterface::class);
|
||||
|
||||
$this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface');
|
||||
|
||||
$this->typedDataManager = $this->getMock(TypedDataManagerInterface::class);
|
||||
@@ -168,10 +200,16 @@ class ContentEntityBaseUnitTest extends UnitTestCase {
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
$container->set('entity.manager', $this->entityManager);
|
||||
$container->set('entity_field.manager', $this->entityFieldManager);
|
||||
$container->set('entity_type.bundle.info', $this->entityTypeBundleInfo);
|
||||
$container->set('entity_type.manager', $this->entityTypeManager);
|
||||
$container->set('uuid', $this->uuid);
|
||||
$container->set('typed_data_manager', $this->typedDataManager);
|
||||
$container->set('language_manager', $this->languageManager);
|
||||
$container->set('plugin.manager.field.field_type', $this->fieldTypePluginManager);
|
||||
// Inject the container into entity.manager so it can defer to
|
||||
// entity_type.manager and other services.
|
||||
$this->entityManager->setContainer($container);
|
||||
\Drupal::setContainer($container);
|
||||
|
||||
$this->fieldDefinitions = [
|
||||
@@ -179,14 +217,14 @@ class ContentEntityBaseUnitTest extends UnitTestCase {
|
||||
'revision_id' => BaseFieldDefinition::create('integer'),
|
||||
];
|
||||
|
||||
$this->entityManager->expects($this->any())
|
||||
$this->entityFieldManager->expects($this->any())
|
||||
->method('getFieldDefinitions')
|
||||
->with($this->entityTypeId, $this->bundle)
|
||||
->will($this->returnValue($this->fieldDefinitions));
|
||||
|
||||
$this->entity = $this->getMockForAbstractClass('\Drupal\Core\Entity\ContentEntityBase', [$values, $this->entityTypeId, $this->bundle], '', TRUE, TRUE, TRUE, ['isNew']);
|
||||
$this->entity = $this->getMockForAbstractClass(ContentEntityBase::class, [$values, $this->entityTypeId, $this->bundle], '', TRUE, TRUE, TRUE, ['isNew']);
|
||||
$values['defaultLangcode'] = [LanguageInterface::LANGCODE_DEFAULT => LanguageInterface::LANGCODE_NOT_SPECIFIED];
|
||||
$this->entityUnd = $this->getMockForAbstractClass('\Drupal\Core\Entity\ContentEntityBase', [$values, $this->entityTypeId, $this->bundle]);
|
||||
$this->entityUnd = $this->getMockForAbstractClass(ContentEntityBase::class, [$values, $this->entityTypeId, $this->bundle]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -283,7 +321,7 @@ class ContentEntityBaseUnitTest extends UnitTestCase {
|
||||
* @covers ::isTranslatable
|
||||
*/
|
||||
public function testIsTranslatable() {
|
||||
$this->entityManager->expects($this->any())
|
||||
$this->entityTypeBundleInfo->expects($this->any())
|
||||
->method('getBundleInfo')
|
||||
->with($this->entityTypeId)
|
||||
->will($this->returnValue([
|
||||
@@ -382,7 +420,7 @@ class ContentEntityBaseUnitTest extends UnitTestCase {
|
||||
$entity->preSave($storage);
|
||||
});
|
||||
|
||||
$this->entityManager->expects($this->any())
|
||||
$this->entityTypeManager->expects($this->any())
|
||||
->method('getStorage')
|
||||
->with($this->entityTypeId)
|
||||
->will($this->returnValue($storage));
|
||||
@@ -434,7 +472,7 @@ class ContentEntityBaseUnitTest extends UnitTestCase {
|
||||
$access->expects($this->at(3))
|
||||
->method('createAccess')
|
||||
->will($this->returnValue(AccessResult::allowed()));
|
||||
$this->entityManager->expects($this->exactly(4))
|
||||
$this->entityTypeManager->expects($this->exactly(4))
|
||||
->method('getAccessControlHandler')
|
||||
->will($this->returnValue($access));
|
||||
$this->assertTrue($this->entity->access($operation));
|
||||
|
||||
@@ -6,6 +6,7 @@ use Drupal\Core\Entity\Enhancer\EntityRouteEnhancer;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Core\Entity\Enhancer\EntityRouteEnhancer
|
||||
@@ -26,6 +27,7 @@ class EntityRouteEnhancerTest extends UnitTestCase {
|
||||
$defaults = [];
|
||||
$defaults['_controller'] = 'Drupal\Tests\Core\Controller\TestController::content';
|
||||
$defaults['_entity_form'] = 'entity_test.default';
|
||||
$defaults['_route_object'] = (new Route('/test', $defaults));
|
||||
$new_defaults = $route_enhancer->enhance($defaults, $request);
|
||||
$this->assertTrue(is_callable($new_defaults['_controller']));
|
||||
$this->assertEquals($defaults['_controller'], $new_defaults['_controller'], '_controller did not get overridden.');
|
||||
@@ -33,12 +35,14 @@ class EntityRouteEnhancerTest extends UnitTestCase {
|
||||
// Set _entity_form and ensure that the form is set.
|
||||
$defaults = [];
|
||||
$defaults['_entity_form'] = 'entity_test.default';
|
||||
$defaults['_route_object'] = (new Route('/test', $defaults));
|
||||
$new_defaults = $route_enhancer->enhance($defaults, $request);
|
||||
$this->assertEquals('controller.entity_form:getContentResult', $new_defaults['_controller']);
|
||||
|
||||
// Set _entity_list and ensure that the entity list controller is set.
|
||||
$defaults = [];
|
||||
$defaults['_entity_list'] = 'entity_test.default';
|
||||
$defaults['_route_object'] = (new Route('/test', $defaults));
|
||||
$new_defaults = $route_enhancer->enhance($defaults, $request);
|
||||
$this->assertEquals('\Drupal\Core\Entity\Controller\EntityListController::listing', $new_defaults['_controller'], 'The entity list controller was not set.');
|
||||
$this->assertEquals('entity_test.default', $new_defaults['entity_type']);
|
||||
@@ -48,6 +52,7 @@ class EntityRouteEnhancerTest extends UnitTestCase {
|
||||
$defaults = [];
|
||||
$defaults['_entity_view'] = 'entity_test.full';
|
||||
$defaults['entity_test'] = 'Mock entity';
|
||||
$defaults['_route_object'] = (new Route('/test', $defaults));
|
||||
$defaults = $route_enhancer->enhance($defaults, $request);
|
||||
$this->assertEquals('\Drupal\Core\Entity\Controller\EntityViewController::view', $defaults['_controller'], 'The entity view controller was not set.');
|
||||
$this->assertEquals($defaults['_entity'], 'Mock entity');
|
||||
@@ -62,13 +67,9 @@ class EntityRouteEnhancerTest extends UnitTestCase {
|
||||
// Add a converter.
|
||||
$options['parameters']['foo'] = ['type' => 'entity:entity_test'];
|
||||
// Set the route.
|
||||
$route = $this->getMockBuilder('Symfony\Component\Routing\Route')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$route->expects($this->any())
|
||||
->method('getOptions')
|
||||
->will($this->returnValue($options));
|
||||
$route = new Route('/test');
|
||||
$route->setOptions($options);
|
||||
$route->setDefaults($defaults);
|
||||
|
||||
$defaults[RouteObjectInterface::ROUTE_OBJECT] = $route;
|
||||
$defaults = $route_enhancer->enhance($defaults, $request);
|
||||
@@ -81,6 +82,7 @@ class EntityRouteEnhancerTest extends UnitTestCase {
|
||||
$defaults = [];
|
||||
$defaults['_entity_view'] = 'entity_test';
|
||||
$defaults['entity_test'] = 'Mock entity';
|
||||
$defaults['_route_object'] = (new Route('/test', $defaults));
|
||||
$defaults = $route_enhancer->enhance($defaults, $request);
|
||||
$this->assertEquals('\Drupal\Core\Entity\Controller\EntityViewController::view', $defaults['_controller'], 'The entity view controller was not set.');
|
||||
$this->assertEquals($defaults['_entity'], 'Mock entity');
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Drupal\Tests\Core\Entity;
|
||||
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Language\Language;
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
@@ -14,11 +15,11 @@ use Drupal\Tests\UnitTestCase;
|
||||
class EntityLinkTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* The mocked entity manager.
|
||||
* The mocked entity type manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $entityManager;
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* The tested link generator.
|
||||
@@ -40,12 +41,12 @@ class EntityLinkTest extends UnitTestCase {
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->entityManager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
|
||||
$this->entityTypeManager = $this->getMock(EntityTypeManagerInterface::class);
|
||||
$this->linkGenerator = $this->getMock('Drupal\Core\Utility\LinkGeneratorInterface');
|
||||
$this->languageManager = $this->getMock('Drupal\Core\Language\LanguageManagerInterface');
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
$container->set('entity.manager', $this->entityManager);
|
||||
$container->set('entity_type.manager', $this->entityTypeManager);
|
||||
$container->set('link_generator', $this->linkGenerator);
|
||||
$container->set('language_manager', $this->languageManager);
|
||||
\Drupal::setContainer($container);
|
||||
@@ -86,7 +87,7 @@ class EntityLinkTest extends UnitTestCase {
|
||||
['langcode', 'langcode'],
|
||||
]);
|
||||
|
||||
$this->entityManager
|
||||
$this->entityTypeManager
|
||||
->expects($this->any())
|
||||
->method('getDefinition')
|
||||
->with($entity_type_id)
|
||||
@@ -148,7 +149,7 @@ class EntityLinkTest extends UnitTestCase {
|
||||
['langcode', 'langcode'],
|
||||
]);
|
||||
|
||||
$this->entityManager
|
||||
$this->entityTypeManager
|
||||
->expects($this->any())
|
||||
->method('getDefinition')
|
||||
->with($entity_type_id)
|
||||
|
||||
@@ -11,6 +11,7 @@ use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityListBuilder;
|
||||
use Drupal\Core\Routing\RedirectDestinationInterface;
|
||||
use Drupal\entity_test\EntityTestListBuilder;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
@@ -62,6 +63,13 @@ class EntityListBuilderTest extends UnitTestCase {
|
||||
*/
|
||||
protected $role;
|
||||
|
||||
/**
|
||||
* The redirect destination service.
|
||||
*
|
||||
* @var \Drupal\Core\Routing\RedirectDestinationInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $redirectDestination;
|
||||
|
||||
/**
|
||||
* The EntityListBuilder object to test.
|
||||
*
|
||||
@@ -80,7 +88,8 @@ class EntityListBuilderTest extends UnitTestCase {
|
||||
$this->moduleHandler = $this->getMock('\Drupal\Core\Extension\ModuleHandlerInterface');
|
||||
$this->entityType = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface');
|
||||
$this->translationManager = $this->getMock('\Drupal\Core\StringTranslation\TranslationInterface');
|
||||
$this->entityListBuilder = new TestEntityListBuilder($this->entityType, $this->roleStorage, $this->moduleHandler);
|
||||
$this->entityListBuilder = new TestEntityListBuilder($this->entityType, $this->roleStorage);
|
||||
$this->redirectDestination = $this->getMock(RedirectDestinationInterface::class);
|
||||
$this->container = new ContainerBuilder();
|
||||
\Drupal::setContainer($this->container);
|
||||
}
|
||||
@@ -114,15 +123,20 @@ class EntityListBuilderTest extends UnitTestCase {
|
||||
$url = $this->getMockBuilder('\Drupal\Core\Url')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$url->expects($this->any())
|
||||
->method('toArray')
|
||||
->will($this->returnValue([]));
|
||||
$url->expects($this->atLeastOnce())
|
||||
->method('mergeOptions')
|
||||
->with(['query' => ['destination' => '/foo/bar']]);
|
||||
$this->role->expects($this->any())
|
||||
->method('urlInfo')
|
||||
->method('toUrl')
|
||||
->will($this->returnValue($url));
|
||||
|
||||
$list = new EntityListBuilder($this->entityType, $this->roleStorage, $this->moduleHandler);
|
||||
$this->redirectDestination->expects($this->atLeastOnce())
|
||||
->method('getAsArray')
|
||||
->willReturn(['destination' => '/foo/bar']);
|
||||
|
||||
$list = new EntityListBuilder($this->entityType, $this->roleStorage);
|
||||
$list->setStringTranslation($this->translationManager);
|
||||
$list->setRedirectDestination($this->redirectDestination);
|
||||
|
||||
$operations = $list->getOperations($this->role);
|
||||
$this->assertInternalType('array', $operations);
|
||||
|
||||
@@ -445,17 +445,31 @@ class EntityResolverManagerTest extends UnitTestCase {
|
||||
$definition->expects($this->any())
|
||||
->method('getClass')
|
||||
->will($this->returnValue('Drupal\Tests\Core\Entity\SimpleTestEntity'));
|
||||
$definition->expects($this->any())
|
||||
->method('isRevisionable')
|
||||
->willReturn(FALSE);
|
||||
$revisionable_definition = $this->getMock('Drupal\Core\Entity\EntityTypeInterface');
|
||||
$revisionable_definition->expects($this->any())
|
||||
->method('getClass')
|
||||
->will($this->returnValue('Drupal\Tests\Core\Entity\SimpleTestEntity'));
|
||||
$revisionable_definition->expects($this->any())
|
||||
->method('isRevisionable')
|
||||
->willReturn(TRUE);
|
||||
$this->entityManager->expects($this->any())
|
||||
->method('getDefinitions')
|
||||
->will($this->returnValue([
|
||||
'entity_test' => $definition,
|
||||
'entity_test_rev' => $revisionable_definition,
|
||||
]));
|
||||
$this->entityManager->expects($this->any())
|
||||
->method('getDefinition')
|
||||
->will($this->returnCallback(function ($entity_type) use ($definition) {
|
||||
->will($this->returnCallback(function ($entity_type) use ($definition, $revisionable_definition) {
|
||||
if ($entity_type == 'entity_test') {
|
||||
return $definition;
|
||||
}
|
||||
elseif ($entity_type === 'entity_test_rev') {
|
||||
return $revisionable_definition;
|
||||
}
|
||||
else {
|
||||
return NULL;
|
||||
}
|
||||
@@ -492,6 +506,8 @@ class SimpleTestEntity extends Entity {
|
||||
|
||||
/**
|
||||
* A basic form with a passed entity with an interface.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class BasicForm extends FormBase {
|
||||
|
||||
|
||||
@@ -127,6 +127,18 @@ class EntityTypeTest extends UnitTestCase {
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the isInternal() method.
|
||||
*/
|
||||
public function testIsInternal() {
|
||||
$entity_type = $this->setUpEntityType(['internal' => TRUE]);
|
||||
$this->assertTrue($entity_type->isInternal());
|
||||
$entity_type = $this->setUpEntityType(['internal' => FALSE]);
|
||||
$this->assertFalse($entity_type->isInternal());
|
||||
$entity_type = $this->setUpEntityType([]);
|
||||
$this->assertFalse($entity_type->isInternal());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the isRevisionable() method.
|
||||
*/
|
||||
@@ -392,6 +404,28 @@ class EntityTypeTest extends UnitTestCase {
|
||||
$this->assertEquals('200 entity test plural entities', $entity_type->getCountLabel(200));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the ::getBundleLabel() method.
|
||||
*
|
||||
* @covers ::getBundleLabel
|
||||
* @dataProvider providerTestGetBundleLabel
|
||||
*/
|
||||
public function testGetBundleLabel($definition, $expected) {
|
||||
$entity_type = $this->setUpEntityType($definition);
|
||||
$entity_type->setStringTranslation($this->getStringTranslationStub());
|
||||
$this->assertEquals($expected, $entity_type->getBundleLabel());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides test data for ::testGetBundleLabel().
|
||||
*/
|
||||
public function providerTestGetBundleLabel() {
|
||||
return [
|
||||
[['label' => 'Entity Label Foo'], 'Entity Label Foo bundle'],
|
||||
[['bundle_label' => 'Bundle Label Bar'], 'Bundle Label Bar'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a mock controller class name.
|
||||
*
|
||||
|
||||
@@ -5,7 +5,11 @@ namespace Drupal\Tests\Core\Entity;
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Entity\EntityTypeRepositoryInterface;
|
||||
use Drupal\Core\Language\Language;
|
||||
use Drupal\entity_test\Entity\EntityTestMul;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
@@ -30,11 +34,11 @@ class EntityUnitTest extends UnitTestCase {
|
||||
protected $entityType;
|
||||
|
||||
/**
|
||||
* The entity manager used for testing.
|
||||
* The entity type manager used for testing.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $entityManager;
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* The ID of the type of the entity under test.
|
||||
@@ -94,8 +98,8 @@ class EntityUnitTest extends UnitTestCase {
|
||||
->method('getListCacheTags')
|
||||
->willReturn([$this->entityTypeId . '_list']);
|
||||
|
||||
$this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface');
|
||||
$this->entityManager->expects($this->any())
|
||||
$this->entityTypeManager = $this->getMockForAbstractClass(EntityTypeManagerInterface::class);
|
||||
$this->entityTypeManager->expects($this->any())
|
||||
->method('getDefinition')
|
||||
->with($this->entityTypeId)
|
||||
->will($this->returnValue($this->entityType));
|
||||
@@ -111,7 +115,9 @@ class EntityUnitTest extends UnitTestCase {
|
||||
$this->cacheTagsInvalidator = $this->getMock('Drupal\Core\Cache\CacheTagsInvalidator');
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
$container->set('entity.manager', $this->entityManager);
|
||||
// Ensure that Entity doesn't use the deprecated entity.manager service.
|
||||
$container->set('entity.manager', NULL);
|
||||
$container->set('entity_type.manager', $this->entityTypeManager);
|
||||
$container->set('uuid', $this->uuid);
|
||||
$container->set('language_manager', $this->languageManager);
|
||||
$container->set('cache_tags.invalidator', $this->cacheTagsInvalidator);
|
||||
@@ -186,7 +192,7 @@ class EntityUnitTest extends UnitTestCase {
|
||||
|
||||
// Set a dummy property on the entity under test to test that the label can
|
||||
// be returned form a property if there is no callback.
|
||||
$this->entityManager->expects($this->at(1))
|
||||
$this->entityTypeManager->expects($this->at(1))
|
||||
->method('getDefinition')
|
||||
->with($this->entityTypeId)
|
||||
->will($this->returnValue([
|
||||
@@ -213,9 +219,10 @@ class EntityUnitTest extends UnitTestCase {
|
||||
$access->expects($this->at(1))
|
||||
->method('createAccess')
|
||||
->will($this->returnValue(AccessResult::allowed()));
|
||||
$this->entityManager->expects($this->exactly(2))
|
||||
$this->entityTypeManager->expects($this->exactly(2))
|
||||
->method('getAccessControlHandler')
|
||||
->will($this->returnValue($access));
|
||||
|
||||
$this->assertEquals(AccessResult::allowed(), $this->entity->access($operation));
|
||||
$this->assertEquals(AccessResult::allowed(), $this->entity->access('create'));
|
||||
}
|
||||
@@ -239,11 +246,11 @@ class EntityUnitTest extends UnitTestCase {
|
||||
// Base our mocked entity on a real entity class so we can test if calling
|
||||
// Entity::load() on the base class will bubble up to an actual entity.
|
||||
$this->entityTypeId = 'entity_test_mul';
|
||||
$methods = get_class_methods('Drupal\entity_test\Entity\EntityTestMul');
|
||||
$methods = get_class_methods(EntityTestMul::class);
|
||||
unset($methods[array_search('load', $methods)]);
|
||||
unset($methods[array_search('loadMultiple', $methods)]);
|
||||
unset($methods[array_search('create', $methods)]);
|
||||
$this->entity = $this->getMockBuilder('Drupal\entity_test\Entity\EntityTestMul')
|
||||
$this->entity = $this->getMockBuilder(EntityTestMul::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods($methods)
|
||||
->getMock();
|
||||
@@ -260,21 +267,25 @@ class EntityUnitTest extends UnitTestCase {
|
||||
|
||||
$class_name = get_class($this->entity);
|
||||
|
||||
$this->entityManager->expects($this->once())
|
||||
$entity_type_repository = $this->getMockForAbstractClass(EntityTypeRepositoryInterface::class);
|
||||
$entity_type_repository->expects($this->once())
|
||||
->method('getEntityTypeFromClass')
|
||||
->with($class_name)
|
||||
->willReturn($this->entityTypeId);
|
||||
|
||||
$storage = $this->getMock('\Drupal\Core\Entity\EntityStorageInterface');
|
||||
$storage = $this->getMock(EntityStorageInterface::class);
|
||||
$storage->expects($this->once())
|
||||
->method('load')
|
||||
->with(1)
|
||||
->will($this->returnValue($this->entity));
|
||||
$this->entityManager->expects($this->once())
|
||||
|
||||
$this->entityTypeManager->expects($this->once())
|
||||
->method('getStorage')
|
||||
->with($this->entityTypeId)
|
||||
->will($this->returnValue($storage));
|
||||
|
||||
\Drupal::getContainer()->set('entity_type.repository', $entity_type_repository);
|
||||
|
||||
// Call Entity::load statically and check that it returns the mock entity.
|
||||
$this->assertSame($this->entity, $class_name::load(1));
|
||||
}
|
||||
@@ -290,21 +301,25 @@ class EntityUnitTest extends UnitTestCase {
|
||||
|
||||
$class_name = get_class($this->entity);
|
||||
|
||||
$this->entityManager->expects($this->once())
|
||||
$entity_type_repository = $this->getMockForAbstractClass(EntityTypeRepositoryInterface::class);
|
||||
$entity_type_repository->expects($this->once())
|
||||
->method('getEntityTypeFromClass')
|
||||
->with($class_name)
|
||||
->willReturn($this->entityTypeId);
|
||||
|
||||
$storage = $this->getMock('\Drupal\Core\Entity\EntityStorageInterface');
|
||||
$storage = $this->getMock(EntityStorageInterface::class);
|
||||
$storage->expects($this->once())
|
||||
->method('loadMultiple')
|
||||
->with([1])
|
||||
->will($this->returnValue([1 => $this->entity]));
|
||||
$this->entityManager->expects($this->once())
|
||||
|
||||
$this->entityTypeManager->expects($this->once())
|
||||
->method('getStorage')
|
||||
->with($this->entityTypeId)
|
||||
->will($this->returnValue($storage));
|
||||
|
||||
\Drupal::getContainer()->set('entity_type.repository', $entity_type_repository);
|
||||
|
||||
// Call Entity::loadMultiple statically and check that it returns the mock
|
||||
// entity.
|
||||
$this->assertSame([1 => $this->entity], $class_name::loadMultiple([1]));
|
||||
@@ -317,21 +332,26 @@ class EntityUnitTest extends UnitTestCase {
|
||||
$this->setupTestLoad();
|
||||
|
||||
$class_name = get_class($this->entity);
|
||||
$this->entityManager->expects($this->once())
|
||||
|
||||
$entity_type_repository = $this->getMockForAbstractClass(EntityTypeRepositoryInterface::class);
|
||||
$entity_type_repository->expects($this->once())
|
||||
->method('getEntityTypeFromClass')
|
||||
->with($class_name)
|
||||
->willReturn($this->entityTypeId);
|
||||
|
||||
$storage = $this->getMock('\Drupal\Core\Entity\EntityStorageInterface');
|
||||
$storage = $this->getMock(EntityStorageInterface::class);
|
||||
$storage->expects($this->once())
|
||||
->method('create')
|
||||
->with([])
|
||||
->will($this->returnValue($this->entity));
|
||||
$this->entityManager->expects($this->once())
|
||||
|
||||
$this->entityTypeManager->expects($this->once())
|
||||
->method('getStorage')
|
||||
->with($this->entityTypeId)
|
||||
->will($this->returnValue($storage));
|
||||
|
||||
\Drupal::getContainer()->set('entity_type.repository', $entity_type_repository);
|
||||
|
||||
// Call Entity::create() statically and check that it returns the mock
|
||||
// entity.
|
||||
$this->assertSame($this->entity, $class_name::create([]));
|
||||
@@ -345,10 +365,12 @@ class EntityUnitTest extends UnitTestCase {
|
||||
$storage->expects($this->once())
|
||||
->method('save')
|
||||
->with($this->entity);
|
||||
$this->entityManager->expects($this->once())
|
||||
|
||||
$this->entityTypeManager->expects($this->once())
|
||||
->method('getStorage')
|
||||
->with($this->entityTypeId)
|
||||
->will($this->returnValue($storage));
|
||||
|
||||
$this->entity->save();
|
||||
}
|
||||
|
||||
@@ -361,10 +383,12 @@ class EntityUnitTest extends UnitTestCase {
|
||||
// Testing the argument of the delete() method consumes too much memory.
|
||||
$storage->expects($this->once())
|
||||
->method('delete');
|
||||
$this->entityManager->expects($this->once())
|
||||
|
||||
$this->entityTypeManager->expects($this->once())
|
||||
->method('getStorage')
|
||||
->with($this->entityTypeId)
|
||||
->will($this->returnValue($storage));
|
||||
|
||||
$this->entity->delete();
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace Drupal\Tests\Core\Entity;
|
||||
|
||||
use Drupal\Core\Entity\Entity;
|
||||
use Drupal\Core\Entity\EntityMalformedException;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Entity\Exception\UndefinedLinkTemplateException;
|
||||
use Drupal\Core\Entity\RevisionableInterface;
|
||||
@@ -21,11 +21,11 @@ use Drupal\Tests\UnitTestCase;
|
||||
class EntityUrlTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* The entity manager mock used in this test.
|
||||
* The entity type bundle info service mock used in this test.
|
||||
*
|
||||
* @var \Prophecy\Prophecy\ProphecyInterface|\Drupal\Core\Entity\EntityManagerInterface
|
||||
* @var \Prophecy\Prophecy\ProphecyInterface|\Drupal\Core\Entity\EntityTypeBundleInfoInterface
|
||||
*/
|
||||
protected $entityManager;
|
||||
protected $entityTypeBundleInfo;
|
||||
|
||||
/**
|
||||
* The ID of the entity type used in this test.
|
||||
@@ -511,7 +511,7 @@ class EntityUrlTest extends UnitTestCase {
|
||||
* @return \Drupal\Core\Entity\Entity|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected function getEntity($class, array $values, array $methods = []) {
|
||||
$methods = array_merge($methods, ['getEntityType', 'entityManager']);
|
||||
$methods = array_merge($methods, ['getEntityType', 'entityManager', 'entityTypeBundleInfo']);
|
||||
|
||||
// Prophecy does not allow prophesizing abstract classes while actually
|
||||
// calling their code. We use Prophecy below because that allows us to
|
||||
@@ -526,8 +526,8 @@ class EntityUrlTest extends UnitTestCase {
|
||||
$this->entityType->getKey('langcode')->willReturn(FALSE);
|
||||
$entity->method('getEntityType')->willReturn($this->entityType->reveal());
|
||||
|
||||
$this->entityManager = $this->prophesize(EntityManagerInterface::class);
|
||||
$entity->method('entityManager')->willReturn($this->entityManager->reveal());
|
||||
$this->entityTypeBundleInfo = $this->prophesize(EntityTypeBundleInfoInterface::class);
|
||||
$entity->method('entityTypeBundleInfo')->willReturn($this->entityTypeBundleInfo->reveal());
|
||||
|
||||
return $entity;
|
||||
}
|
||||
@@ -581,7 +581,7 @@ class EntityUrlTest extends UnitTestCase {
|
||||
* The bundle information to register.
|
||||
*/
|
||||
protected function registerBundleInfo($bundle_info) {
|
||||
$this->entityManager
|
||||
$this->entityTypeBundleInfo
|
||||
->getBundleInfo($this->entityTypeId)
|
||||
->willReturn([$this->entityTypeId => $bundle_info]);
|
||||
}
|
||||
|
||||
@@ -4,9 +4,12 @@ namespace Drupal\Tests\Core\Entity\KeyValueStore;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityInterface;
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\Core\Entity\EntityFieldManagerInterface;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityMalformedException;
|
||||
use Drupal\Core\Entity\EntityManager;
|
||||
use Drupal\Core\Entity\EntityStorageException;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Language\Language;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage;
|
||||
@@ -58,12 +61,26 @@ class KeyValueEntityStorageTest extends UnitTestCase {
|
||||
protected $entityStorage;
|
||||
|
||||
/**
|
||||
* The mocked entity manager.
|
||||
* The entity manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $entityManager;
|
||||
|
||||
/**
|
||||
* The mocked entity type manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* The mocked entity field manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityFieldManagerInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $entityFieldManager;
|
||||
|
||||
/**
|
||||
* The mocked cache tags invalidator.
|
||||
*
|
||||
@@ -102,12 +119,16 @@ class KeyValueEntityStorageTest extends UnitTestCase {
|
||||
->method('getListCacheTags')
|
||||
->willReturn(['test_entity_type_list']);
|
||||
|
||||
$this->entityManager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
|
||||
$this->entityManager->expects($this->any())
|
||||
$this->entityManager = new EntityManager();
|
||||
|
||||
$this->entityTypeManager = $this->getMock(EntityTypeManagerInterface::class);
|
||||
$this->entityTypeManager->expects($this->any())
|
||||
->method('getDefinition')
|
||||
->with('test_entity_type')
|
||||
->will($this->returnValue($this->entityType));
|
||||
|
||||
$this->entityFieldManager = $this->getMock(EntityFieldManagerInterface::class);
|
||||
|
||||
$this->cacheTagsInvalidator = $this->getMock('Drupal\Core\Cache\CacheTagsInvalidatorInterface');
|
||||
|
||||
$this->keyValueStore = $this->getMock('Drupal\Core\KeyValueStore\KeyValueStoreInterface');
|
||||
@@ -127,8 +148,13 @@ class KeyValueEntityStorageTest extends UnitTestCase {
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
$container->set('entity.manager', $this->entityManager);
|
||||
$container->set('entity_field.manager', $this->entityFieldManager);
|
||||
$container->set('entity_type.manager', $this->entityTypeManager);
|
||||
$container->set('language_manager', $this->languageManager);
|
||||
$container->set('cache_tags.invalidator', $this->cacheTagsInvalidator);
|
||||
// Inject the container into entity.manager so it can defer to
|
||||
// entity_type.manager and other services.
|
||||
$this->entityManager->setContainer($container);
|
||||
\Drupal::setContainer($container);
|
||||
}
|
||||
|
||||
@@ -335,7 +361,7 @@ class KeyValueEntityStorageTest extends UnitTestCase {
|
||||
$this->assertSame('foo', $entity->getOriginalId());
|
||||
|
||||
$expected = ['id' => 'foo'];
|
||||
$entity->expects($this->once())
|
||||
$entity->expects($this->atLeastOnce())
|
||||
->method('toArray')
|
||||
->will($this->returnValue($expected));
|
||||
|
||||
|
||||
@@ -8,8 +8,11 @@
|
||||
namespace Drupal\Tests\Core\Entity\Sql;
|
||||
|
||||
use Drupal\Core\Cache\CacheBackendInterface;
|
||||
use Drupal\Core\Entity\EntityFieldManagerInterface;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityManager;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Entity\Query\QueryFactoryInterface;
|
||||
use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
|
||||
use Drupal\Core\Language\Language;
|
||||
@@ -50,6 +53,20 @@ class SqlContentEntityStorageTest extends UnitTestCase {
|
||||
*/
|
||||
protected $entityManager;
|
||||
|
||||
/**
|
||||
* The mocked entity type manager used in this test.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* The mocked entity field manager used in this test.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityFieldManagerInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $entityFieldManager;
|
||||
|
||||
/**
|
||||
* The entity type ID.
|
||||
*
|
||||
@@ -104,7 +121,12 @@ class SqlContentEntityStorageTest extends UnitTestCase {
|
||||
$this->container = new ContainerBuilder();
|
||||
\Drupal::setContainer($this->container);
|
||||
|
||||
$this->entityManager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
|
||||
$this->entityManager = new EntityManager();
|
||||
// Inject the container into entity.manager so it can defer to
|
||||
// entity_type.manager and other services.
|
||||
$this->entityManager->setContainer($this->container);
|
||||
$this->entityTypeManager = $this->getMock(EntityTypeManagerInterface::class);
|
||||
$this->entityFieldManager = $this->getMock(EntityFieldManagerInterface::class);
|
||||
$this->moduleHandler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface');
|
||||
$this->cache = $this->getMock('Drupal\Core\Cache\CacheBackendInterface');
|
||||
$this->languageManager = $this->getMock('Drupal\Core\Language\LanguageManagerInterface');
|
||||
@@ -114,6 +136,10 @@ class SqlContentEntityStorageTest extends UnitTestCase {
|
||||
$this->connection = $this->getMockBuilder('Drupal\Core\Database\Connection')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->container->set('entity.manager', $this->entityManager);
|
||||
$this->container->set('entity_type.manager', $this->entityTypeManager);
|
||||
$this->container->set('entity_field.manager', $this->entityFieldManager);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -986,7 +1012,6 @@ class SqlContentEntityStorageTest extends UnitTestCase {
|
||||
->will($this->returnValue($language));
|
||||
|
||||
$this->container->set('language_manager', $language_manager);
|
||||
$this->container->set('entity.manager', $this->entityManager);
|
||||
$this->container->set('module_handler', $this->moduleHandler);
|
||||
|
||||
$entity = $this->getMockBuilder('Drupal\Core\Entity\ContentEntityBase')
|
||||
@@ -1006,14 +1031,14 @@ class SqlContentEntityStorageTest extends UnitTestCase {
|
||||
|
||||
// ContentEntityStorageBase iterates over the entity which calls this method
|
||||
// internally in ContentEntityBase::getProperties().
|
||||
$this->entityManager->expects($this->once())
|
||||
$this->entityFieldManager->expects($this->once())
|
||||
->method('getFieldDefinitions')
|
||||
->will($this->returnValue([]));
|
||||
|
||||
$this->entityType->expects($this->atLeastOnce())
|
||||
->method('isRevisionable')
|
||||
->will($this->returnValue(FALSE));
|
||||
$this->entityManager->expects($this->atLeastOnce())
|
||||
$this->entityTypeManager->expects($this->atLeastOnce())
|
||||
->method('getDefinition')
|
||||
->with($this->entityType->id())
|
||||
->will($this->returnValue($this->entityType));
|
||||
@@ -1077,15 +1102,15 @@ class SqlContentEntityStorageTest extends UnitTestCase {
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->entityManager->expects($this->any())
|
||||
$this->entityTypeManager->expects($this->any())
|
||||
->method('getDefinition')
|
||||
->will($this->returnValue($this->entityType));
|
||||
|
||||
$this->entityManager->expects($this->any())
|
||||
$this->entityFieldManager->expects($this->any())
|
||||
->method('getFieldStorageDefinitions')
|
||||
->will($this->returnValue($this->fieldDefinitions));
|
||||
|
||||
$this->entityManager->expects($this->any())
|
||||
$this->entityFieldManager->expects($this->any())
|
||||
->method('getBaseFieldDefinitions')
|
||||
->will($this->returnValue($this->fieldDefinitions));
|
||||
|
||||
@@ -1259,15 +1284,15 @@ class SqlContentEntityStorageTest extends UnitTestCase {
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->entityManager->expects($this->any())
|
||||
$this->entityTypeManager->expects($this->any())
|
||||
->method('getDefinition')
|
||||
->will($this->returnValue($this->entityType));
|
||||
|
||||
$this->entityManager->expects($this->any())
|
||||
$this->entityFieldManager->expects($this->any())
|
||||
->method('getFieldStorageDefinitions')
|
||||
->will($this->returnValue($this->fieldDefinitions));
|
||||
|
||||
$this->entityManager->expects($this->any())
|
||||
$this->entityFieldManager->expects($this->any())
|
||||
->method('getBaseFieldDefinitions')
|
||||
->will($this->returnValue($this->fieldDefinitions));
|
||||
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
namespace Drupal\Tests\Core\Entity\TypedData;
|
||||
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\Core\Entity\EntityFieldManagerInterface;
|
||||
use Drupal\Core\Entity\EntityManager;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Entity\Plugin\DataType\EntityAdapter;
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
@@ -26,19 +29,33 @@ class EntityAdapterUnitTest extends UnitTestCase {
|
||||
protected $bundle;
|
||||
|
||||
/**
|
||||
* The entity used for testing.
|
||||
* The content entity used for testing.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\ContentEntityBase|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $entity;
|
||||
|
||||
/**
|
||||
* The entity adapter under test.
|
||||
* The config entity used for testing.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\ConfigtEntityBase|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $configEntity;
|
||||
|
||||
/**
|
||||
* The content entity adapter under test.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\Plugin\DataType\EntityAdapter
|
||||
*/
|
||||
protected $entityAdapter;
|
||||
|
||||
/**
|
||||
* The config entity adapter under test.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\Plugin\DataType\EntityAdapter
|
||||
*/
|
||||
protected $configEntityAdapter;
|
||||
|
||||
/**
|
||||
* The entity type used for testing.
|
||||
*
|
||||
@@ -53,6 +70,19 @@ class EntityAdapterUnitTest extends UnitTestCase {
|
||||
*/
|
||||
protected $entityManager;
|
||||
|
||||
/**
|
||||
* The entity type manager used for testing.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityFieldManagerInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $entityFieldManager;
|
||||
|
||||
/**
|
||||
* The type ID of the entity under test.
|
||||
*
|
||||
@@ -130,8 +160,10 @@ class EntityAdapterUnitTest extends UnitTestCase {
|
||||
'uuid' => 'uuid',
|
||||
]));
|
||||
|
||||
$this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface');
|
||||
$this->entityManager->expects($this->any())
|
||||
$this->entityManager = new EntityManager();
|
||||
|
||||
$this->entityTypeManager = $this->getMock(EntityTypeManagerInterface::class);
|
||||
$this->entityTypeManager->expects($this->any())
|
||||
->method('getDefinition')
|
||||
->with($this->entityTypeId)
|
||||
->will($this->returnValue($this->entityType));
|
||||
@@ -183,26 +215,37 @@ class EntityAdapterUnitTest extends UnitTestCase {
|
||||
->method('createFieldItemList')
|
||||
->willReturn($this->fieldItemList);
|
||||
|
||||
$this->entityFieldManager = $this->getMockForAbstractClass(EntityFieldManagerInterface::class);
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
$container->set('entity.manager', $this->entityManager);
|
||||
$container->set('entity_type.manager', $this->entityTypeManager);
|
||||
$container->set('entity_field.manager', $this->entityFieldManager);
|
||||
$container->set('uuid', $this->uuid);
|
||||
$container->set('typed_data_manager', $this->typedDataManager);
|
||||
$container->set('language_manager', $this->languageManager);
|
||||
$container->set('plugin.manager.field.field_type', $this->fieldTypePluginManager);
|
||||
// Inject the container into entity.manager so it can defer to
|
||||
// entity_type.manager and other services.
|
||||
$this->entityManager->setContainer($container);
|
||||
\Drupal::setContainer($container);
|
||||
|
||||
$this->fieldDefinitions = [
|
||||
'id' => BaseFieldDefinition::create('integer'),
|
||||
'revision_id' => BaseFieldDefinition::create('integer'),
|
||||
];
|
||||
|
||||
$this->entityManager->expects($this->any())
|
||||
$this->entityFieldManager->expects($this->any())
|
||||
->method('getFieldDefinitions')
|
||||
->with($this->entityTypeId, $this->bundle)
|
||||
->will($this->returnValue($this->fieldDefinitions));
|
||||
|
||||
$this->entity = $this->getMockForAbstractClass('\Drupal\Core\Entity\ContentEntityBase', [$values, $this->entityTypeId, $this->bundle]);
|
||||
|
||||
$this->entityAdapter = EntityAdapter::createFromEntity($this->entity);
|
||||
|
||||
$this->configEntity = $this->getMockForAbstractClass('\Drupal\Core\Config\Entity\ConfigEntityBase', [$values, $this->entityTypeId, $this->bundle]);
|
||||
|
||||
$this->configEntityAdapter = EntityAdapter::createFromEntity($this->configEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -403,6 +446,7 @@ class EntityAdapterUnitTest extends UnitTestCase {
|
||||
* @covers ::getIterator
|
||||
*/
|
||||
public function testGetIterator() {
|
||||
// Content entity test.
|
||||
$iterator = $this->entityAdapter->getIterator();
|
||||
$fields = iterator_to_array($iterator);
|
||||
$this->assertArrayHasKey('id', $fields);
|
||||
@@ -411,6 +455,11 @@ class EntityAdapterUnitTest extends UnitTestCase {
|
||||
|
||||
$this->entityAdapter->setValue(NULL);
|
||||
$this->assertEquals(new \ArrayIterator([]), $this->entityAdapter->getIterator());
|
||||
|
||||
// Config entity test.
|
||||
$iterator = $this->configEntityAdapter->getIterator();
|
||||
$this->configEntityAdapter->setValue(NULL);
|
||||
$this->assertEquals(new \ArrayIterator([]), $this->entityAdapter->getIterator());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,11 +2,15 @@
|
||||
|
||||
namespace Drupal\Tests\Core\EventSubscriber;
|
||||
|
||||
use Drupal\Core\Cache\CacheableJsonResponse;
|
||||
use Drupal\Core\Cache\CacheableMetadata;
|
||||
use Drupal\Core\EventSubscriber\ExceptionJsonSubscriber;
|
||||
use Drupal\Core\Http\Exception\CacheableMethodNotAllowedHttpException;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
|
||||
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
|
||||
@@ -18,21 +22,34 @@ class ExceptionJsonSubscriberTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @covers ::on4xx
|
||||
* @dataProvider providerTestOn4xx
|
||||
*/
|
||||
public function testOn4xx() {
|
||||
public function testOn4xx(HttpExceptionInterface $exception, $expected_response_class) {
|
||||
$kernel = $this->prophesize(HttpKernelInterface::class);
|
||||
$request = Request::create('/test');
|
||||
$e = new MethodNotAllowedHttpException(['POST', 'PUT'], 'test message');
|
||||
$event = new GetResponseForExceptionEvent($kernel->reveal(), $request, 'GET', $e);
|
||||
$event = new GetResponseForExceptionEvent($kernel->reveal(), $request, 'GET', $exception);
|
||||
$subscriber = new ExceptionJsonSubscriber();
|
||||
$subscriber->on4xx($event);
|
||||
$response = $event->getResponse();
|
||||
|
||||
$this->assertInstanceOf(JsonResponse::class, $response);
|
||||
$this->assertInstanceOf($expected_response_class, $response);
|
||||
$this->assertEquals('{"message":"test message"}', $response->getContent());
|
||||
$this->assertEquals(405, $response->getStatusCode());
|
||||
$this->assertEquals('POST, PUT', $response->headers->get('Allow'));
|
||||
$this->assertEquals('application/json', $response->headers->get('Content-Type'));
|
||||
}
|
||||
|
||||
public function providerTestOn4xx() {
|
||||
return [
|
||||
'uncacheable exception' => [
|
||||
new MethodNotAllowedHttpException(['POST', 'PUT'], 'test message'),
|
||||
JsonResponse::class
|
||||
],
|
||||
'cacheable exception' => [
|
||||
new CacheableMethodNotAllowedHttpException((new CacheableMetadata())->setCacheContexts(['route']), ['POST', 'PUT'], 'test message'),
|
||||
CacheableJsonResponse::class
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
-3
@@ -5,8 +5,8 @@ package: Testing
|
||||
# version: VERSION
|
||||
# core: 8.x
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
# Information added by Drupal.org packaging script on 2018-03-07
|
||||
version: '8.5.0'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1515021228
|
||||
datestamp: 1520457825
|
||||
|
||||
+3
-3
@@ -6,8 +6,8 @@ package: Testing
|
||||
# core: 8.x
|
||||
hidden: true
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
# Information added by Drupal.org packaging script on 2018-03-07
|
||||
version: '8.5.0'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1515021228
|
||||
datestamp: 1520457825
|
||||
|
||||
+3
-3
@@ -6,8 +6,8 @@ package: Testing
|
||||
# core: 8.x
|
||||
hidden: true
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
# Information added by Drupal.org packaging script on 2018-03-07
|
||||
version: '8.5.0'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1515021228
|
||||
datestamp: 1520457825
|
||||
|
||||
+3
-3
@@ -6,8 +6,8 @@ package: Testing
|
||||
# core: 8.x
|
||||
hidden: true
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
# Information added by Drupal.org packaging script on 2018-03-07
|
||||
version: '8.5.0'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1515021228
|
||||
datestamp: 1520457825
|
||||
|
||||
+3
-3
@@ -5,8 +5,8 @@ package: Testing
|
||||
# version: VERSION
|
||||
# core: 8.x
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
# Information added by Drupal.org packaging script on 2018-03-07
|
||||
version: '8.5.0'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1515021228
|
||||
datestamp: 1520457825
|
||||
|
||||
@@ -76,7 +76,8 @@ class FormAjaxSubscriberTest extends UnitTestCase {
|
||||
->willReturn($response);
|
||||
|
||||
$event = $this->assertResponseFromException($request, $exception, $response);
|
||||
$this->assertSame(200, $event->getResponse()->headers->get('X-Status-Code'));
|
||||
$this->assertTrue($event->isAllowingCustomResponseCode());
|
||||
$this->assertSame(200, $event->getResponse()->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,7 +101,8 @@ class FormAjaxSubscriberTest extends UnitTestCase {
|
||||
->willReturn($response);
|
||||
|
||||
$event = $this->assertResponseFromException($request, $exception, $response);
|
||||
$this->assertSame(200, $event->getResponse()->headers->get('X-Status-Code'));
|
||||
$this->assertTrue($event->isAllowingCustomResponseCode());
|
||||
$this->assertSame(200, $event->getResponse()->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -176,9 +178,10 @@ class FormAjaxSubscriberTest extends UnitTestCase {
|
||||
|
||||
$event = new GetResponseForExceptionEvent($this->httpKernel, $request, HttpKernelInterface::MASTER_REQUEST, $exception);
|
||||
$this->subscriber->onException($event);
|
||||
$this->assertTrue($event->isAllowingCustomResponseCode());
|
||||
$actual_response = $event->getResponse();
|
||||
$this->assertInstanceOf('\Drupal\Core\Ajax\AjaxResponse', $actual_response);
|
||||
$this->assertSame(200, $actual_response->headers->get('X-Status-Code'));
|
||||
$this->assertSame(200, $actual_response->getStatusCode());
|
||||
$expected_commands[] = [
|
||||
'command' => 'insert',
|
||||
'method' => 'prepend',
|
||||
|
||||
@@ -10,7 +10,7 @@ use Drupal\Tests\UnitTestCase;
|
||||
* DrupalStandardsListener has a dependency on composer/composer, so we can't
|
||||
* test it directly. However, we can create a test which is annotated as
|
||||
* covering a deprecated class. This way we can know whether the standards
|
||||
* listener process handles deprecation errors properly.
|
||||
* listener process ignores deprecation errors.
|
||||
*
|
||||
* Note that this test is annotated as covering
|
||||
* \Drupal\deprecation_test\Deprecation\FixtureDeprecatedClass::testFunction(),
|
||||
@@ -22,7 +22,7 @@ use Drupal\Tests\UnitTestCase;
|
||||
*
|
||||
* @group Listeners
|
||||
*
|
||||
* @coversDefaultClass \Drupal\deprecation_test\Deprecation\FixtureDeprecatedClass
|
||||
* @coversDefaultClass \Drupal\deprecation_test\Deprecation\DrupalStandardsListenerDeprecatedClass
|
||||
*/
|
||||
class DrupalStandardsListenerDeprecationTest extends UnitTestCase {
|
||||
|
||||
|
||||
@@ -102,12 +102,12 @@ class LoggerChannelTest extends UnitTestCase {
|
||||
*/
|
||||
public function providerTestLog() {
|
||||
$account_mock = $this->getMock('Drupal\Core\Session\AccountInterface');
|
||||
$account_mock->expects($this->exactly(2))
|
||||
$account_mock->expects($this->any())
|
||||
->method('id')
|
||||
->will($this->returnValue(1));
|
||||
|
||||
$request_mock = $this->getMock('Symfony\Component\HttpFoundation\Request');
|
||||
$request_mock->expects($this->exactly(2))
|
||||
$request_mock = $this->getMock('Symfony\Component\HttpFoundation\Request', ['getClientIp']);
|
||||
$request_mock->expects($this->any())
|
||||
->method('getClientIp')
|
||||
->will($this->returnValue('127.0.0.1'));
|
||||
$request_mock->headers = $this->getMock('Symfony\Component\HttpFoundation\ParameterBag');
|
||||
|
||||
@@ -3,9 +3,15 @@
|
||||
namespace Drupal\Tests\Core\ParamConverter;
|
||||
|
||||
use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException;
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\ContentEntityStorageInterface;
|
||||
use Drupal\Core\Entity\ContentEntityTypeInterface;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\Core\Language\LanguageManagerInterface;
|
||||
use Drupal\Core\ParamConverter\EntityConverter;
|
||||
use Drupal\Core\ParamConverter\ParamNotConvertedException;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
||||
/**
|
||||
@@ -130,4 +136,74 @@ class EntityConverterTest extends UnitTestCase {
|
||||
$this->entityConverter->convert('id', ['type' => 'entity:{invalid_id}'], 'foo', ['foo' => 'id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that omitting the language manager triggers a deprecation error.
|
||||
*
|
||||
* @group legacy
|
||||
*
|
||||
* @expectedDeprecation The language manager parameter has been added to EntityConverter since version 8.5.0 and will be made required in version 9.0.0 when requesting the latest translation-affected revision of an entity.
|
||||
*/
|
||||
public function testDeprecatedOptionalLanguageManager() {
|
||||
$entity = $this->createMock(ContentEntityInterface::class);
|
||||
$entity->expects($this->any())
|
||||
->method('getEntityTypeId')
|
||||
->willReturn('entity_test');
|
||||
$entity->expects($this->any())
|
||||
->method('id')
|
||||
->willReturn('id');
|
||||
$entity->expects($this->any())
|
||||
->method('isTranslatable')
|
||||
->willReturn(FALSE);
|
||||
$entity->expects($this->any())
|
||||
->method('getLoadedRevisionId')
|
||||
->willReturn('revision_id');
|
||||
|
||||
$storage = $this->createMock(ContentEntityStorageInterface::class);
|
||||
$storage->expects($this->any())
|
||||
->method('load')
|
||||
->with('id')
|
||||
->willReturn($entity);
|
||||
$storage->expects($this->any())
|
||||
->method('getLatestRevisionId')
|
||||
->with('id')
|
||||
->willReturn('revision_id');
|
||||
|
||||
$this->entityManager->expects($this->any())
|
||||
->method('getStorage')
|
||||
->with('entity_test')
|
||||
->willReturn($storage);
|
||||
|
||||
$entity_type = $this->createMock(ContentEntityTypeInterface::class);
|
||||
$entity_type->expects($this->any())
|
||||
->method('isRevisionable')
|
||||
->willReturn(TRUE);
|
||||
|
||||
$this->entityManager->expects($this->any())
|
||||
->method('getDefinition')
|
||||
->with('entity_test')
|
||||
->willReturn($entity_type);
|
||||
|
||||
$language = $this->createMock(LanguageInterface::class);
|
||||
$language->expects($this->any())
|
||||
->method('getId')
|
||||
->willReturn('en');
|
||||
|
||||
$language_manager = $this->createMock(LanguageManagerInterface::class);
|
||||
$language_manager->expects($this->any())
|
||||
->method('getCurrentLanguage')
|
||||
->with(LanguageInterface::TYPE_CONTENT)
|
||||
->willReturn($language);
|
||||
|
||||
/** @var \Symfony\Component\DependencyInjection\ContainerInterface|\PHPUnit_Framework_MockObject_MockObject $container */
|
||||
$container = $this->createMock(ContainerInterface::class);
|
||||
$container->expects($this->any())
|
||||
->method('get')
|
||||
->with('language_manager')
|
||||
->willReturn($language_manager);
|
||||
|
||||
\Drupal::setContainer($container);
|
||||
$definition = ['type' => 'entity:entity_test', 'load_latest_revision' => TRUE];
|
||||
$this->entityConverter->convert('id', $definition, 'foo', []);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ class PasswordHashingTest extends UnitTestCase {
|
||||
* @covers ::needsRehash
|
||||
*/
|
||||
public function testPasswordHashing() {
|
||||
$this->assertSame($this->passwordHasher->getCountLog2($this->hashedPassword), PhpassHashedPassword::MIN_HASH_COUNT, 'Hashed password has the minimum number of log2 iterations.');
|
||||
$this->assertSame(PhpassHashedPassword::MIN_HASH_COUNT, $this->passwordHasher->getCountLog2($this->hashedPassword), 'Hashed password has the minimum number of log2 iterations.');
|
||||
$this->assertNotEquals($this->hashedPassword, $this->md5HashedPassword, 'Password hashes not the same.');
|
||||
$this->assertTrue($this->passwordHasher->check($this->password, $this->md5HashedPassword), 'Password check succeeds.');
|
||||
$this->assertTrue($this->passwordHasher->check($this->password, $this->hashedPassword), 'Password check succeeds.');
|
||||
@@ -119,7 +119,7 @@ class PasswordHashingTest extends UnitTestCase {
|
||||
$this->assertTrue($password_hasher->needsRehash($this->hashedPassword), 'Needs a new hash after incrementing the log2 count.');
|
||||
// Re-hash the password.
|
||||
$rehashed_password = $password_hasher->hash($this->password);
|
||||
$this->assertSame($password_hasher->getCountLog2($rehashed_password), PhpassHashedPassword::MIN_HASH_COUNT + 1, 'Re-hashed password has the correct number of log2 iterations.');
|
||||
$this->assertSame(PhpassHashedPassword::MIN_HASH_COUNT + 1, $password_hasher->getCountLog2($rehashed_password), 'Re-hashed password has the correct number of log2 iterations.');
|
||||
$this->assertNotEquals($rehashed_password, $this->hashedPassword, 'Password hash changed again.');
|
||||
|
||||
// Now the hash should be OK.
|
||||
|
||||
@@ -76,12 +76,6 @@ class PathProcessorTest extends UnitTestCase {
|
||||
$language_manager->expects($this->any())
|
||||
->method('getLanguageTypes')
|
||||
->will($this->returnValue([LanguageInterface::TYPE_INTERFACE]));
|
||||
$language_manager->expects($this->any())
|
||||
->method('getNegotiationMethods')
|
||||
->will($this->returnValue($method_definitions));
|
||||
$language_manager->expects($this->any())
|
||||
->method('getNegotiationMethodInstance')
|
||||
->will($this->returnValue($method_instance));
|
||||
|
||||
$method_instance->setLanguageManager($language_manager);
|
||||
$this->languageManager = $language_manager;
|
||||
|
||||
@@ -47,10 +47,10 @@ class CategorizingPluginManagerTraitTest extends UnitTestCase {
|
||||
* @covers ::getCategories
|
||||
*/
|
||||
public function testGetCategories() {
|
||||
$this->assertSame(array_values($this->pluginManager->getCategories()), [
|
||||
$this->assertSame([
|
||||
'fruits',
|
||||
'vegetables',
|
||||
]);
|
||||
], array_values($this->pluginManager->getCategories()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,7 +58,7 @@ class CategorizingPluginManagerTraitTest extends UnitTestCase {
|
||||
*/
|
||||
public function testGetSortedDefinitions() {
|
||||
$sorted = $this->pluginManager->getSortedDefinitions();
|
||||
$this->assertSame(array_keys($sorted), ['apple', 'mango', 'cucumber']);
|
||||
$this->assertSame(['apple', 'mango', 'cucumber'], array_keys($sorted));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,9 +66,9 @@ class CategorizingPluginManagerTraitTest extends UnitTestCase {
|
||||
*/
|
||||
public function testGetGroupedDefinitions() {
|
||||
$grouped = $this->pluginManager->getGroupedDefinitions();
|
||||
$this->assertSame(array_keys($grouped), ['fruits', 'vegetables']);
|
||||
$this->assertSame(array_keys($grouped['fruits']), ['apple', 'mango']);
|
||||
$this->assertSame(array_keys($grouped['vegetables']), ['cucumber']);
|
||||
$this->assertSame(['fruits', 'vegetables'], array_keys($grouped));
|
||||
$this->assertSame(['apple', 'mango'], array_keys($grouped['fruits']));
|
||||
$this->assertSame(['cucumber'], array_keys($grouped['vegetables']));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,7 +82,7 @@ class CategorizingPluginManagerTraitTest extends UnitTestCase {
|
||||
'category' => 'bag',
|
||||
];
|
||||
$this->pluginManager->processDefinition($definition, 'some');
|
||||
$this->assertSame($definition['category'], 'bag');
|
||||
$this->assertSame('bag', $definition['category']);
|
||||
|
||||
// No category, provider without label.
|
||||
$definition = [
|
||||
@@ -90,7 +90,7 @@ class CategorizingPluginManagerTraitTest extends UnitTestCase {
|
||||
'provider' => 'core',
|
||||
];
|
||||
$this->pluginManager->processDefinition($definition, 'some');
|
||||
$this->assertSame($definition['category'], 'core');
|
||||
$this->assertSame('core', $definition['category']);
|
||||
|
||||
// No category, provider is module with label.
|
||||
$definition = [
|
||||
@@ -98,7 +98,7 @@ class CategorizingPluginManagerTraitTest extends UnitTestCase {
|
||||
'provider' => 'node',
|
||||
];
|
||||
$this->pluginManager->processDefinition($definition, 'some');
|
||||
$this->assertSame($definition['category'], 'Node');
|
||||
$this->assertSame('Node', $definition['category']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,344 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\Core\Plugin\Context;
|
||||
|
||||
use Drupal\Core\Cache\NullBackend;
|
||||
use Drupal\Core\DependencyInjection\ClassResolverInterface;
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\ContentEntityStorageInterface;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Entity\EntityType;
|
||||
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Plugin\Context\Context;
|
||||
use Drupal\Core\Plugin\Context\ContextDefinition;
|
||||
use Drupal\Core\TypedData\TypedDataManager;
|
||||
use Drupal\Core\Validation\ConstraintManager;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Prophecy\Argument;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Core\Plugin\Context\ContextDefinition
|
||||
* @group Plugin
|
||||
*/
|
||||
class ContextDefinitionIsSatisfiedTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* The entity type manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* The entity manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityManagerInterface
|
||||
*/
|
||||
protected $entityManager;
|
||||
|
||||
/**
|
||||
* The entity type bundle info.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
|
||||
*/
|
||||
protected $entityTypeBundleInfo;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$namespaces = new \ArrayObject([
|
||||
'Drupal\\Core\\TypedData' => $this->root . '/core/lib/Drupal/Core/TypedData',
|
||||
'Drupal\\Core\\Validation' => $this->root . '/core/lib/Drupal/Core/Validation',
|
||||
'Drupal\\Core\\Entity' => $this->root . '/core/lib/Drupal/Core/Entity',
|
||||
]);
|
||||
$cache_backend = new NullBackend('cache');
|
||||
$module_handler = $this->prophesize(ModuleHandlerInterface::class);
|
||||
|
||||
$class_resolver = $this->prophesize(ClassResolverInterface::class);
|
||||
$class_resolver->getInstanceFromDefinition(Argument::type('string'))->will(function ($arguments) {
|
||||
$class_name = $arguments[0];
|
||||
return new $class_name();
|
||||
});
|
||||
|
||||
$type_data_manager = new TypedDataManager($namespaces, $cache_backend, $module_handler->reveal(), $class_resolver->reveal());
|
||||
$type_data_manager->setValidationConstraintManager(new ConstraintManager($namespaces, $cache_backend, $module_handler->reveal()));
|
||||
|
||||
$this->entityTypeManager = $this->prophesize(EntityTypeManagerInterface::class);
|
||||
$this->entityManager = $this->prophesize(EntityManagerInterface::class);
|
||||
|
||||
$this->entityTypeBundleInfo = $this->prophesize(EntityTypeBundleInfoInterface::class);
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
$container->set('typed_data_manager', $type_data_manager);
|
||||
$container->set('entity_type.manager', $this->entityTypeManager->reveal());
|
||||
$container->set('entity.manager', $this->entityManager->reveal());
|
||||
$container->set('entity_type.bundle.info', $this->entityTypeBundleInfo->reveal());
|
||||
\Drupal::setContainer($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the requirement is satisfied as expected.
|
||||
*
|
||||
* @param bool $expected
|
||||
* The expected outcome.
|
||||
* @param \Drupal\Core\Plugin\Context\ContextDefinition $requirement
|
||||
* The requirement to check against.
|
||||
* @param \Drupal\Core\Plugin\Context\ContextDefinition $definition
|
||||
* The context definition to check.
|
||||
* @param mixed $value
|
||||
* (optional) The value to set on the context, defaults to NULL.
|
||||
*/
|
||||
protected function assertRequirementIsSatisfied($expected, ContextDefinition $requirement, ContextDefinition $definition, $value = NULL) {
|
||||
$context = new Context($definition, $value);
|
||||
$this->assertSame($expected, $requirement->isSatisfiedBy($context));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::isSatisfiedBy
|
||||
* @covers ::getSampleValues
|
||||
* @covers ::getConstraintObjects
|
||||
*
|
||||
* @dataProvider providerTestIsSatisfiedBy
|
||||
*/
|
||||
public function testIsSatisfiedBy($expected, ContextDefinition $requirement, ContextDefinition $definition, $value = NULL) {
|
||||
$entity_storage = $this->prophesize(EntityStorageInterface::class);
|
||||
$content_entity_storage = $this->prophesize(ContentEntityStorageInterface::class);
|
||||
$this->entityTypeManager->getStorage('test_config')->willReturn($entity_storage->reveal());
|
||||
$this->entityTypeManager->getStorage('test_content')->willReturn($content_entity_storage->reveal());
|
||||
$this->entityManager->getDefinitions()->willReturn([
|
||||
'test_config' => new EntityType(['id' => 'test_config']),
|
||||
'test_content' => new EntityType(['id' => 'test_content']),
|
||||
]);
|
||||
$this->entityTypeBundleInfo->getBundleInfo('test_config')->willReturn([
|
||||
'test_config' => ['label' => 'test_config'],
|
||||
]);
|
||||
$this->entityTypeBundleInfo->getBundleInfo('test_content')->willReturn([
|
||||
'test_content' => ['label' => 'test_content'],
|
||||
]);
|
||||
|
||||
$this->assertRequirementIsSatisfied($expected, $requirement, $definition, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides test data for ::testIsSatisfiedBy().
|
||||
*/
|
||||
public function providerTestIsSatisfiedBy() {
|
||||
$data = [];
|
||||
|
||||
// Simple data types.
|
||||
$data['both any'] = [
|
||||
TRUE,
|
||||
new ContextDefinition('any'),
|
||||
new ContextDefinition('any'),
|
||||
];
|
||||
$data['requirement any'] = [
|
||||
TRUE,
|
||||
new ContextDefinition('any'),
|
||||
new ContextDefinition('integer'),
|
||||
];
|
||||
$data['integer, out of range'] = [
|
||||
FALSE,
|
||||
(new ContextDefinition('integer'))->addConstraint('Range', ['min' => 0, 'max' => 10]),
|
||||
new ContextDefinition('integer'),
|
||||
20,
|
||||
];
|
||||
$data['integer, within range'] = [
|
||||
TRUE,
|
||||
(new ContextDefinition('integer'))->addConstraint('Range', ['min' => 0, 'max' => 10]),
|
||||
new ContextDefinition('integer'),
|
||||
5,
|
||||
];
|
||||
$data['integer, no value'] = [
|
||||
TRUE,
|
||||
(new ContextDefinition('integer'))->addConstraint('Range', ['min' => 0, 'max' => 10]),
|
||||
new ContextDefinition('integer'),
|
||||
];
|
||||
$data['non-integer, within range'] = [
|
||||
FALSE,
|
||||
(new ContextDefinition('integer'))->addConstraint('Range', ['min' => 0, 'max' => 10]),
|
||||
new ContextDefinition('any'),
|
||||
5,
|
||||
];
|
||||
|
||||
// Entities without bundles.
|
||||
$data['content entity, matching type, no value'] = [
|
||||
TRUE,
|
||||
new ContextDefinition('entity:test_content'),
|
||||
new ContextDefinition('entity:test_content'),
|
||||
];
|
||||
$entity = $this->prophesize(ContentEntityInterface::class)->willImplement(\IteratorAggregate::class);
|
||||
$entity->getIterator()->willReturn(new \ArrayIterator([]));
|
||||
$entity->getCacheContexts()->willReturn([]);
|
||||
$entity->getCacheTags()->willReturn([]);
|
||||
$entity->getCacheMaxAge()->willReturn(0);
|
||||
$entity->getEntityTypeId()->willReturn('test_content');
|
||||
$data['content entity, matching type, correct value'] = [
|
||||
TRUE,
|
||||
new ContextDefinition('entity:test_content'),
|
||||
new ContextDefinition('entity:test_content'),
|
||||
$entity->reveal(),
|
||||
];
|
||||
$data['content entity, incorrect manual constraint'] = [
|
||||
TRUE,
|
||||
new ContextDefinition('entity:test_content'),
|
||||
(new ContextDefinition('entity:test_content'))->addConstraint('EntityType', 'test_config'),
|
||||
];
|
||||
$data['config entity, matching type, no value'] = [
|
||||
TRUE,
|
||||
new ContextDefinition('entity:test_config'),
|
||||
new ContextDefinition('entity:test_config'),
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::isSatisfiedBy
|
||||
* @covers ::getSampleValues
|
||||
* @covers ::getConstraintObjects
|
||||
*
|
||||
* @dataProvider providerTestIsSatisfiedByGenerateBundledEntity
|
||||
*/
|
||||
public function testIsSatisfiedByGenerateBundledEntity($expected, array $requirement_bundles, array $candidate_bundles, array $bundles_to_instantiate = NULL) {
|
||||
// If no bundles are explicitly specified, instantiate all bundles.
|
||||
if (!$bundles_to_instantiate) {
|
||||
$bundles_to_instantiate = $candidate_bundles;
|
||||
}
|
||||
|
||||
$content_entity_storage = $this->prophesize(ContentEntityStorageInterface::class);
|
||||
foreach ($bundles_to_instantiate as $bundle) {
|
||||
$entity = $this->prophesize(ContentEntityInterface::class)->willImplement(\IteratorAggregate::class);
|
||||
$entity->getEntityTypeId()->willReturn('test_content');
|
||||
$entity->getIterator()->willReturn(new \ArrayIterator([]));
|
||||
$entity->bundle()->willReturn($bundle);
|
||||
$content_entity_storage->createWithSampleValues($bundle)
|
||||
->willReturn($entity->reveal())
|
||||
->shouldBeCalled();
|
||||
}
|
||||
|
||||
$this->entityTypeManager->getStorage('test_content')->willReturn($content_entity_storage->reveal());
|
||||
$this->entityManager->getDefinitions()->willReturn([
|
||||
'test_content' => new EntityType(['id' => 'test_content']),
|
||||
]);
|
||||
|
||||
$this->entityTypeBundleInfo->getBundleInfo('test_content')->willReturn([
|
||||
'first_bundle' => ['label' => 'First bundle'],
|
||||
'second_bundle' => ['label' => 'Second bundle'],
|
||||
'third_bundle' => ['label' => 'Third bundle'],
|
||||
]);
|
||||
|
||||
$requirement = new ContextDefinition('entity:test_content');
|
||||
if ($requirement_bundles) {
|
||||
$requirement->addConstraint('Bundle', $requirement_bundles);
|
||||
}
|
||||
$definition = (new ContextDefinition('entity:test_content'))->addConstraint('Bundle', $candidate_bundles);
|
||||
$this->assertRequirementIsSatisfied($expected, $requirement, $definition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides test data for ::testIsSatisfiedByGenerateBundledEntity().
|
||||
*/
|
||||
public function providerTestIsSatisfiedByGenerateBundledEntity() {
|
||||
$data = [];
|
||||
$data['no requirement'] = [
|
||||
TRUE,
|
||||
[],
|
||||
['first_bundle'],
|
||||
];
|
||||
$data['single requirement'] = [
|
||||
TRUE,
|
||||
['first_bundle'],
|
||||
['first_bundle'],
|
||||
];
|
||||
$data['single requirement, multiple candidates, satisfies last candidate'] = [
|
||||
TRUE,
|
||||
['third_bundle'],
|
||||
['first_bundle', 'second_bundle', 'third_bundle'],
|
||||
];
|
||||
$data['single requirement, multiple candidates, satisfies first candidate'] = [
|
||||
TRUE,
|
||||
['first_bundle'],
|
||||
['first_bundle', 'second_bundle', 'third_bundle'],
|
||||
// Once the first match is found, subsequent candidates are not checked.
|
||||
['first_bundle'],
|
||||
];
|
||||
$data['unsatisfied requirement'] = [
|
||||
FALSE,
|
||||
['second_bundle'],
|
||||
['first_bundle', 'third_bundle'],
|
||||
];
|
||||
$data['multiple requirements'] = [
|
||||
TRUE,
|
||||
['first_bundle', 'second_bundle'],
|
||||
['first_bundle'],
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::isSatisfiedBy
|
||||
* @covers ::getSampleValues
|
||||
* @covers ::getConstraintObjects
|
||||
*
|
||||
* @dataProvider providerTestIsSatisfiedByPassBundledEntity
|
||||
*/
|
||||
public function testIsSatisfiedByPassBundledEntity($expected, $requirement_constraint) {
|
||||
$this->entityManager->getDefinitions()->willReturn([
|
||||
'test_content' => new EntityType(['id' => 'test_content']),
|
||||
]);
|
||||
$this->entityTypeManager->getStorage('test_content')->shouldNotBeCalled();
|
||||
|
||||
$this->entityTypeBundleInfo->getBundleInfo('test_content')->willReturn([
|
||||
'first_bundle' => ['label' => 'First bundle'],
|
||||
'second_bundle' => ['label' => 'Second bundle'],
|
||||
'third_bundle' => ['label' => 'Third bundle'],
|
||||
]);
|
||||
|
||||
$entity = $this->prophesize(ContentEntityInterface::class)->willImplement(\IteratorAggregate::class);
|
||||
$entity->getEntityTypeId()->willReturn('test_content');
|
||||
$entity->getIterator()->willReturn(new \ArrayIterator([]));
|
||||
$entity->getCacheContexts()->willReturn([]);
|
||||
$entity->getCacheTags()->willReturn([]);
|
||||
$entity->getCacheMaxAge()->willReturn(0);
|
||||
$entity->bundle()->willReturn('third_bundle');
|
||||
|
||||
$requirement = new ContextDefinition('entity:test_content');
|
||||
if ($requirement_constraint) {
|
||||
$requirement->addConstraint('Bundle', $requirement_constraint);
|
||||
}
|
||||
$definition = new ContextDefinition('entity:test_content');
|
||||
$this->assertRequirementIsSatisfied($expected, $requirement, $definition, $entity->reveal());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides test data for ::testIsSatisfiedByPassBundledEntity().
|
||||
*/
|
||||
public function providerTestIsSatisfiedByPassBundledEntity() {
|
||||
$data = [];
|
||||
$data[] = [TRUE, []];
|
||||
$data[] = [FALSE, ['first_bundle']];
|
||||
$data[] = [FALSE, ['second_bundle']];
|
||||
$data[] = [TRUE, ['third_bundle']];
|
||||
$data[] = [TRUE, ['first_bundle', 'second_bundle', 'third_bundle']];
|
||||
$data[] = [FALSE, ['first_bundle', 'second_bundle']];
|
||||
$data[] = [TRUE, ['first_bundle', 'third_bundle']];
|
||||
$data[] = [TRUE, ['second_bundle', 'third_bundle']];
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace Drupal\Core\Validation;
|
||||
|
||||
if (!function_exists('t')) {
|
||||
function t($string, array $args = []) {
|
||||
return strtr($string, $args);
|
||||
}
|
||||
}
|
||||
@@ -104,6 +104,7 @@ class ContextTest extends UnitTestCase {
|
||||
$container = new Container();
|
||||
$cache_context_manager = $this->getMockBuilder('Drupal\Core\Cache\CacheContextsManager')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['validateTokens'])
|
||||
->getMock();
|
||||
$container->set('cache_contexts_manager', $cache_context_manager);
|
||||
$cache_context_manager->expects($this->any())
|
||||
|
||||
@@ -9,12 +9,19 @@ namespace Drupal\Tests\Core\Plugin;
|
||||
|
||||
use Drupal\Component\Plugin\ConfigurablePluginInterface;
|
||||
use Drupal\Component\Plugin\Exception\ContextException;
|
||||
use Drupal\Core\Cache\NullBackend;
|
||||
use Drupal\Core\DependencyInjection\ClassResolverInterface;
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Plugin\Context\ContextDefinition;
|
||||
use Drupal\Core\Plugin\Context\ContextHandler;
|
||||
use Drupal\Core\Plugin\ContextAwarePluginInterface;
|
||||
use Drupal\Core\TypedData\DataDefinition;
|
||||
use Drupal\Core\TypedData\Plugin\DataType\StringData;
|
||||
use Drupal\Core\TypedData\TypedDataManager;
|
||||
use Drupal\Core\Validation\ConstraintManager;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Prophecy\Argument;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Core\Plugin\Context\ContextHandler
|
||||
@@ -36,6 +43,26 @@ class ContextHandlerTest extends UnitTestCase {
|
||||
parent::setUp();
|
||||
|
||||
$this->contextHandler = new ContextHandler();
|
||||
|
||||
$namespaces = new \ArrayObject([
|
||||
'Drupal\\Core\\TypedData' => $this->root . '/core/lib/Drupal/Core/TypedData',
|
||||
'Drupal\\Core\\Validation' => $this->root . '/core/lib/Drupal/Core/Validation',
|
||||
]);
|
||||
$cache_backend = new NullBackend('cache');
|
||||
$module_handler = $this->prophesize(ModuleHandlerInterface::class);
|
||||
$class_resolver = $this->prophesize(ClassResolverInterface::class);
|
||||
$class_resolver->getInstanceFromDefinition(Argument::type('string'))->will(function ($arguments) {
|
||||
$class_name = $arguments[0];
|
||||
return new $class_name();
|
||||
});
|
||||
$type_data_manager = new TypedDataManager($namespaces, $cache_backend, $module_handler->reveal(), $class_resolver->reveal());
|
||||
$type_data_manager->setValidationConstraintManager(
|
||||
new ConstraintManager($namespaces, $cache_backend, $module_handler->reveal())
|
||||
);
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
$container->set('typed_data_manager', $type_data_manager);
|
||||
\Drupal::setContainer($container);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,10 +87,10 @@ class ContextHandlerTest extends UnitTestCase {
|
||||
$context_any = $this->getMock('Drupal\Core\Plugin\Context\ContextInterface');
|
||||
$context_any->expects($this->atLeastOnce())
|
||||
->method('getContextDefinition')
|
||||
->will($this->returnValue(new ContextDefinition('empty')));
|
||||
->will($this->returnValue(new ContextDefinition('any')));
|
||||
|
||||
$requirement_specific = new ContextDefinition('specific');
|
||||
$requirement_specific->setConstraints(['bar' => 'baz']);
|
||||
$requirement_specific = new ContextDefinition('string');
|
||||
$requirement_specific->setConstraints(['Blank' => []]);
|
||||
|
||||
$context_constraint_mismatch = $this->getMock('Drupal\Core\Plugin\Context\ContextInterface');
|
||||
$context_constraint_mismatch->expects($this->atLeastOnce())
|
||||
@@ -74,8 +101,8 @@ class ContextHandlerTest extends UnitTestCase {
|
||||
->method('getContextDefinition')
|
||||
->will($this->returnValue(new ContextDefinition('fuzzy')));
|
||||
|
||||
$context_definition_specific = new ContextDefinition('specific');
|
||||
$context_definition_specific->setConstraints(['bar' => 'baz']);
|
||||
$context_definition_specific = new ContextDefinition('string');
|
||||
$context_definition_specific->setConstraints(['Blank' => []]);
|
||||
$context_specific = $this->getMock('Drupal\Core\Plugin\Context\ContextInterface');
|
||||
$context_specific->expects($this->atLeastOnce())
|
||||
->method('getContextDefinition')
|
||||
@@ -112,13 +139,13 @@ class ContextHandlerTest extends UnitTestCase {
|
||||
public function providerTestGetMatchingContexts() {
|
||||
$requirement_any = new ContextDefinition();
|
||||
|
||||
$requirement_specific = new ContextDefinition('specific');
|
||||
$requirement_specific->setConstraints(['bar' => 'baz']);
|
||||
$requirement_specific = new ContextDefinition('string');
|
||||
$requirement_specific->setConstraints(['Blank' => []]);
|
||||
|
||||
$context_any = $this->getMock('Drupal\Core\Plugin\Context\ContextInterface');
|
||||
$context_any->expects($this->atLeastOnce())
|
||||
->method('getContextDefinition')
|
||||
->will($this->returnValue(new ContextDefinition('empty')));
|
||||
->will($this->returnValue(new ContextDefinition('any')));
|
||||
$context_constraint_mismatch = $this->getMock('Drupal\Core\Plugin\Context\ContextInterface');
|
||||
$context_constraint_mismatch->expects($this->atLeastOnce())
|
||||
->method('getContextDefinition')
|
||||
@@ -127,8 +154,8 @@ class ContextHandlerTest extends UnitTestCase {
|
||||
$context_datatype_mismatch->expects($this->atLeastOnce())
|
||||
->method('getContextDefinition')
|
||||
->will($this->returnValue(new ContextDefinition('fuzzy')));
|
||||
$context_definition_specific = new ContextDefinition('specific');
|
||||
$context_definition_specific->setConstraints(['bar' => 'baz']);
|
||||
$context_definition_specific = new ContextDefinition('string');
|
||||
$context_definition_specific->setConstraints(['Blank' => []]);
|
||||
$context_specific = $this->getMock('Drupal\Core\Plugin\Context\ContextInterface');
|
||||
$context_specific->expects($this->atLeastOnce())
|
||||
->method('getContextDefinition')
|
||||
@@ -158,7 +185,7 @@ class ContextHandlerTest extends UnitTestCase {
|
||||
public function testFilterPluginDefinitionsByContexts($has_context, $definitions, $expected) {
|
||||
if ($has_context) {
|
||||
$context = $this->getMock('Drupal\Core\Plugin\Context\ContextInterface');
|
||||
$expected_context_definition = (new ContextDefinition('expected_data_type'))->setConstraints(['expected_constraint_name' => 'expected_constraint_value']);
|
||||
$expected_context_definition = (new ContextDefinition('string'))->setConstraints(['Blank' => []]);
|
||||
$context->expects($this->atLeastOnce())
|
||||
->method('getContextDefinition')
|
||||
->will($this->returnValue($expected_context_definition));
|
||||
@@ -189,7 +216,7 @@ class ContextHandlerTest extends UnitTestCase {
|
||||
// No context, all plugins available.
|
||||
$data[] = [FALSE, $plugins, $plugins];
|
||||
|
||||
$plugins = ['expected_plugin' => ['context' => ['context1' => new ContextDefinition('expected_data_type')]]];
|
||||
$plugins = ['expected_plugin' => ['context' => ['context1' => new ContextDefinition('string')]]];
|
||||
// Missing context, no plugins available.
|
||||
$data[] = [FALSE, $plugins, []];
|
||||
// Satisfied context, all plugins available.
|
||||
@@ -206,7 +233,7 @@ class ContextHandlerTest extends UnitTestCase {
|
||||
// Optional mismatched constraint, all plugins available.
|
||||
$data[] = [FALSE, $plugins, $plugins];
|
||||
|
||||
$expected_context_definition = (new ContextDefinition('expected_data_type'))->setConstraints(['expected_constraint_name' => 'expected_constraint_value']);
|
||||
$expected_context_definition = (new ContextDefinition('string'))->setConstraints(['Blank' => []]);
|
||||
$plugins = ['expected_plugin' => ['context' => ['context1' => $expected_context_definition]]];
|
||||
// Satisfied context with constraint, all plugins available.
|
||||
$data[] = [TRUE, $plugins, $plugins];
|
||||
@@ -220,7 +247,7 @@ class ContextHandlerTest extends UnitTestCase {
|
||||
$unexpected_context_definition = (new ContextDefinition('unexpected_data_type'))->setConstraints(['mismatched_constraint_name' => 'mismatched_constraint_value']);
|
||||
$plugins = [
|
||||
'unexpected_plugin' => ['context' => ['context1' => $unexpected_context_definition]],
|
||||
'expected_plugin' => ['context' => ['context2' => new ContextDefinition('expected_data_type')]],
|
||||
'expected_plugin' => ['context' => ['context2' => new ContextDefinition('string')]],
|
||||
];
|
||||
// Context only satisfies one plugin.
|
||||
$data[] = [TRUE, $plugins, ['expected_plugin' => $plugins['expected_plugin']]];
|
||||
|
||||
@@ -38,6 +38,7 @@ class BubbleableMetadataTest extends UnitTestCase {
|
||||
if (!$b instanceof BubbleableMetadata) {
|
||||
$renderer = $this->getMockBuilder('Drupal\Core\Render\Renderer')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['mergeAttachments'])
|
||||
->getMock();
|
||||
$renderer->expects($this->never())
|
||||
->method('mergeAttachments');
|
||||
|
||||
@@ -42,17 +42,28 @@ class ContentTypeHeaderMatcherTest extends UnitTestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that routes are not filtered on GET requests.
|
||||
* Tests that routes are not filtered on safe requests.
|
||||
*
|
||||
* @dataProvider providerTestSafeRequestFilter
|
||||
*/
|
||||
public function testGetRequestFilter() {
|
||||
public function testSafeRequestFilter($method) {
|
||||
$collection = $this->fixtures->sampleRouteCollection();
|
||||
$collection->addCollection($this->fixtures->contentRouteCollection());
|
||||
|
||||
$request = Request::create('path/two', 'GET');
|
||||
$request = Request::create('path/two', $method);
|
||||
$routes = $this->matcher->filter($collection, $request);
|
||||
$this->assertEquals(count($routes), 7, 'The correct number of routes was found.');
|
||||
}
|
||||
|
||||
public function providerTestSafeRequestFilter() {
|
||||
return [
|
||||
['GET'],
|
||||
['HEAD'],
|
||||
['OPTIONS'],
|
||||
['TRACE'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that XML-restricted routes get filtered out on JSON requests.
|
||||
*/
|
||||
|
||||
@@ -15,34 +15,6 @@ use Symfony\Component\Routing\RouteCollection;
|
||||
*/
|
||||
class MethodFilterTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @covers ::applies
|
||||
* @dataProvider providerApplies
|
||||
*/
|
||||
public function testApplies(array $route_methods, $expected_applies) {
|
||||
$route = new Route('/test', [], [], [], '', [], $route_methods);
|
||||
$method_filter = new MethodFilter();
|
||||
|
||||
$this->assertSame($expected_applies, $method_filter->applies($route));
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testApplies().
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function providerApplies() {
|
||||
return [
|
||||
'only GET' => [['GET'], TRUE],
|
||||
'only PATCH' => [['PATCH'], TRUE],
|
||||
'only POST' => [['POST'], TRUE],
|
||||
'only DELETE' => [['DELETE'], TRUE],
|
||||
'only HEAD' => [['HEAD'], TRUE],
|
||||
'all' => [['GET', 'PATCH', 'POST', 'DELETE', 'HEAD'], TRUE],
|
||||
'none' => [[], FALSE],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::filter
|
||||
*/
|
||||
@@ -125,4 +97,22 @@ class MethodFilterTest extends UnitTestCase {
|
||||
$this->assertEquals($expected_collection, $result_collection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that the incoming and outgoing collections have the same order.
|
||||
*
|
||||
* @covers ::filter
|
||||
*/
|
||||
public function testCollectionOrder() {
|
||||
$request = Request::create('/test', 'GET');
|
||||
|
||||
$collection = new RouteCollection();
|
||||
$collection->add('entity.taxonomy_term.canonical', new Route('/test'));
|
||||
$collection->add('views.view.taxonomy_term_page', new Route('/test', [], [], [], '', [], ['GET', 'POST']));
|
||||
|
||||
$method_filter = new MethodFilter();
|
||||
$result_collection = $method_filter->filter($collection, $request);
|
||||
|
||||
$this->assertEquals(['entity.taxonomy_term.canonical', 'views.view.taxonomy_term_page'], array_keys($result_collection->all()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,25 +15,6 @@ use Symfony\Component\Routing\RouteCollection;
|
||||
*/
|
||||
class RequestFormatRouteFilterTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @covers ::applies
|
||||
*/
|
||||
public function testAppliesWithoutFormat() {
|
||||
$route_filter = new RequestFormatRouteFilter();
|
||||
$route = new Route('/test');
|
||||
$this->assertFalse($route_filter->applies($route));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::applies
|
||||
*/
|
||||
public function testAppliesWithFormat() {
|
||||
$route_filter = new RequestFormatRouteFilter();
|
||||
$route = new Route('/test');
|
||||
$route->setRequirement('_format', 'json');
|
||||
$this->assertTrue($route_filter->applies($route));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::filter
|
||||
* @dataProvider filterProvider
|
||||
@@ -65,6 +46,7 @@ class RequestFormatRouteFilterTest extends UnitTestCase {
|
||||
$sole_route_match_single_format->add('sole_route_single_format', $route_with_format);
|
||||
|
||||
return [
|
||||
'nothing requested' => [clone $collection, '', ['test_0']],
|
||||
'xml requested' => [clone $collection, 'xml', ['test_2', 'test_0']],
|
||||
'json requested' => [clone $collection, 'json', ['test_1', 'test_2', 'test_0']],
|
||||
'html format requested' => [clone $collection, 'html', ['test_0']],
|
||||
|
||||
@@ -43,7 +43,7 @@ class WriteSafeSessionHandlerTest extends UnitTestCase {
|
||||
$session_id = 'some-id';
|
||||
$session_data = 'serialized-session-data';
|
||||
|
||||
$this->assertSame($this->sessionHandler->isSessionWritable(), TRUE);
|
||||
$this->assertSame(TRUE, $this->sessionHandler->isSessionWritable());
|
||||
|
||||
// Writing should be enabled, return value passed to the caller by default.
|
||||
$this->wrappedSessionHandler->expects($this->at(0))
|
||||
@@ -57,10 +57,10 @@ class WriteSafeSessionHandlerTest extends UnitTestCase {
|
||||
->will($this->returnValue(FALSE));
|
||||
|
||||
$result = $this->sessionHandler->write($session_id, $session_data);
|
||||
$this->assertSame($result, TRUE);
|
||||
$this->assertSame(TRUE, $result);
|
||||
|
||||
$result = $this->sessionHandler->write($session_id, $session_data);
|
||||
$this->assertSame($result, FALSE);
|
||||
$this->assertSame(FALSE, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,10 +77,10 @@ class WriteSafeSessionHandlerTest extends UnitTestCase {
|
||||
// Disable writing upon construction.
|
||||
$this->sessionHandler = new WriteSafeSessionHandler($this->wrappedSessionHandler, FALSE);
|
||||
|
||||
$this->assertSame($this->sessionHandler->isSessionWritable(), FALSE);
|
||||
$this->assertSame(FALSE, $this->sessionHandler->isSessionWritable());
|
||||
|
||||
$result = $this->sessionHandler->write($session_id, $session_data);
|
||||
$this->assertSame($result, TRUE);
|
||||
$this->assertSame(TRUE, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,22 +93,22 @@ class WriteSafeSessionHandlerTest extends UnitTestCase {
|
||||
$session_id = 'some-id';
|
||||
$session_data = 'serialized-session-data';
|
||||
|
||||
$this->assertSame($this->sessionHandler->isSessionWritable(), TRUE);
|
||||
$this->assertSame(TRUE, $this->sessionHandler->isSessionWritable());
|
||||
|
||||
// Disable writing after construction.
|
||||
$this->sessionHandler->setSessionWritable(FALSE);
|
||||
$this->assertSame($this->sessionHandler->isSessionWritable(), FALSE);
|
||||
$this->assertSame(FALSE, $this->sessionHandler->isSessionWritable());
|
||||
|
||||
$this->sessionHandler = new WriteSafeSessionHandler($this->wrappedSessionHandler, FALSE);
|
||||
|
||||
$this->assertSame($this->sessionHandler->isSessionWritable(), FALSE);
|
||||
$this->assertSame(FALSE, $this->sessionHandler->isSessionWritable());
|
||||
|
||||
$result = $this->sessionHandler->write($session_id, $session_data);
|
||||
$this->assertSame($result, TRUE);
|
||||
$this->assertSame(TRUE, $result);
|
||||
|
||||
// Enable writing again.
|
||||
$this->sessionHandler->setSessionWritable(TRUE);
|
||||
$this->assertSame($this->sessionHandler->isSessionWritable(), TRUE);
|
||||
$this->assertSame(TRUE, $this->sessionHandler->isSessionWritable());
|
||||
|
||||
// Writing should be enabled, return value passed to the caller by default.
|
||||
$this->wrappedSessionHandler->expects($this->at(0))
|
||||
@@ -122,10 +122,10 @@ class WriteSafeSessionHandlerTest extends UnitTestCase {
|
||||
->will($this->returnValue(FALSE));
|
||||
|
||||
$result = $this->sessionHandler->write($session_id, $session_data);
|
||||
$this->assertSame($result, TRUE);
|
||||
$this->assertSame(TRUE, $result);
|
||||
|
||||
$result = $this->sessionHandler->write($session_id, $session_data);
|
||||
$this->assertSame($result, FALSE);
|
||||
$this->assertSame(FALSE, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -148,13 +148,13 @@ class WriteSafeSessionHandlerTest extends UnitTestCase {
|
||||
call_user_func_array([$invocation, 'with'], $args);
|
||||
|
||||
// Test with writable session.
|
||||
$this->assertSame($this->sessionHandler->isSessionWritable(), TRUE);
|
||||
$this->assertSame(TRUE, $this->sessionHandler->isSessionWritable());
|
||||
$actual_result = call_user_func_array([$this->sessionHandler, $method], $args);
|
||||
$this->assertSame($expected_result, $actual_result);
|
||||
|
||||
// Test with non-writable session.
|
||||
$this->sessionHandler->setSessionWritable(FALSE);
|
||||
$this->assertSame($this->sessionHandler->isSessionWritable(), FALSE);
|
||||
$this->assertSame(FALSE, $this->sessionHandler->isSessionWritable());
|
||||
$actual_result = call_user_func_array([$this->sessionHandler, $method], $args);
|
||||
$this->assertSame($expected_result, $actual_result);
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user