Update Composer, update everything
This commit is contained in:
parent
ea3e94409f
commit
dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions
|
@ -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() {}
|
||||
|
||||
}
|
|
@ -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 {}
|
|
@ -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'));
|
||||
}
|
||||
|
||||
}
|
|
@ -6,13 +6,13 @@ use Drupal\Component\Annotation\Plugin;
|
|||
use Drupal\Component\Annotation\Plugin\Discovery\AnnotationBridgeDecorator;
|
||||
use Drupal\Component\Plugin\Definition\PluginDefinition;
|
||||
use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Component\Annotation\Plugin\Discovery\AnnotationBridgeDecorator
|
||||
* @group Plugin
|
||||
*/
|
||||
class AnnotationBridgeDecoratorTest extends UnitTestCase {
|
||||
class AnnotationBridgeDecoratorTest extends TestCase {
|
||||
|
||||
/**
|
||||
* @covers ::getDefinitions
|
||||
|
@ -35,6 +35,9 @@ class AnnotationBridgeDecoratorTest extends UnitTestCase {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@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';
|
||||
|
||||
}
|
|
@ -7,14 +7,14 @@
|
|||
|
||||
namespace Drupal\Tests\Component\Assertion;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Drupal\Component\Assertion\Inspector;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Component\Assertion\Inspector
|
||||
* @group Assertion
|
||||
*/
|
||||
class InspectorTest extends PHPUnit_Framework_TestCase {
|
||||
class InspectorTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Tests asserting argument is an array or traversable object.
|
||||
|
@ -157,19 +157,19 @@ class InspectorTest extends PHPUnit_Framework_TestCase {
|
|||
'strchr',
|
||||
[$this, 'callMe'],
|
||||
[__CLASS__, 'callMeStatic'],
|
||||
function() {
|
||||
function () {
|
||||
return TRUE;
|
||||
}
|
||||
},
|
||||
]));
|
||||
|
||||
$this->assertFalse(Inspector::assertAllCallable([
|
||||
'strchr',
|
||||
[$this, 'callMe'],
|
||||
[__CLASS__, 'callMeStatic'],
|
||||
function() {
|
||||
function () {
|
||||
return TRUE;
|
||||
},
|
||||
"I'm not callable"
|
||||
"I'm not callable",
|
||||
]));
|
||||
}
|
||||
|
||||
|
@ -256,6 +256,7 @@ class InspectorTest extends PHPUnit_Framework_TestCase {
|
|||
* Quick class for testing for objects with __toString.
|
||||
*/
|
||||
class StringObject {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
@ -3,17 +3,21 @@
|
|||
namespace Drupal\Tests\Component\Bridge;
|
||||
|
||||
use Drupal\Component\Bridge\ZfExtensionManagerSfContainer;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
|
||||
use Zend\Feed\Reader\Extension\Atom\Entry;
|
||||
use Zend\Feed\Reader\StandaloneExtensionManager;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Component\Bridge\ZfExtensionManagerSfContainer
|
||||
* @group Bridge
|
||||
*/
|
||||
class ZfExtensionManagerSfContainerTest extends UnitTestCase {
|
||||
class ZfExtensionManagerSfContainerTest extends TestCase {
|
||||
|
||||
/**
|
||||
* @covers ::setContainer
|
||||
* @covers ::setStandalone
|
||||
* @covers ::get
|
||||
*/
|
||||
public function testGet() {
|
||||
|
@ -24,10 +28,16 @@ class ZfExtensionManagerSfContainerTest extends UnitTestCase {
|
|||
$bridge = new ZfExtensionManagerSfContainer();
|
||||
$bridge->setContainer($container);
|
||||
$this->assertEquals($service, $bridge->get('foo'));
|
||||
$bridge->setStandalone(StandaloneExtensionManager::class);
|
||||
$this->assertInstanceOf(Entry::class, $bridge->get('Atom\Entry'));
|
||||
// Ensure that the container is checked first.
|
||||
$container->set('atomentry', $service);
|
||||
$this->assertEquals($service, $bridge->get('Atom\Entry'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::setContainer
|
||||
* @covers ::setStandalone
|
||||
* @covers ::has
|
||||
*/
|
||||
public function testHas() {
|
||||
|
@ -39,6 +49,42 @@ class ZfExtensionManagerSfContainerTest extends UnitTestCase {
|
|||
$bridge->setContainer($container);
|
||||
$this->assertTrue($bridge->has('foo'));
|
||||
$this->assertFalse($bridge->has('bar'));
|
||||
$this->assertFalse($bridge->has('Atom\Entry'));
|
||||
$bridge->setStandalone(StandaloneExtensionManager::class);
|
||||
$this->assertTrue($bridge->has('Atom\Entry'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::setStandalone
|
||||
*/
|
||||
public function testSetStandaloneException() {
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(\RuntimeException::class);
|
||||
$this->expectExceptionMessage('Drupal\Tests\Component\Bridge\ZfExtensionManagerSfContainerTest must implement Zend\Feed\Reader\ExtensionManagerInterface or Zend\Feed\Writer\ExtensionManagerInterface');
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(\RuntimeException::class, 'Drupal\Tests\Component\Bridge\ZfExtensionManagerSfContainerTest must implement Zend\Feed\Reader\ExtensionManagerInterface or Zend\Feed\Writer\ExtensionManagerInterface');
|
||||
}
|
||||
$bridge = new ZfExtensionManagerSfContainer();
|
||||
$bridge->setStandalone(static::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::get
|
||||
*/
|
||||
public function testGetContainerException() {
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(ServiceNotFoundException::class);
|
||||
$this->expectExceptionMessage('You have requested a non-existent service "test.foo".');
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(ServiceNotFoundException::class, 'You have requested a non-existent service "test.foo".');
|
||||
}
|
||||
$container = new ContainerBuilder();
|
||||
$bridge = new ZfExtensionManagerSfContainer('test.');
|
||||
$bridge->setContainer($container);
|
||||
$bridge->setStandalone(StandaloneExtensionManager::class);
|
||||
$bridge->get('foo');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,13 +4,13 @@ namespace Drupal\Tests\Component\ClassFinder;
|
|||
|
||||
use Composer\Autoload\ClassLoader;
|
||||
use Drupal\Component\ClassFinder\ClassFinder;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Component\ClassFinder\ClassFinder
|
||||
* @group ClassFinder
|
||||
*/
|
||||
class ClassFinderTest extends UnitTestCase {
|
||||
class ClassFinderTest extends TestCase {
|
||||
|
||||
/**
|
||||
* @covers ::findFile
|
||||
|
@ -20,7 +20,7 @@ class ClassFinderTest extends UnitTestCase {
|
|||
|
||||
// The full path is returned therefore only tests with
|
||||
// assertStringEndsWith() so the test is portable.
|
||||
$this->assertStringEndsWith('core/tests/Drupal/Tests/UnitTestCase.php', $finder->findFile(UnitTestCase::class));
|
||||
$this->assertStringEndsWith('core/tests/Drupal/Tests/Component/ClassFinder/ClassFinderTest.php', $finder->findFile(ClassFinderTest::class));
|
||||
$class = 'Not\\A\\Class';
|
||||
$this->assertNull($finder->findFile($class));
|
||||
|
||||
|
@ -30,7 +30,7 @@ class ClassFinderTest extends UnitTestCase {
|
|||
$loader->register();
|
||||
$this->assertEquals(__FILE__, $finder->findFile($class));
|
||||
// This shouldn't prevent us from finding the original file.
|
||||
$this->assertStringEndsWith('core/tests/Drupal/Tests/UnitTestCase.php', $finder->findFile(UnitTestCase::class));
|
||||
$this->assertStringEndsWith('core/tests/Drupal/Tests/Component/ClassFinder/ClassFinderTest.php', $finder->findFile(ClassFinderTest::class));
|
||||
|
||||
// Clean up the additional autoloader after the test.
|
||||
$loader->unregister();
|
||||
|
|
|
@ -2,14 +2,14 @@
|
|||
|
||||
namespace Drupal\Tests\Component\Datetime;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\Component\Datetime\DateTimePlus;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Component\Datetime\DateTimePlus
|
||||
* @group Datetime
|
||||
*/
|
||||
class DateTimePlusTest extends UnitTestCase {
|
||||
class DateTimePlusTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Test creating dates from string and array input.
|
||||
|
@ -87,7 +87,13 @@ class DateTimePlusTest extends UnitTestCase {
|
|||
* @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 UnitTestCase {
|
|||
* @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)
|
||||
|
@ -167,7 +178,7 @@ class DateTimePlusTest extends UnitTestCase {
|
|||
* Assertion helper for testTimestamp and testDateTimestamp since they need
|
||||
* different dataProviders.
|
||||
*
|
||||
* @param DateTimePlus $date
|
||||
* @param \Drupal\Component\Datetime\DateTimePlus $date
|
||||
* DateTimePlus to test.
|
||||
* @input mixed $input
|
||||
* The original input passed to the test method.
|
||||
|
@ -242,7 +253,12 @@ class DateTimePlusTest extends UnitTestCase {
|
|||
* @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);
|
||||
}
|
||||
|
||||
|
@ -293,7 +309,7 @@ class DateTimePlusTest extends UnitTestCase {
|
|||
* @see DateTimePlusTest::testDates()
|
||||
*/
|
||||
public function providerTestDates() {
|
||||
return [
|
||||
$dates = [
|
||||
// String input.
|
||||
// Create date object from datetime string.
|
||||
['2009-03-07 10:30', 'America/Chicago', '2009-03-07T10:30:00-06:00'],
|
||||
|
@ -308,6 +324,19 @@ class DateTimePlusTest extends UnitTestCase {
|
|||
// Same during daylight savings time.
|
||||
['2009-06-07 10:30', 'Australia/Canberra', '2009-06-07T10:30:00+10:00'],
|
||||
];
|
||||
|
||||
// On 32-bit systems, timestamps are limited to 1901-2038.
|
||||
if (PHP_INT_SIZE > 4) {
|
||||
// Create a date object in the distant past.
|
||||
// @see https://www.drupal.org/node/2795489#comment-12127088
|
||||
if (version_compare(PHP_VERSION, '5.6.15', '>=')) {
|
||||
$dates[] = ['1809-02-12 10:30', 'America/Chicago', '1809-02-12T10:30:00-06:00'];
|
||||
}
|
||||
// Create a date object in the far future.
|
||||
$dates[] = ['2345-01-02 02:04', 'UTC', '2345-01-02T02:04:00+00:00'];
|
||||
}
|
||||
|
||||
return $dates;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -320,7 +349,7 @@ class DateTimePlusTest extends UnitTestCase {
|
|||
* @see DateTimePlusTest::testDates()
|
||||
*/
|
||||
public function providerTestDateArrays() {
|
||||
return [
|
||||
$dates = [
|
||||
// Array input.
|
||||
// Create date object from date array, date only.
|
||||
[['year' => 2010, 'month' => 2, 'day' => 28], 'America/Chicago', '2010-02-28T00:00:00-06:00'],
|
||||
|
@ -331,6 +360,19 @@ class DateTimePlusTest extends UnitTestCase {
|
|||
// Create date object from date array with hour.
|
||||
[['year' => 2010, 'month' => 2, 'day' => 28, 'hour' => 10], 'Europe/Berlin', '2010-02-28T10:00:00+01:00'],
|
||||
];
|
||||
|
||||
// On 32-bit systems, timestamps are limited to 1901-2038.
|
||||
if (PHP_INT_SIZE > 4) {
|
||||
// Create a date object in the distant past.
|
||||
// @see https://www.drupal.org/node/2795489#comment-12127088
|
||||
if (version_compare(PHP_VERSION, '5.6.15', '>=')) {
|
||||
$dates[] = [['year' => 1809, 'month' => 2, 'day' => 12], 'America/Chicago', '1809-02-12T00:00:00-06:00'];
|
||||
}
|
||||
// Create a date object in the far future.
|
||||
$dates[] = [['year' => 2345, 'month' => 1, 'day' => 2], 'UTC', '2345-01-02T00:00:00+00:00'];
|
||||
}
|
||||
|
||||
return $dates;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -765,7 +807,7 @@ class DateTimePlusTest extends UnitTestCase {
|
|||
public function testValidateFormat() {
|
||||
// Check that an input that does not strictly follow the input format will
|
||||
// produce the desired date. In this case the year string '11' doesn't
|
||||
// precisely match the 'Y' formater parameter, but PHP will parse it
|
||||
// precisely match the 'Y' formatter parameter, but PHP will parse it
|
||||
// regardless. However, when formatted with the same string, the year will
|
||||
// be output with four digits. With the ['validate_format' => FALSE]
|
||||
// $settings, this will not thrown an exception.
|
||||
|
@ -774,8 +816,104 @@ class DateTimePlusTest extends UnitTestCase {
|
|||
|
||||
// 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.
|
||||
*
|
||||
* @covers ::__call
|
||||
*/
|
||||
public function testChainable() {
|
||||
$date = new DateTimePlus('now', 'Australia/Sydney');
|
||||
|
||||
$date->setTimestamp(12345678);
|
||||
$rendered = $date->render();
|
||||
$this->assertEquals('1970-05-24 07:21:18 Australia/Sydney', $rendered);
|
||||
|
||||
$date->setTimestamp(23456789);
|
||||
$rendered = $date->setTimezone(new \DateTimeZone('America/New_York'))->render();
|
||||
$this->assertEquals('1970-09-29 07:46:29 America/New_York', $rendered);
|
||||
|
||||
$date = DateTimePlus::createFromFormat('Y-m-d H:i:s', '1970-05-24 07:21:18', new \DateTimeZone('Australia/Sydney'))
|
||||
->setTimezone(new \DateTimeZone('America/New_York'));
|
||||
$rendered = $date->render();
|
||||
$this->assertInstanceOf(DateTimePlus::class, $date);
|
||||
$this->assertEquals(12345678, $date->getTimestamp());
|
||||
$this->assertEquals('1970-05-23 17:21:18 America/New_York', $rendered);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that non-chainable methods work.
|
||||
*
|
||||
* @covers ::__call
|
||||
*/
|
||||
public function testChainableNonChainable() {
|
||||
$datetime1 = new DateTimePlus('2009-10-11 12:00:00');
|
||||
$datetime2 = new DateTimePlus('2009-10-13 12:00:00');
|
||||
$interval = $datetime1->diff($datetime2);
|
||||
$this->assertInstanceOf(\DateInterval::class, $interval);
|
||||
$this->assertEquals('+2 days', $interval->format('%R%a days'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that chained calls to non-existent functions throw an exception.
|
||||
*
|
||||
* @covers ::__call
|
||||
*/
|
||||
public function testChainableNonCallable() {
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getPhpDateTime
|
||||
*/
|
||||
public function testGetPhpDateTime() {
|
||||
$new_york = new \DateTimeZone('America/New_York');
|
||||
$berlin = new \DateTimeZone('Europe/Berlin');
|
||||
|
||||
// Test retrieving a cloned copy of the wrapped \DateTime object, and that
|
||||
// altering it does not change the DateTimePlus object.
|
||||
$datetimeplus = DateTimePlus::createFromFormat('Y-m-d H:i:s', '2017-07-13 22:40:00', $new_york, ['langcode' => 'en']);
|
||||
$this->assertEquals(1500000000, $datetimeplus->getTimestamp());
|
||||
$this->assertEquals('America/New_York', $datetimeplus->getTimezone()->getName());
|
||||
|
||||
$datetime = $datetimeplus->getPhpDateTime();
|
||||
$this->assertInstanceOf('DateTime', $datetime);
|
||||
$this->assertEquals(1500000000, $datetime->getTimestamp());
|
||||
$this->assertEquals('America/New_York', $datetime->getTimezone()->getName());
|
||||
|
||||
$datetime->setTimestamp(1400000000)->setTimezone($berlin);
|
||||
$this->assertEquals(1400000000, $datetime->getTimestamp());
|
||||
$this->assertEquals('Europe/Berlin', $datetime->getTimezone()->getName());
|
||||
$this->assertEquals(1500000000, $datetimeplus->getTimestamp());
|
||||
$this->assertEquals('America/New_York', $datetimeplus->getTimezone()->getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace Drupal\Tests\Component\Datetime;
|
||||
|
||||
use Drupal\Component\Datetime\Time;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
|
@ -15,7 +15,7 @@ use Symfony\Component\HttpFoundation\Request;
|
|||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
class TimeTest extends UnitTestCase {
|
||||
class TimeTest extends TestCase {
|
||||
|
||||
/**
|
||||
* The mocked request stack.
|
||||
|
@ -37,8 +37,7 @@ class TimeTest extends UnitTestCase {
|
|||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
namespace Drupal\Tests\Component\DependencyInjection;
|
||||
|
||||
use Drupal\Component\Utility\Crypt;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\DependencyInjection\Exception\LogicException;
|
||||
|
@ -21,7 +22,7 @@ use Prophecy\Argument;
|
|||
* @coversDefaultClass \Drupal\Component\DependencyInjection\Container
|
||||
* @group DependencyInjection
|
||||
*/
|
||||
class ContainerTest extends \PHPUnit_Framework_TestCase {
|
||||
class ContainerTest extends TestCase {
|
||||
|
||||
/**
|
||||
* The tested container.
|
||||
|
@ -69,7 +70,12 @@ class ContainerTest extends \PHPUnit_Framework_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);
|
||||
}
|
||||
|
||||
|
@ -92,7 +98,12 @@ class ContainerTest extends \PHPUnit_Framework_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');
|
||||
}
|
||||
|
||||
|
@ -102,7 +113,12 @@ class ContainerTest extends \PHPUnit_Framework_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);
|
||||
}
|
||||
|
||||
|
@ -136,7 +152,12 @@ class ContainerTest extends \PHPUnit_Framework_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');
|
||||
}
|
||||
|
||||
|
@ -241,7 +262,12 @@ class ContainerTest extends \PHPUnit_Framework_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');
|
||||
}
|
||||
|
||||
|
@ -254,7 +280,12 @@ class ContainerTest extends \PHPUnit_Framework_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');
|
||||
}
|
||||
|
||||
|
@ -303,7 +334,12 @@ class ContainerTest extends \PHPUnit_Framework_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');
|
||||
}
|
||||
|
||||
|
@ -315,7 +351,12 @@ class ContainerTest extends \PHPUnit_Framework_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');
|
||||
}
|
||||
|
||||
|
@ -340,7 +381,12 @@ class ContainerTest extends \PHPUnit_Framework_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');
|
||||
}
|
||||
|
||||
|
@ -360,7 +406,12 @@ class ContainerTest extends \PHPUnit_Framework_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);
|
||||
}
|
||||
|
||||
|
@ -386,7 +437,12 @@ class ContainerTest extends \PHPUnit_Framework_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');
|
||||
}
|
||||
|
||||
|
@ -422,7 +478,12 @@ class ContainerTest extends \PHPUnit_Framework_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');
|
||||
}
|
||||
|
||||
|
@ -461,7 +522,12 @@ class ContainerTest extends \PHPUnit_Framework_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');
|
||||
}
|
||||
|
||||
|
@ -499,7 +565,12 @@ class ContainerTest extends \PHPUnit_Framework_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');
|
||||
}
|
||||
|
||||
|
@ -516,7 +587,7 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
|
|||
$configurator = $this->prophesize('\Drupal\Tests\Component\DependencyInjection\MockConfiguratorInterface');
|
||||
$configurator->configureService(Argument::type('object'))
|
||||
->shouldBeCalled(1)
|
||||
->will(function($args) use ($container) {
|
||||
->will(function ($args) use ($container) {
|
||||
$args[0]->setContainer($container);
|
||||
});
|
||||
$container->set('configurator', $configurator->reveal());
|
||||
|
@ -597,7 +668,12 @@ class ContainerTest extends \PHPUnit_Framework_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');
|
||||
}
|
||||
|
||||
|
@ -611,7 +687,12 @@ class ContainerTest extends \PHPUnit_Framework_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.');
|
||||
}
|
||||
|
@ -653,46 +734,6 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
|
|||
$this->assertTrue($this->container->initialized('late.service_alias'), 'Late service is initialized after it was retrieved once.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that unsupported methods throw an Exception.
|
||||
*
|
||||
* @covers ::enterScope
|
||||
* @covers ::leaveScope
|
||||
* @covers ::addScope
|
||||
* @covers ::hasScope
|
||||
* @covers ::isScopeActive
|
||||
*
|
||||
* @dataProvider scopeExceptionTestProvider
|
||||
*/
|
||||
public function testScopeFunctionsWithException($method, $argument) {
|
||||
$callable = [
|
||||
$this->container,
|
||||
$method,
|
||||
];
|
||||
|
||||
$this->setExpectedException(\BadMethodCallException::class);
|
||||
$callable($argument);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for scopeExceptionTestProvider().
|
||||
*
|
||||
* @return array[]
|
||||
* Returns per data set an array with:
|
||||
* - method name to call
|
||||
* - argument to pass
|
||||
*/
|
||||
public function scopeExceptionTestProvider() {
|
||||
$scope = $this->prophesize('\Symfony\Component\DependencyInjection\ScopeInterface')->reveal();
|
||||
return [
|
||||
['enterScope', 'test_scope'],
|
||||
['leaveScope', 'test_scope'],
|
||||
['hasScope', 'test_scope'],
|
||||
['isScopeActive', 'test_scope'],
|
||||
['addScope', $scope],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that Container::getServiceIds() works properly.
|
||||
*
|
||||
|
@ -754,12 +795,18 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
|
|||
]),
|
||||
'properties' => $this->getCollection(['_someProperty' => 'foo']),
|
||||
'calls' => [
|
||||
['setContainer', $this->getCollection([
|
||||
$this->getServiceCall('service_container'),
|
||||
])],
|
||||
['setOtherConfigParameter', $this->getCollection([
|
||||
$this->getParameterCall('some_other_config'),
|
||||
])],
|
||||
[
|
||||
'setContainer',
|
||||
$this->getCollection([
|
||||
$this->getServiceCall('service_container'),
|
||||
]),
|
||||
],
|
||||
[
|
||||
'setOtherConfigParameter',
|
||||
$this->getCollection([
|
||||
$this->getParameterCall('some_other_config'),
|
||||
]),
|
||||
],
|
||||
],
|
||||
'priority' => 0,
|
||||
];
|
||||
|
@ -811,7 +858,8 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
|
|||
$services['invalid_argument_service'] = [
|
||||
'class' => '\Drupal\Tests\Component\DependencyInjection\MockService',
|
||||
'arguments' => $this->getCollection([
|
||||
1, // Test passing non-strings, too.
|
||||
// Test passing non-strings, too.
|
||||
1,
|
||||
(object) [
|
||||
'type' => 'invalid',
|
||||
],
|
||||
|
@ -863,9 +911,12 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
|
|||
[NULL, 'bar'],
|
||||
],
|
||||
'calls' => [
|
||||
['setContainer', $this->getCollection([
|
||||
$this->getServiceCall('service_container'),
|
||||
])],
|
||||
[
|
||||
'setContainer',
|
||||
$this->getCollection([
|
||||
$this->getServiceCall('service_container'),
|
||||
]),
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
|
@ -942,7 +993,7 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
|
|||
'arguments' => [],
|
||||
'configurator' => [
|
||||
$this->getServiceCall('configurator'),
|
||||
'configureService'
|
||||
'configureService',
|
||||
],
|
||||
];
|
||||
$services['configurable_service_exception'] = [
|
||||
|
@ -1072,7 +1123,7 @@ class MockInstantiationService {
|
|||
class MockService {
|
||||
|
||||
/**
|
||||
* @var ContainerInterface
|
||||
* @var \Symfony\Component\DependencyInjection\ContainerInterface
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
|
@ -1110,7 +1161,7 @@ class MockService {
|
|||
/**
|
||||
* Sets the container object.
|
||||
*
|
||||
* @param ContainerInterface $container
|
||||
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
|
||||
* The container to inject via setter injection.
|
||||
*/
|
||||
public function setContainer(ContainerInterface $container) {
|
||||
|
@ -1120,7 +1171,7 @@ class MockService {
|
|||
/**
|
||||
* Gets the container object.
|
||||
*
|
||||
* @return ContainerInterface
|
||||
* @return \Symfony\Component\DependencyInjection\ContainerInterface
|
||||
* The internally set container.
|
||||
*/
|
||||
public function getContainer() {
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
namespace Drupal\Tests\Component\DependencyInjection\Dumper {
|
||||
|
||||
use Drupal\Component\Utility\Crypt;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\DependencyInjection\Parameter;
|
||||
|
@ -21,7 +22,7 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
|
|||
* @coversDefaultClass \Drupal\Component\DependencyInjection\Dumper\OptimizedPhpArrayDumper
|
||||
* @group DependencyInjection
|
||||
*/
|
||||
class OptimizedPhpArrayDumperTest extends \PHPUnit_Framework_TestCase {
|
||||
class OptimizedPhpArrayDumperTest extends TestCase {
|
||||
|
||||
/**
|
||||
* The container builder instance.
|
||||
|
@ -67,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'] = [];
|
||||
|
@ -146,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');
|
||||
|
@ -211,6 +212,8 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
|
|||
* @covers ::getParameterCall
|
||||
*
|
||||
* @dataProvider getDefinitionsDataProvider
|
||||
*
|
||||
* @group legacy
|
||||
*/
|
||||
public function testGetServiceDefinitions($services, $definition_services) {
|
||||
$this->containerDefinition['services'] = $definition_services;
|
||||
|
@ -248,7 +251,6 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
|
|||
'arguments_count' => 0,
|
||||
'properties' => [],
|
||||
'calls' => [],
|
||||
'scope' => ContainerInterface::SCOPE_CONTAINER,
|
||||
'shared' => TRUE,
|
||||
'factory' => FALSE,
|
||||
'configurator' => FALSE,
|
||||
|
@ -360,11 +362,6 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
|
|||
'calls' => $calls,
|
||||
] + $base_service_definition;
|
||||
|
||||
$service_definitions[] = [
|
||||
'scope' => ContainerInterface::SCOPE_PROTOTYPE,
|
||||
'shared' => FALSE,
|
||||
] + $base_service_definition;
|
||||
|
||||
$service_definitions[] = [
|
||||
'shared' => FALSE,
|
||||
] + $base_service_definition;
|
||||
|
@ -407,7 +404,6 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
|
|||
$definition->getArguments()->willReturn($service_definition['arguments']);
|
||||
$definition->getProperties()->willReturn($service_definition['properties']);
|
||||
$definition->getMethodCalls()->willReturn($service_definition['calls']);
|
||||
$definition->getScope()->willReturn($service_definition['scope']);
|
||||
$definition->isShared()->willReturn($service_definition['shared']);
|
||||
$definition->getDecoratedService()->willReturn(NULL);
|
||||
$definition->getFactory()->willReturn($service_definition['factory']);
|
||||
|
@ -440,9 +436,6 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
|
|||
}
|
||||
}
|
||||
|
||||
// Remove any remaining scope.
|
||||
unset($filtered_service_definition['scope']);
|
||||
|
||||
if (isset($filtered_service_definition['public']) && $filtered_service_definition['public'] === FALSE) {
|
||||
$services_provided[] = [
|
||||
['foo_service' => $definition->reveal()],
|
||||
|
@ -480,27 +473,14 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the correct InvalidArgumentException is thrown for getScope().
|
||||
*
|
||||
* @covers ::getServiceDefinition
|
||||
*/
|
||||
public function testGetServiceDefinitionWithInvalidScope() {
|
||||
$bar_definition = new Definition('\stdClass');
|
||||
$bar_definition->setScope('foo_scope');
|
||||
$services['bar'] = $bar_definition;
|
||||
|
||||
$this->containerBuilder->getDefinitions()->willReturn($services);
|
||||
$this->setExpectedException(InvalidArgumentException::class);
|
||||
$this->dumper->getArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that references to aliases work correctly.
|
||||
*
|
||||
* @covers ::getReferenceCall
|
||||
*
|
||||
* @dataProvider publicPrivateDataProvider
|
||||
*
|
||||
* @group legacy
|
||||
*/
|
||||
public function testGetServiceDefinitionWithReferenceToAlias($public) {
|
||||
$bar_definition = new Definition('\stdClass');
|
||||
|
@ -556,6 +536,8 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
|
|||
* getDecoratedService().
|
||||
*
|
||||
* @covers ::getServiceDefinition
|
||||
*
|
||||
* @group legacy
|
||||
*/
|
||||
public function testGetServiceDefinitionForDecoratedService() {
|
||||
$bar_definition = new Definition('\stdClass');
|
||||
|
@ -563,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();
|
||||
}
|
||||
|
||||
|
@ -580,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();
|
||||
}
|
||||
|
||||
|
@ -597,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();
|
||||
}
|
||||
|
||||
|
@ -614,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();
|
||||
}
|
||||
|
||||
|
@ -664,6 +666,7 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
|
|||
* define a dummy, else it cannot be tested.
|
||||
*/
|
||||
namespace Symfony\Component\ExpressionLanguage {
|
||||
|
||||
if (!class_exists('\Symfony\Component\ExpressionLanguage\Expression')) {
|
||||
/**
|
||||
* Dummy class to ensure non-existent Symfony component can be tested.
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Drupal\Tests\Component\Diff;
|
|||
|
||||
use Drupal\Component\Diff\Diff;
|
||||
use Drupal\Component\Diff\DiffFormatter;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test DiffFormatter classes.
|
||||
|
@ -12,7 +13,7 @@ use Drupal\Component\Diff\DiffFormatter;
|
|||
*
|
||||
* @group Diff
|
||||
*/
|
||||
class DiffFormatterTest extends \PHPUnit_Framework_TestCase {
|
||||
class DiffFormatterTest extends TestCase {
|
||||
|
||||
/**
|
||||
* @return array
|
||||
|
|
|
@ -7,6 +7,7 @@ use Drupal\Component\Diff\Engine\DiffOpAdd;
|
|||
use Drupal\Component\Diff\Engine\DiffOpCopy;
|
||||
use Drupal\Component\Diff\Engine\DiffOpChange;
|
||||
use Drupal\Component\Diff\Engine\DiffOpDelete;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test DiffEngine class.
|
||||
|
@ -15,7 +16,7 @@ use Drupal\Component\Diff\Engine\DiffOpDelete;
|
|||
*
|
||||
* @group Diff
|
||||
*/
|
||||
class DiffEngineTest extends \PHPUnit_Framework_TestCase {
|
||||
class DiffEngineTest extends TestCase {
|
||||
|
||||
/**
|
||||
* @return array
|
||||
|
@ -85,4 +86,21 @@ class DiffEngineTest extends \PHPUnit_Framework_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', '']));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
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.
|
||||
|
@ -15,7 +17,7 @@ use Drupal\Component\Diff\Engine\DiffOp;
|
|||
*
|
||||
* @group Diff
|
||||
*/
|
||||
class DiffOpTest extends \PHPUnit_Framework_TestCase {
|
||||
class DiffOpTest extends TestCase {
|
||||
|
||||
/**
|
||||
* DiffOp::reverse() always throws an error.
|
||||
|
@ -23,7 +25,12 @@ class DiffOpTest extends \PHPUnit_Framework_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();
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Drupal\Tests\Component\Diff\Engine;
|
||||
|
||||
use Drupal\Component\Diff\Engine\HWLDFWordAccumulator;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test HWLDFWordAccumulator.
|
||||
|
@ -11,7 +12,7 @@ use Drupal\Component\Diff\Engine\HWLDFWordAccumulator;
|
|||
*
|
||||
* @group Diff
|
||||
*/
|
||||
class HWLDFWordAccumulatorTest extends \PHPUnit_Framework_TestCase {
|
||||
class HWLDFWordAccumulatorTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Verify that we only get back a NBSP from an empty accumulator.
|
||||
|
|
|
@ -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
|
|
@ -4,8 +4,9 @@ namespace Drupal\Tests\Component\Discovery;
|
|||
|
||||
use Drupal\Component\Discovery\DiscoveryException;
|
||||
use Drupal\Component\Discovery\YamlDirectoryDiscovery;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\Component\FileCache\FileCacheFactory;
|
||||
use org\bovigo\vfs\vfsStream;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* YamlDirectoryDiscoveryTest component unit tests.
|
||||
|
@ -14,7 +15,15 @@ use org\bovigo\vfs\vfsStream;
|
|||
*
|
||||
* @group Discovery
|
||||
*/
|
||||
class YamlDirectoryDiscoveryTest extends UnitTestCase {
|
||||
class YamlDirectoryDiscoveryTest extends TestCase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
// Ensure that FileCacheFactory has a prefix.
|
||||
FileCacheFactory::setPrefix('prefix');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests YAML directory discovery.
|
||||
|
@ -115,7 +124,13 @@ class YamlDirectoryDiscoveryTest extends UnitTestCase {
|
|||
* @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' => "",
|
||||
|
@ -135,7 +150,13 @@ class YamlDirectoryDiscoveryTest extends UnitTestCase {
|
|||
* @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}",
|
||||
|
|
|
@ -2,18 +2,27 @@
|
|||
|
||||
namespace Drupal\Tests\Component\Discovery;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\Component\Discovery\YamlDiscovery;
|
||||
use Drupal\Component\FileCache\FileCacheFactory;
|
||||
use org\bovigo\vfs\vfsStream;
|
||||
use org\bovigo\vfs\vfsStreamWrapper;
|
||||
use org\bovigo\vfs\vfsStreamDirectory;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* YamlDiscovery component unit tests.
|
||||
*
|
||||
* @group Discovery
|
||||
*/
|
||||
class YamlDiscoveryTest extends UnitTestCase {
|
||||
class YamlDiscoveryTest extends TestCase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
// Ensure that FileCacheFactory has a prefix.
|
||||
FileCacheFactory::setPrefix('prefix');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the YAML file discovery.
|
||||
|
|
|
@ -2,15 +2,15 @@
|
|||
|
||||
namespace Drupal\Tests\Component;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use org\bovigo\vfs\vfsStream;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* General tests for \Drupal\Component that can't go anywhere else.
|
||||
*
|
||||
* @group Component
|
||||
*/
|
||||
class DrupalComponentTest extends UnitTestCase {
|
||||
class DrupalComponentTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Tests that classes in Component do not use any Core class.
|
||||
|
@ -32,6 +32,34 @@ class DrupalComponentTest extends UnitTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
@ -64,7 +92,7 @@ class DrupalComponentTest extends UnitTestCase {
|
|||
protected function assertNoCoreUsage($class_path) {
|
||||
$contents = file_get_contents($class_path);
|
||||
preg_match_all('/^.*Drupal\\\Core.*$/m', $contents, $matches);
|
||||
$matches = array_filter($matches[0], function($line) {
|
||||
$matches = array_filter($matches[0], function ($line) {
|
||||
// Filter references to @see as they don't really matter.
|
||||
return strpos($line, '@see') === FALSE;
|
||||
});
|
||||
|
|
|
@ -6,9 +6,10 @@ namespace Drupal\Tests\Component\EventDispatcher;
|
|||
use Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher;
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\EventDispatcher\Tests\CallableClass;
|
||||
use Symfony\Component\EventDispatcher\Tests\TestEventListener;
|
||||
use Symfony\Component\EventDispatcher\Tests\ContainerAwareEventDispatcherTest as SymfonyContainerAwareEventDispatcherTest;
|
||||
use Symfony\Component\EventDispatcher\Tests\TestEventListener;
|
||||
|
||||
/**
|
||||
* Unit tests for the ContainerAwareEventDispatcher.
|
||||
|
@ -37,7 +38,7 @@ class ContainerAwareEventDispatcherTest extends SymfonyContainerAwareEventDispat
|
|||
// When passing in callables exclusively as listeners into the event
|
||||
// dispatcher constructor, the event dispatcher must not attempt to
|
||||
// resolve any services.
|
||||
$container = $this->getMock('Symfony\Component\DependencyInjection\IntrospectableContainerInterface');
|
||||
$container = $this->getMockBuilder(ContainerInterface::class)->getMock();
|
||||
$container->expects($this->never())->method($this->anything());
|
||||
|
||||
$firstListener = new CallableClass();
|
||||
|
@ -72,7 +73,7 @@ class ContainerAwareEventDispatcherTest extends SymfonyContainerAwareEventDispat
|
|||
// When passing in callables exclusively as listeners into the event
|
||||
// dispatcher constructor, the event dispatcher must not attempt to
|
||||
// resolve any services.
|
||||
$container = $this->getMock('Symfony\Component\DependencyInjection\IntrospectableContainerInterface');
|
||||
$container = $this->getMockBuilder(ContainerInterface::class)->getMock();
|
||||
$container->expects($this->never())->method($this->anything());
|
||||
|
||||
$firstListener = new CallableClass();
|
||||
|
@ -192,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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,13 +5,14 @@ namespace Drupal\Tests\Component\FileCache;
|
|||
use Drupal\Component\FileCache\FileCache;
|
||||
use Drupal\Component\FileCache\NullFileCache;
|
||||
use Drupal\Component\FileCache\FileCacheFactory;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\Component\Utility\Random;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Component\FileCache\FileCacheFactory
|
||||
* @group FileCache
|
||||
*/
|
||||
class FileCacheFactoryTest extends UnitTestCase {
|
||||
class FileCacheFactoryTest extends TestCase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -58,7 +59,13 @@ class FileCacheFactoryTest extends UnitTestCase {
|
|||
*/
|
||||
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', []);
|
||||
}
|
||||
|
||||
|
@ -104,51 +111,53 @@ class FileCacheFactoryTest extends UnitTestCase {
|
|||
$class = get_class($file_cache);
|
||||
|
||||
// Test fallback configuration.
|
||||
$data['fallback-configuration'] = [[
|
||||
], [], FileCache::class];
|
||||
$data['fallback-configuration'] = [
|
||||
[],
|
||||
[],
|
||||
FileCache::class,
|
||||
];
|
||||
|
||||
// Test default configuration.
|
||||
$data['default-configuration'] = [[
|
||||
'default' => [
|
||||
'class' => $class,
|
||||
],
|
||||
], [], $class];
|
||||
$data['default-configuration'] = [
|
||||
['default' => ['class' => $class]],
|
||||
[],
|
||||
$class,
|
||||
];
|
||||
|
||||
// Test specific per collection setting.
|
||||
$data['collection-setting'] = [[
|
||||
'test_foo_settings' => [
|
||||
'class' => $class,
|
||||
],
|
||||
], [], $class];
|
||||
|
||||
$data['collection-setting'] = [
|
||||
['test_foo_settings' => ['class' => $class]],
|
||||
[],
|
||||
$class,
|
||||
];
|
||||
|
||||
// Test default configuration plus specific per collection setting.
|
||||
$data['default-plus-collection-setting'] = [[
|
||||
'default' => [
|
||||
'class' => '\stdClass',
|
||||
$data['default-plus-collection-setting'] = [
|
||||
[
|
||||
'default' => ['class' => '\stdClass'],
|
||||
'test_foo_settings' => ['class' => $class],
|
||||
],
|
||||
'test_foo_settings' => [
|
||||
'class' => $class,
|
||||
],
|
||||
], [], $class];
|
||||
[],
|
||||
$class,
|
||||
];
|
||||
|
||||
// Test default configuration plus class specific override.
|
||||
$data['default-plus-class-override'] = [[
|
||||
'default' => [
|
||||
'class' => '\stdClass',
|
||||
],
|
||||
], [ 'class' => $class ], $class];
|
||||
$data['default-plus-class-override'] = [
|
||||
['default' => ['class' => '\stdClass']],
|
||||
['class' => $class],
|
||||
$class,
|
||||
];
|
||||
|
||||
// Test default configuration plus class specific override plus specific
|
||||
// per collection setting.
|
||||
$data['default-plus-class-plus-collection-setting'] = [[
|
||||
'default' => [
|
||||
'class' => '\stdClass',
|
||||
$data['default-plus-class-plus-collection-setting'] = [
|
||||
[
|
||||
'default' => ['class' => '\stdClass'],
|
||||
'test_foo_settings' => ['class' => $class],
|
||||
],
|
||||
'test_foo_settings' => [
|
||||
'class' => $class,
|
||||
],
|
||||
], [ 'class' => '\stdClass'], $class];
|
||||
['class' => '\stdClass'],
|
||||
$class,
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
@ -170,7 +179,10 @@ class FileCacheFactoryTest extends UnitTestCase {
|
|||
* @covers ::setPrefix
|
||||
*/
|
||||
public function testGetSetPrefix() {
|
||||
$prefix = $this->randomMachineName();
|
||||
// Random generator.
|
||||
$random = new Random();
|
||||
|
||||
$prefix = $random->name(8, TRUE);
|
||||
FileCacheFactory::setPrefix($prefix);
|
||||
$this->assertEquals($prefix, FileCacheFactory::getPrefix());
|
||||
}
|
||||
|
|
|
@ -3,13 +3,13 @@
|
|||
namespace Drupal\Tests\Component\FileCache;
|
||||
|
||||
use Drupal\Component\FileCache\FileCache;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Component\FileCache\FileCache
|
||||
* @group FileCache
|
||||
*/
|
||||
class FileCacheTest extends UnitTestCase {
|
||||
class FileCacheTest extends TestCase {
|
||||
|
||||
/**
|
||||
* FileCache object used for the tests.
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
namespace Drupal\Tests\Component\FileSystem;
|
||||
|
||||
use Drupal\Component\FileSystem\RegexDirectoryIterator;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use org\bovigo\vfs\vfsStream;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Component\FileSystem\RegexDirectoryIterator
|
||||
* @group FileSystem
|
||||
*/
|
||||
class RegexDirectoryIteratorTest extends UnitTestCase {
|
||||
class RegexDirectoryIteratorTest extends TestCase {
|
||||
|
||||
/**
|
||||
* @covers ::accept
|
||||
|
@ -21,7 +21,7 @@ class RegexDirectoryIteratorTest extends UnitTestCase {
|
|||
$iterator = new RegexDirectoryIterator(vfsStream::url('root'), $regex);
|
||||
|
||||
// Create an array of filenames to assert against.
|
||||
$file_list = array_map(function(\SplFileInfo $file) {
|
||||
$file_list = array_map(function (\SplFileInfo $file) {
|
||||
return $file->getFilename();
|
||||
}, array_values(iterator_to_array($iterator)));
|
||||
|
||||
|
@ -91,7 +91,7 @@ class RegexDirectoryIteratorTest extends UnitTestCase {
|
|||
[
|
||||
'1.yml',
|
||||
'2.yml',
|
||||
'3.txt'
|
||||
'3.txt',
|
||||
],
|
||||
],
|
||||
[
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace Drupal\Tests\Component\Gettext;
|
||||
|
||||
use Drupal\Component\Gettext\PoHeader;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Unit tests for the Gettext PO file header handling features.
|
||||
|
@ -12,7 +12,7 @@ use Drupal\Tests\UnitTestCase;
|
|||
*
|
||||
* @group Gettext
|
||||
*/
|
||||
class PoHeaderTest extends UnitTestCase {
|
||||
class PoHeaderTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Tests that plural expressions are evaluated correctly.
|
||||
|
@ -279,7 +279,8 @@ class PoHeaderTest extends UnitTestCase {
|
|||
193 => 1,
|
||||
194 => 1,
|
||||
'default' => 2,
|
||||
], ],
|
||||
],
|
||||
],
|
||||
[
|
||||
'nplurals=4; plural=(((n==1)||(n==11))?(0):(((n==2)||(n==12))?(1):(((n>2)&&(n<20))?(2):3)));',
|
||||
[
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
|
@ -3,13 +3,13 @@
|
|||
namespace Drupal\Tests\Component\Graph;
|
||||
|
||||
use Drupal\Component\Graph\Graph;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Component\Graph\Graph
|
||||
* @group Graph
|
||||
*/
|
||||
class GraphTest extends UnitTestCase {
|
||||
class GraphTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Test depth-first-search features.
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
namespace Drupal\Tests\Component\HttpFoundation;
|
||||
|
||||
use Drupal\Component\HttpFoundation\SecuredRedirectResponse;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Cookie;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
|
||||
|
@ -18,7 +18,7 @@ use Symfony\Component\HttpFoundation\RedirectResponse;
|
|||
* @group Routing
|
||||
* @coversDefaultClass \Drupal\Component\HttpFoundation\SecuredRedirectResponse
|
||||
*/
|
||||
class SecuredRedirectResponseTest extends UnitTestCase {
|
||||
class SecuredRedirectResponseTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Test copying of redirect response.
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Drupal\Tests\Component\PhpStorage;
|
|||
|
||||
use Drupal\Component\PhpStorage\FileStorage;
|
||||
use Drupal\Component\PhpStorage\FileReadOnlyStorage;
|
||||
use Drupal\Component\Utility\Random;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Component\PhpStorage\FileReadOnlyStorage
|
||||
|
@ -48,8 +49,11 @@ class FileStorageReadOnlyTest extends PhpStorageTestBase {
|
|||
* Tests writing with one class and reading with another.
|
||||
*/
|
||||
public function testReadOnly() {
|
||||
// Random generator.
|
||||
$random = new Random();
|
||||
|
||||
$php = new FileStorage($this->standardSettings);
|
||||
$name = $this->randomMachineName() . '/' . $this->randomMachineName() . '.php';
|
||||
$name = $random->name(8, TRUE) . '/' . $random->name(8, TRUE) . '.php';
|
||||
|
||||
// Find a global that doesn't exist.
|
||||
do {
|
||||
|
@ -59,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));
|
||||
|
@ -85,8 +89,11 @@ class FileStorageReadOnlyTest extends PhpStorageTestBase {
|
|||
* @covers ::deleteAll
|
||||
*/
|
||||
public function testDeleteAll() {
|
||||
// Random generator.
|
||||
$random = new Random();
|
||||
|
||||
$php = new FileStorage($this->standardSettings);
|
||||
$name = $this->randomMachineName() . '/' . $this->randomMachineName() . '.php';
|
||||
$name = $random->name(8, TRUE) . '/' . $random->name(8, TRUE) . '.php';
|
||||
|
||||
// Find a global that doesn't exist.
|
||||
do {
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
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;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Component\PhpStorage\FileStorage
|
||||
|
@ -55,11 +58,13 @@ class FileStorageTest extends PhpStorageTestBase {
|
|||
* @covers ::deleteAll
|
||||
*/
|
||||
public function testDeleteAll() {
|
||||
// Random generator.
|
||||
$random_generator = new Random();
|
||||
|
||||
// Write out some files.
|
||||
$php = new FileStorage($this->standardSettings);
|
||||
|
||||
$name = $this->randomMachineName() . '/' . $this->randomMachineName() . '.php';
|
||||
$name = $random_generator->name(8, TRUE) . '/' . $random_generator->name(8, TRUE) . '.php';
|
||||
|
||||
// Find a global that doesn't exist.
|
||||
do {
|
||||
|
@ -84,4 +89,24 @@ class FileStorageTest extends PhpStorageTestBase {
|
|||
unset($GLOBALS[$random]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::createDirectory
|
||||
*/
|
||||
public function testCreateDirectoryFailWarning() {
|
||||
$directory = new vfsStreamDirectory('permissionDenied', 0200);
|
||||
$storage = new FileStorage([
|
||||
'directory' => $directory->url(),
|
||||
'bin' => 'test',
|
||||
]);
|
||||
$code = "<?php\n echo 'here';";
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Drupal\Tests\Component\PhpStorage;
|
||||
|
||||
use Drupal\Component\Utility\Crypt;
|
||||
use Drupal\Component\Utility\Random;
|
||||
|
||||
/**
|
||||
* Base test class for MTime protected storage.
|
||||
|
@ -36,7 +37,10 @@ abstract class MTimeProtectedFileStorageBase extends PhpStorageTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->secret = $this->randomMachineName();
|
||||
// Random generator.
|
||||
$random = new Random();
|
||||
|
||||
$this->secret = $random->name(8, TRUE);
|
||||
|
||||
$this->settings = [
|
||||
'directory' => $this->directory,
|
||||
|
@ -85,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.
|
||||
|
@ -117,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']);
|
||||
}
|
||||
|
|
|
@ -3,13 +3,14 @@
|
|||
namespace Drupal\Tests\Component\PhpStorage;
|
||||
|
||||
use Drupal\Component\PhpStorage\PhpStorageInterface;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\Component\Utility\Random;
|
||||
use org\bovigo\vfs\vfsStream;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Base test for PHP storages.
|
||||
*/
|
||||
abstract class PhpStorageTestBase extends UnitTestCase {
|
||||
abstract class PhpStorageTestBase extends TestCase {
|
||||
|
||||
/**
|
||||
* A unique per test class directory path to test php storage.
|
||||
|
@ -31,7 +32,10 @@ abstract class PhpStorageTestBase extends UnitTestCase {
|
|||
* Assert that a PHP storage's load/save/delete operations work.
|
||||
*/
|
||||
public function assertCRUD($php) {
|
||||
$name = $this->randomMachineName() . '/' . $this->randomMachineName() . '.php';
|
||||
// Random generator.
|
||||
$random_generator = new Random();
|
||||
|
||||
$name = $random_generator->name(8, TRUE) . '/' . $random_generator->name(8, TRUE) . '.php';
|
||||
|
||||
// Find a global that doesn't exist.
|
||||
do {
|
||||
|
|
|
@ -3,13 +3,13 @@
|
|||
namespace Drupal\Tests\Component\Plugin\Context;
|
||||
|
||||
use Drupal\Component\Plugin\Context\Context;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Component\Plugin\Context\Context
|
||||
* @group Plugin
|
||||
*/
|
||||
class ContextTest extends UnitTestCase {
|
||||
class ContextTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Data provider for testGetContextValue.
|
||||
|
@ -71,10 +71,16 @@ class ContextTest extends UnitTestCase {
|
|||
|
||||
// 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,16 +5,16 @@ 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\UnitTestCase;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Component\Plugin\Factory\DefaultFactory
|
||||
* @group Plugin
|
||||
*/
|
||||
class DefaultFactoryTest extends UnitTestCase {
|
||||
class DefaultFactoryTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Tests getPluginClass() with a valid array plugin definition.
|
||||
|
@ -22,8 +22,8 @@ class DefaultFactoryTest extends UnitTestCase {
|
|||
* @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 UnitTestCase {
|
|||
* @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 UnitTestCase {
|
|||
* @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 UnitTestCase {
|
|||
* @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 UnitTestCase {
|
|||
* @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 UnitTestCase {
|
|||
* @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 UnitTestCase {
|
|||
* @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 UnitTestCase {
|
|||
* @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 UnitTestCase {
|
|||
* @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 UnitTestCase {
|
|||
* @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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,14 +2,14 @@
|
|||
|
||||
namespace Drupal\Tests\Component\Plugin\Discovery;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Component\Plugin\Discovery\DiscoveryCachedTrait
|
||||
* @uses \Drupal\Component\Plugin\Discovery\DiscoveryTrait
|
||||
* @group Plugin
|
||||
*/
|
||||
class DiscoveryCachedTraitTest extends UnitTestCase {
|
||||
class DiscoveryCachedTraitTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Data provider for testGetDefinition().
|
||||
|
@ -46,7 +46,7 @@ class DiscoveryCachedTraitTest extends UnitTestCase {
|
|||
$trait->expects($this->once())
|
||||
->method('getDefinitions')
|
||||
// Use a callback method, so we can perform the side-effects.
|
||||
->willReturnCallback(function() use ($reflection_definitions, $trait, $get_definitions) {
|
||||
->willReturnCallback(function () use ($reflection_definitions, $trait, $get_definitions) {
|
||||
$reflection_definitions->setValue($trait, $get_definitions);
|
||||
return $get_definitions;
|
||||
});
|
||||
|
|
|
@ -3,13 +3,13 @@
|
|||
namespace Drupal\Tests\Component\Plugin\Discovery;
|
||||
|
||||
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @group Plugin
|
||||
* @coversDefaultClass \Drupal\Component\Plugin\Discovery\DiscoveryTrait
|
||||
*/
|
||||
class DiscoveryTraitTest extends UnitTestCase {
|
||||
class DiscoveryTraitTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Data provider for testDoGetDefinition().
|
||||
|
@ -69,7 +69,12 @@ class DiscoveryTraitTest extends UnitTestCase {
|
|||
$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 UnitTestCase {
|
|||
->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);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
|
||||
namespace Drupal\Tests\Component\Plugin\Discovery;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @group Plugin
|
||||
* @coversDefaultClass \Drupal\Component\Plugin\Discovery\StaticDiscoveryDecorator
|
||||
*/
|
||||
class StaticDiscoveryDecoratorTest extends UnitTestCase {
|
||||
class StaticDiscoveryDecoratorTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Helper method to provide a mocked callback object with expectations.
|
||||
|
@ -100,7 +100,12 @@ class StaticDiscoveryDecoratorTest extends UnitTestCase {
|
|||
$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().
|
||||
|
@ -171,7 +176,7 @@ class StaticDiscoveryDecoratorTest extends UnitTestCase {
|
|||
|
||||
// Exercise getDefinitions(). It calls parent::getDefinitions() but in this
|
||||
// case there will be no side-effects.
|
||||
$this->assertArrayEquals(
|
||||
$this->assertEquals(
|
||||
$definitions,
|
||||
$mock_decorator->getDefinitions()
|
||||
);
|
||||
|
@ -220,7 +225,7 @@ class StaticDiscoveryDecoratorTest extends UnitTestCase {
|
|||
$ref_decorated->setValue($mock_decorator, $mock_decorated);
|
||||
|
||||
// Exercise __call.
|
||||
$this->assertArrayEquals(
|
||||
$this->assertEquals(
|
||||
$args,
|
||||
\call_user_func_array([$mock_decorated, $method], $args)
|
||||
);
|
||||
|
|
|
@ -10,13 +10,13 @@
|
|||
namespace Drupal\Tests\Component\Plugin\Factory;
|
||||
|
||||
use Drupal\Component\Plugin\Factory\ReflectionFactory;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @group Plugin
|
||||
* @coversDefaultClass \Drupal\Component\Plugin\Factory\ReflectionFactory
|
||||
*/
|
||||
class ReflectionFactoryTest extends UnitTestCase {
|
||||
class ReflectionFactoryTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Data provider for testGetInstanceArguments.
|
||||
|
@ -123,7 +123,12 @@ class ReflectionFactoryTest extends UnitTestCase {
|
|||
// 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.
|
||||
|
@ -172,9 +177,7 @@ class ArgumentsPluginId {
|
|||
*/
|
||||
class ArgumentsMany {
|
||||
|
||||
public function __construct(
|
||||
$configuration, $plugin_definition, $plugin_id, $foo = 'default_value', $what_am_i_doing_here = 'what_default'
|
||||
) {
|
||||
public function __construct($configuration, $plugin_definition, $plugin_id, $foo = 'default_value', $what_am_i_doing_here = 'what_default') {
|
||||
// No-op.
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {}
|
|
@ -2,13 +2,13 @@
|
|||
|
||||
namespace Drupal\Tests\Component\Plugin;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Component\Plugin\PluginBase
|
||||
* @group Plugin
|
||||
*/
|
||||
class PluginBaseTest extends UnitTestCase {
|
||||
class PluginBaseTest extends TestCase {
|
||||
|
||||
/**
|
||||
* @dataProvider providerTestGetPluginId
|
||||
|
@ -63,7 +63,6 @@ class PluginBaseTest extends UnitTestCase {
|
|||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @dataProvider providerTestGetDerivativeId
|
||||
* @covers ::getDerivativeId
|
||||
|
|
|
@ -3,13 +3,15 @@
|
|||
namespace Drupal\Tests\Component\Plugin;
|
||||
|
||||
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\Component\Plugin\Mapper\MapperInterface;
|
||||
use Drupal\Component\Plugin\PluginManagerBase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Component\Plugin\PluginManagerBase
|
||||
* @group Plugin
|
||||
*/
|
||||
class PluginManagerBaseTest extends UnitTestCase {
|
||||
class PluginManagerBaseTest extends TestCase {
|
||||
|
||||
/**
|
||||
* A callback method for mocking FactoryInterface objects.
|
||||
|
@ -58,7 +60,7 @@ class PluginManagerBaseTest extends UnitTestCase {
|
|||
$configuration_array = ['config' => 'something'];
|
||||
$result = $manager->createInstance('valid', $configuration_array);
|
||||
$this->assertEquals('valid', $result['plugin_id']);
|
||||
$this->assertArrayEquals($configuration_array, $result['configuration']);
|
||||
$this->assertEquals($configuration_array, $result['configuration']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -81,13 +83,52 @@ class PluginManagerBaseTest extends UnitTestCase {
|
|||
$factory_ref->setValue($manager, $this->getMockFactoryInterface(1));
|
||||
$no_fallback_result = $manager->createInstance('valid', $configuration_array);
|
||||
$this->assertEquals('valid', $no_fallback_result['plugin_id']);
|
||||
$this->assertArrayEquals($configuration_array, $no_fallback_result['configuration']);
|
||||
$this->assertEquals($configuration_array, $no_fallback_result['configuration']);
|
||||
|
||||
// Test with fallback interface and invalid plugin_id.
|
||||
$factory_ref->setValue($manager, $this->getMockFactoryInterface(2));
|
||||
$fallback_result = $manager->createInstance('invalid', $configuration_array);
|
||||
$this->assertEquals('invalid_fallback', $fallback_result['plugin_id']);
|
||||
$this->assertArrayEquals($configuration_array, $fallback_result['configuration']);
|
||||
$this->assertEquals($configuration_array, $fallback_result['configuration']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getInstance
|
||||
*/
|
||||
public function testGetInstance() {
|
||||
$options = [
|
||||
'foo' => 'F00',
|
||||
'bar' => 'bAr',
|
||||
];
|
||||
$instance = new \stdClass();
|
||||
$mapper = $this->prophesize(MapperInterface::class);
|
||||
$mapper->getInstance($options)
|
||||
->shouldBeCalledTimes(1)
|
||||
->willReturn($instance);
|
||||
$manager = new StubPluginManagerBaseWithMapper($mapper->reveal());
|
||||
$this->assertEquals($instance, $manager->getInstance($options));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getInstance
|
||||
*/
|
||||
public function testGetInstanceWithoutMapperShouldThrowException() {
|
||||
$options = [
|
||||
'foo' => 'F00',
|
||||
'bar' => 'bAr',
|
||||
];
|
||||
/** @var \Drupal\Component\Plugin\PluginManagerBase $manager */
|
||||
$manager = $this->getMockBuilder(PluginManagerBase::class)
|
||||
->getMockForAbstractClass();
|
||||
// Set the expected exception thrown by ::getInstance.
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(\BadMethodCallException::class);
|
||||
$this->expectExceptionMessage(sprintf('%s does not support this method unless %s::$mapper is set.', get_class($manager), get_class($manager)));
|
||||
}
|
||||
else {
|
||||
$this->setExpectedException(\BadMethodCallException::class, sprintf('%s does not support this method unless %s::$mapper is set.', get_class($manager), get_class($manager)));
|
||||
}
|
||||
$manager->getInstance($options);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\Component\Plugin;
|
||||
|
||||
use Drupal\Component\Plugin\Mapper\MapperInterface;
|
||||
use Drupal\Component\Plugin\PluginManagerBase;
|
||||
|
||||
/**
|
||||
* Stubs \Drupal\Component\Plugin\PluginManagerBase to take a MapperInterface.
|
||||
*/
|
||||
final class StubPluginManagerBaseWithMapper extends PluginManagerBase {
|
||||
|
||||
/**
|
||||
* Constructs a new instance.
|
||||
*
|
||||
* @param \Drupal\Component\Plugin\Mapper\MapperInterface $mapper
|
||||
*/
|
||||
public function __construct(MapperInterface $mapper) {
|
||||
$this->mapper = $mapper;
|
||||
}
|
||||
|
||||
}
|
|
@ -8,13 +8,13 @@
|
|||
namespace Drupal\Tests\Component\ProxyBuilder;
|
||||
|
||||
use Drupal\Component\ProxyBuilder\ProxyBuilder;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Component\ProxyBuilder\ProxyBuilder
|
||||
* @group proxy_builder
|
||||
*/
|
||||
class ProxyBuilderTest extends UnitTestCase {
|
||||
class ProxyBuilderTest extends TestCase {
|
||||
|
||||
/**
|
||||
* The tested proxy builder.
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace Drupal\Tests\Component\Render;
|
||||
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Tests the TranslatableMarkup class.
|
||||
|
@ -11,7 +11,7 @@ use Drupal\Tests\UnitTestCase;
|
|||
* @coversDefaultClass \Drupal\Component\Render\FormattableMarkup
|
||||
* @group utility
|
||||
*/
|
||||
class FormattableMarkupTest extends UnitTestCase {
|
||||
class FormattableMarkupTest extends TestCase {
|
||||
|
||||
/**
|
||||
* The error message of the last error in the error handler.
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace Drupal\Tests\Component\Render;
|
|||
|
||||
use Drupal\Component\Render\HtmlEscapedText;
|
||||
use Drupal\Component\Render\MarkupInterface;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Tests the HtmlEscapedText class.
|
||||
|
@ -12,7 +12,7 @@ use Drupal\Tests\UnitTestCase;
|
|||
* @coversDefaultClass \Drupal\Component\Render\HtmlEscapedText
|
||||
* @group utility
|
||||
*/
|
||||
class HtmlEscapedTextTest extends UnitTestCase {
|
||||
class HtmlEscapedTextTest extends TestCase {
|
||||
|
||||
/**
|
||||
* @covers ::__toString
|
||||
|
|
|
@ -3,15 +3,15 @@
|
|||
namespace Drupal\Tests\Component\Render;
|
||||
|
||||
use Drupal\Component\Render\PlainTextOutput;
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\Component\Render\MarkupInterface;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Component\Render\PlainTextOutput
|
||||
* @group Utility
|
||||
*/
|
||||
class PlainTextOutputTest extends UnitTestCase {
|
||||
class PlainTextOutputTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Tests ::renderFromHtml().
|
||||
|
@ -28,7 +28,7 @@ class PlainTextOutputTest extends UnitTestCase {
|
|||
* @dataProvider providerRenderFromHtml
|
||||
*/
|
||||
public function testRenderFromHtml($expected, $string, $args = []) {
|
||||
$markup = SafeMarkup::format($string, $args);
|
||||
$markup = new FormattableMarkup($string, $args);
|
||||
$output = PlainTextOutput::renderFromHtml($markup);
|
||||
$this->assertSame($expected, $output);
|
||||
}
|
||||
|
|
|
@ -3,13 +3,13 @@
|
|||
namespace Drupal\Tests\Component\Serialization;
|
||||
|
||||
use Drupal\Component\Serialization\Json;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Component\Serialization\Json
|
||||
* @group Serialization
|
||||
*/
|
||||
class JsonTest extends UnitTestCase {
|
||||
class JsonTest extends TestCase {
|
||||
|
||||
/**
|
||||
* A test string with the full ASCII table.
|
||||
|
@ -32,7 +32,6 @@ class JsonTest extends UnitTestCase {
|
|||
*/
|
||||
protected $htmlUnsafeEscaped;
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -58,7 +57,7 @@ class JsonTest extends UnitTestCase {
|
|||
*/
|
||||
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]);
|
||||
|
|
|
@ -7,13 +7,13 @@ use Drupal\Component\Serialization\SerializationInterface;
|
|||
use Drupal\Component\Serialization\Yaml;
|
||||
use Drupal\Component\Serialization\YamlPecl;
|
||||
use Drupal\Component\Serialization\YamlSymfony;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Component\Serialization\Yaml
|
||||
* @group Serialization
|
||||
*/
|
||||
class YamlTest extends UnitTestCase {
|
||||
class YamlTest extends TestCase {
|
||||
|
||||
/**
|
||||
* @var \PHPUnit_Framework_MockObject_MockObject
|
||||
|
@ -77,20 +77,46 @@ class YamlTest extends UnitTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* 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 UnitTestCase {
|
|||
$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.
|
||||
|
|
|
@ -2,10 +2,12 @@
|
|||
|
||||
namespace Drupal\Tests\Component\Serialization;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Provides standard data to validate different YAML implementations.
|
||||
*/
|
||||
abstract class YamlTestBase extends \PHPUnit_Framework_TestCase {
|
||||
abstract class YamlTestBase extends TestCase {
|
||||
|
||||
/**
|
||||
* Some data that should be able to be serialized.
|
||||
|
@ -35,7 +37,7 @@ abstract class YamlTestBase extends \PHPUnit_Framework_TestCase {
|
|||
[10],
|
||||
[0 => '123456'],
|
||||
],
|
||||
[NULL]
|
||||
[NULL],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -4,8 +4,8 @@ namespace Drupal\Tests\Component\Transliteration;
|
|||
|
||||
use Drupal\Component\Transliteration\PhpTransliteration;
|
||||
use Drupal\Component\Utility\Random;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use org\bovigo\vfs\vfsStream;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Tests Transliteration component functionality.
|
||||
|
@ -14,7 +14,7 @@ use org\bovigo\vfs\vfsStream;
|
|||
*
|
||||
* @coversDefaultClass \Drupal\Component\Transliteration\PhpTransliteration
|
||||
*/
|
||||
class PhpTransliterationTest extends UnitTestCase {
|
||||
class PhpTransliterationTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Tests the PhpTransliteration::removeDiacritics() function.
|
||||
|
@ -106,7 +106,7 @@ class PhpTransliterationTest extends UnitTestCase {
|
|||
// Make some strings with two, three, and four-byte characters for testing.
|
||||
// Note that the 3-byte character is overridden by the 'kg' language.
|
||||
$two_byte = 'Ä Ö Ü Å Ø äöüåøhello';
|
||||
// This is a Cyrrillic character that looks something like a u. See
|
||||
// This is a Cyrillic character that looks something like a "u". See
|
||||
// http://www.unicode.org/charts/PDF/U0400.pdf
|
||||
$three_byte = html_entity_decode('ц', ENT_NOQUOTES, 'UTF-8');
|
||||
// This is a Canadian Aboriginal character like a triangle. See
|
||||
|
@ -182,7 +182,7 @@ class PhpTransliterationTest extends UnitTestCase {
|
|||
]);
|
||||
$transliteration = new PhpTransliteration(vfsStream::url('transliteration/dir'));
|
||||
$transliterated = $transliteration->transliterate(chr(0xC2) . chr(0x82), '../index');
|
||||
$this->assertSame($transliterated, 'safe');
|
||||
$this->assertSame('safe', $transliterated);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,13 +8,13 @@
|
|||
namespace Drupal\Tests\Component\Utility;
|
||||
|
||||
use Drupal\Component\Utility\ArgumentsResolver;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Component\Utility\ArgumentsResolver
|
||||
* @group Access
|
||||
*/
|
||||
class ArgumentsResolverTest extends UnitTestCase {
|
||||
class ArgumentsResolverTest extends TestCase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -41,30 +41,30 @@ class ArgumentsResolverTest extends UnitTestCase {
|
|||
|
||||
// Test an optional parameter with no provided value.
|
||||
$data[] = [
|
||||
function($foo = 'foo') {}, [], [], [] , ['foo'],
|
||||
function ($foo = 'foo') {}, [], [], [] , ['foo'],
|
||||
];
|
||||
|
||||
// Test an optional parameter with a provided value.
|
||||
$data[] = [
|
||||
function($foo = 'foo') {}, ['foo' => 'bar'], [], [], ['bar'],
|
||||
function ($foo = 'foo') {}, ['foo' => 'bar'], [], [], ['bar'],
|
||||
];
|
||||
|
||||
// Test with a provided value.
|
||||
$data[] = [
|
||||
function($foo) {}, ['foo' => 'bar'], [], [], ['bar'],
|
||||
function ($foo) {}, ['foo' => 'bar'], [], [], ['bar'],
|
||||
];
|
||||
|
||||
// Test with an explicitly NULL value.
|
||||
$data[] = [
|
||||
function($foo) {}, [], ['foo' => NULL], [], [NULL],
|
||||
function ($foo) {}, [], ['foo' => NULL], [], [NULL],
|
||||
];
|
||||
|
||||
// Test with a raw value that overrides the provided upcast value, since
|
||||
// it is not typehinted.
|
||||
$scalars = ['foo' => 'baz'];
|
||||
$scalars = ['foo' => 'baz'];
|
||||
$objects = ['foo' => new \stdClass()];
|
||||
$data[] = [
|
||||
function($foo) {}, $scalars, $objects, [], ['baz'],
|
||||
function ($foo) {}, $scalars, $objects, [], ['baz'],
|
||||
];
|
||||
|
||||
return $data;
|
||||
|
@ -74,7 +74,7 @@ class ArgumentsResolverTest extends UnitTestCase {
|
|||
* Tests getArgument() with an object.
|
||||
*/
|
||||
public function testGetArgumentObject() {
|
||||
$callable = function(\stdClass $object) {};
|
||||
$callable = function (\stdClass $object) {};
|
||||
|
||||
$object = new \stdClass();
|
||||
$arguments = (new ArgumentsResolver([], ['object' => $object], []))->getArguments($callable);
|
||||
|
@ -85,7 +85,7 @@ class ArgumentsResolverTest extends UnitTestCase {
|
|||
* Tests getArgument() with a wildcard object for a parameter with a custom name.
|
||||
*/
|
||||
public function testGetWildcardArgument() {
|
||||
$callable = function(\stdClass $custom_name) {};
|
||||
$callable = function (\stdClass $custom_name) {};
|
||||
|
||||
$object = new \stdClass();
|
||||
$arguments = (new ArgumentsResolver([], [], [$object]))->getArguments($callable);
|
||||
|
@ -96,9 +96,9 @@ class ArgumentsResolverTest extends UnitTestCase {
|
|||
* Tests getArgument() with a Route, Request, and Account object.
|
||||
*/
|
||||
public function testGetArgumentOrder() {
|
||||
$a1 = $this->getMock('\Drupal\Tests\Component\Utility\TestInterface1');
|
||||
$a2 = $this->getMock('\Drupal\Tests\Component\Utility\TestClass');
|
||||
$a3 = $this->getMock('\Drupal\Tests\Component\Utility\TestInterface2');
|
||||
$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,
|
||||
|
@ -107,12 +107,12 @@ class ArgumentsResolverTest extends UnitTestCase {
|
|||
$wildcards = [$a3];
|
||||
$resolver = new ArgumentsResolver([], $objects, $wildcards);
|
||||
|
||||
$callable = function(TestInterface1 $t1, TestClass $tc, TestInterface2 $t2) {};
|
||||
$callable = function (Test1Interface $t1, TestClass $tc, Test2Interface $t2) {};
|
||||
$arguments = $resolver->getArguments($callable);
|
||||
$this->assertSame([$a1, $a2, $a3], $arguments);
|
||||
|
||||
// Test again, but with the arguments in a different order.
|
||||
$callable = function(TestInterface2 $t2, TestClass $tc, TestInterface1 $t1) {};
|
||||
$callable = function (Test2Interface $t2, TestClass $tc, Test1Interface $t1) {};
|
||||
$arguments = $resolver->getArguments($callable);
|
||||
$this->assertSame([$a3, $a2, $a1], $arguments);
|
||||
}
|
||||
|
@ -123,12 +123,18 @@ class ArgumentsResolverTest extends UnitTestCase {
|
|||
* Without the typehint, the wildcard object will not be passed to the callable.
|
||||
*/
|
||||
public function testGetWildcardArgumentNoTypehint() {
|
||||
$a = $this->getMock('\Drupal\Tests\Component\Utility\TestInterface1');
|
||||
$a = $this->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.');
|
||||
$callable = function ($route) {};
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -142,7 +148,7 @@ class ArgumentsResolverTest extends UnitTestCase {
|
|||
$scalars = ['route' => 'foo'];
|
||||
$resolver = new ArgumentsResolver($scalars, [], []);
|
||||
|
||||
$callable = function($route) {};
|
||||
$callable = function ($route) {};
|
||||
$arguments = $resolver->getArguments($callable);
|
||||
$this->assertSame(['foo'], $arguments);
|
||||
}
|
||||
|
@ -155,8 +161,14 @@ class ArgumentsResolverTest extends UnitTestCase {
|
|||
$scalars = ['foo' => 'baz'];
|
||||
$resolver = new ArgumentsResolver($scalars, $objects, []);
|
||||
|
||||
$callable = function(\stdClass $foo) {};
|
||||
$this->setExpectedException(\RuntimeException::class, 'requires a value for the "$foo" argument.');
|
||||
$callable = function (\stdClass $foo) {};
|
||||
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 UnitTestCase {
|
|||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -176,7 +194,7 @@ class ArgumentsResolverTest extends UnitTestCase {
|
|||
*/
|
||||
public function providerTestHandleUnresolvedArgument() {
|
||||
$data = [];
|
||||
$data[] = [function($foo) {}];
|
||||
$data[] = [function ($foo) {}];
|
||||
$data[] = [[new TestClass(), 'access']];
|
||||
$data[] = ['Drupal\Tests\Component\Utility\test_access_arguments_resolver_access'];
|
||||
return $data;
|
||||
|
@ -188,6 +206,7 @@ class ArgumentsResolverTest extends UnitTestCase {
|
|||
* Provides a test class.
|
||||
*/
|
||||
class TestClass {
|
||||
|
||||
public function access($foo) {
|
||||
}
|
||||
|
||||
|
@ -196,13 +215,13 @@ class TestClass {
|
|||
/**
|
||||
* Provides a test interface.
|
||||
*/
|
||||
interface TestInterface1 {
|
||||
interface Test1Interface {
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a different test interface.
|
||||
*/
|
||||
interface TestInterface2 {
|
||||
interface Test2Interface {
|
||||
}
|
||||
|
||||
function test_access_arguments_resolver_access($foo) {
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace Drupal\Tests\Component\Utility;
|
||||
|
||||
use Drupal\Component\Utility\Bytes;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Tests bytes size parsing helper methods.
|
||||
|
@ -12,7 +12,7 @@ use Drupal\Tests\UnitTestCase;
|
|||
*
|
||||
* @coversDefaultClass \Drupal\Component\Utility\Bytes
|
||||
*/
|
||||
class BytesTest extends UnitTestCase {
|
||||
class BytesTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Tests \Drupal\Component\Utility\Bytes::toInt().
|
||||
|
@ -52,8 +52,10 @@ class BytesTest extends UnitTestCase {
|
|||
['1 ZB' , pow(Bytes::KILOBYTE, 7)],
|
||||
['1 YB' , pow(Bytes::KILOBYTE, 8)],
|
||||
['23476892 bytes', 23476892],
|
||||
['76MRandomStringThatShouldBeIgnoredByParseSize.', 79691776], // 76 MB
|
||||
['76.24 Giggabyte', 81862076662], // 76.24 GB (with typo)
|
||||
// 76 MB.
|
||||
['76MRandomStringThatShouldBeIgnoredByParseSize.', 79691776],
|
||||
// 76.24 GB (with typo).
|
||||
['76.24 Giggabyte', 81862076662],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
namespace Drupal\Tests\Component\Utility;
|
||||
|
||||
use Drupal\Component\Utility\Color;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Tests Color utility class conversions.
|
||||
*
|
||||
* @group Utility
|
||||
*/
|
||||
class ColorTest extends UnitTestCase {
|
||||
class ColorTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Tests Color::hexToRgb().
|
||||
|
@ -26,7 +26,12 @@ class ColorTest extends UnitTestCase {
|
|||
*/
|
||||
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));
|
||||
}
|
||||
|
@ -56,7 +61,7 @@ class ColorTest extends UnitTestCase {
|
|||
// Add invalid data types (hex value must be a string).
|
||||
foreach ([
|
||||
1, 12, 1234, 12345, 123456, 1234567, 12345678, 123456789, 123456789,
|
||||
-1, PHP_INT_MAX, PHP_INT_MAX + 1, -PHP_INT_MAX, 0x0, 0x010
|
||||
-1, PHP_INT_MAX, PHP_INT_MAX + 1, -PHP_INT_MAX, 0x0, 0x010,
|
||||
] as $value) {
|
||||
$invalid[] = [$value, '', TRUE];
|
||||
}
|
||||
|
@ -118,4 +123,42 @@ class ColorTest extends UnitTestCase {
|
|||
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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
namespace Drupal\Tests\Component\Utility;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\Component\Utility\Crypt;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Tests random byte generation fallback exception situations.
|
||||
|
@ -14,7 +14,7 @@ use Drupal\Component\Utility\Crypt;
|
|||
*
|
||||
* @coversDefaultClass \Drupal\Component\Utility\Crypt
|
||||
*/
|
||||
class CryptRandomFallbackTest extends UnitTestCase {
|
||||
class CryptRandomFallbackTest extends TestCase {
|
||||
|
||||
static protected $functionCalled = 0;
|
||||
|
||||
|
@ -52,7 +52,7 @@ class CryptRandomFallbackTest extends UnitTestCase {
|
|||
|
||||
namespace Drupal\Component\Utility;
|
||||
|
||||
use \Drupal\Tests\Component\Utility\CryptRandomFallbackTest;
|
||||
use Drupal\Tests\Component\Utility\CryptRandomFallbackTest;
|
||||
|
||||
/**
|
||||
* Defines a function in same namespace as Drupal\Component\Utility\Crypt.
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
namespace Drupal\Tests\Component\Utility;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\Component\Utility\Crypt;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Tests random byte generation.
|
||||
|
@ -12,7 +12,7 @@ use Drupal\Component\Utility\Crypt;
|
|||
*
|
||||
* @coversDefaultClass \Drupal\Component\Utility\Crypt
|
||||
*/
|
||||
class CryptTest extends UnitTestCase {
|
||||
class CryptTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Tests random byte generation.
|
||||
|
@ -77,7 +77,12 @@ class CryptTest extends UnitTestCase {
|
|||
* 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace Drupal\Tests\Component\Utility;
|
||||
|
||||
use Drupal\Component\Utility\Environment;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test PHP Environment helper methods.
|
||||
|
@ -12,7 +12,7 @@ use Drupal\Tests\UnitTestCase;
|
|||
*
|
||||
* @coversDefaultClass \Drupal\Component\Utility\Environment
|
||||
*/
|
||||
class EnvironmentTest extends UnitTestCase {
|
||||
class EnvironmentTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Tests \Drupal\Component\Utility\Environment::checkMemoryLimit().
|
||||
|
|
|
@ -5,7 +5,8 @@ namespace Drupal\Tests\Component\Utility;
|
|||
use Drupal\Component\Render\MarkupInterface;
|
||||
use Drupal\Component\Render\MarkupTrait;
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\Component\Utility\Random;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Tests \Drupal\Component\Utility\Html.
|
||||
|
@ -14,7 +15,7 @@ use Drupal\Tests\UnitTestCase;
|
|||
*
|
||||
* @coversDefaultClass \Drupal\Component\Utility\Html
|
||||
*/
|
||||
class HtmlTest extends UnitTestCase {
|
||||
class HtmlTest extends TestCase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -66,9 +67,10 @@ class HtmlTest extends UnitTestCase {
|
|||
[$id1, $id1, []],
|
||||
// Verify that valid UTF-8 characters are not stripped from the identifier.
|
||||
[$id2, $id2, []],
|
||||
// Verify that invalid characters (including non-breaking space) are stripped from the identifier.
|
||||
[$id3, $id3],
|
||||
// Verify that double underscores are not stripped from the identifier.
|
||||
[$id3, $id3],
|
||||
// Verify that invalid characters (including non-breaking space) are
|
||||
// stripped from the identifier.
|
||||
['invalididentifier', 'invalid !"#$%&\'()*+,./:;<=>?@[\\]^`{|}~ identifier', []],
|
||||
// Verify that an identifier starting with a digit is replaced.
|
||||
['_cssidentifier', '1cssidentifier', []],
|
||||
|
@ -341,7 +343,12 @@ class HtmlTest extends UnitTestCase {
|
|||
* @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);
|
||||
}
|
||||
|
||||
|
@ -354,11 +361,14 @@ class HtmlTest extends UnitTestCase {
|
|||
public function providerTestTransformRootRelativeUrlsToAbsolute() {
|
||||
$data = [];
|
||||
|
||||
// Random generator.
|
||||
$random = new Random();
|
||||
|
||||
// One random tag name.
|
||||
$tag_name = strtolower($this->randomMachineName());
|
||||
$tag_name = strtolower($random->name(8, TRUE));
|
||||
|
||||
// A site installed either in the root of a domain or a subdirectory.
|
||||
$base_paths = ['/', '/subdir/' . $this->randomMachineName() . '/'];
|
||||
$base_paths = ['/', '/subdir/' . $random->name(8, TRUE) . '/'];
|
||||
|
||||
foreach ($base_paths as $base_path) {
|
||||
// The only attribute that has more than just a URL as its value, is
|
||||
|
|
|
@ -3,13 +3,13 @@
|
|||
namespace Drupal\Tests\Component\Utility;
|
||||
|
||||
use Drupal\Component\Utility\Image;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Component\Utility\Image
|
||||
* @group Image
|
||||
*/
|
||||
class ImageTest extends UnitTestCase {
|
||||
class ImageTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Tests all control flow branches in image_dimensions_scale().
|
||||
|
|
|
@ -3,13 +3,13 @@
|
|||
namespace Drupal\Tests\Component\Utility;
|
||||
|
||||
use Drupal\Component\Utility\NestedArray;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Component\Utility\NestedArray
|
||||
* @group Utility
|
||||
*/
|
||||
class NestedArrayTest extends UnitTestCase {
|
||||
class NestedArrayTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Form array to check.
|
||||
|
@ -265,16 +265,24 @@ class NestedArrayTest extends UnitTestCase {
|
|||
public function providerTestFilter() {
|
||||
$data = [];
|
||||
$data['1d-array'] = [
|
||||
[0, 1, '', TRUE], NULL, [1 => 1, 3 => TRUE]
|
||||
[0, 1, '', TRUE], NULL, [1 => 1, 3 => TRUE],
|
||||
];
|
||||
$data['1d-array-callable'] = [
|
||||
[0, 1, '', TRUE], function ($element) { return $element === ''; }, [2 => '']
|
||||
[0, 1, '', TRUE],
|
||||
function ($element) {
|
||||
return $element === '';
|
||||
},
|
||||
[2 => ''],
|
||||
];
|
||||
$data['2d-array'] = [
|
||||
[[0, 1, '', TRUE], [0, 1, 2, 3]], NULL, [0 => [1 => 1, 3 => TRUE], 1 => [1 => 1, 2 => 2, 3 => 3]],
|
||||
];
|
||||
$data['2d-array-callable'] = [
|
||||
[[0, 1, '', TRUE], [0, 1, 2, 3]], function ($element) { return is_array($element) || $element === 3; }, [0 => [], 1 => [3 => 3]],
|
||||
[[0, 1, '', TRUE], [0, 1, 2, 3]],
|
||||
function ($element) {
|
||||
return is_array($element) || $element === 3;
|
||||
},
|
||||
[0 => [], 1 => [3 => 3]],
|
||||
];
|
||||
|
||||
return $data;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace Drupal\Tests\Component\Utility;
|
||||
|
||||
use Drupal\Component\Utility\Number;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Tests number manipulation utilities.
|
||||
|
@ -14,7 +14,7 @@ use Drupal\Tests\UnitTestCase;
|
|||
*
|
||||
* @see \Drupal\Component\Utility\Number
|
||||
*/
|
||||
class NumberTest extends UnitTestCase {
|
||||
class NumberTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Tests Number::validStep() without offset.
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace Drupal\Tests\Component\Utility;
|
||||
|
||||
use Drupal\Component\Utility\Random;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Tests random data generation.
|
||||
|
@ -12,7 +12,7 @@ use Drupal\Tests\UnitTestCase;
|
|||
*
|
||||
* @coversDefaultClass \Drupal\Component\Utility\Random
|
||||
*/
|
||||
class RandomTest extends UnitTestCase {
|
||||
class RandomTest extends TestCase {
|
||||
|
||||
/**
|
||||
* The first random string passed to the test callback.
|
||||
|
@ -62,7 +62,12 @@ class RandomTest extends UnitTestCase {
|
|||
// 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 UnitTestCase {
|
|||
// 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;
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -12,15 +12,16 @@ use Drupal\Component\Utility\SafeMarkup;
|
|||
use Drupal\Component\Render\MarkupInterface;
|
||||
use Drupal\Component\Render\MarkupTrait;
|
||||
use Drupal\Component\Utility\UrlHelper;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Tests marking strings as safe.
|
||||
*
|
||||
* @group Utility
|
||||
* @group legacy
|
||||
* @coversDefaultClass \Drupal\Component\Utility\SafeMarkup
|
||||
*/
|
||||
class SafeMarkupTest extends UnitTestCase {
|
||||
class SafeMarkupTest extends TestCase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -35,9 +36,10 @@ class SafeMarkupTest extends UnitTestCase {
|
|||
* Tests SafeMarkup::isSafe() with different objects.
|
||||
*
|
||||
* @covers ::isSafe
|
||||
* @expectedDeprecation SafeMarkup::isSafe() is scheduled for removal in Drupal 9.0.0. Instead, you should just check if a variable is an instance of \Drupal\Component\Render\MarkupInterface. See https://www.drupal.org/node/2549395.
|
||||
*/
|
||||
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));
|
||||
|
@ -48,6 +50,7 @@ class SafeMarkupTest extends UnitTestCase {
|
|||
*
|
||||
* @dataProvider providerCheckPlain
|
||||
* @covers ::checkPlain
|
||||
* @expectedDeprecation SafeMarkup::checkPlain() is scheduled for removal in Drupal 9.0.0. Rely on Twig's auto-escaping feature, or use the @link theme_render #plain_text @endlink key when constructing a render array that contains plain text in order to use the renderer's auto-escaping feature. If neither of these are possible, \Drupal\Component\Utility\Html::escape() can be used in places where explicit escaping is needed. See https://www.drupal.org/node/2549395.
|
||||
*
|
||||
* @param string $text
|
||||
* The text to provide to SafeMarkup::checkPlain().
|
||||
|
@ -107,6 +110,7 @@ class SafeMarkupTest extends UnitTestCase {
|
|||
*
|
||||
* @dataProvider providerFormat
|
||||
* @covers ::format
|
||||
* @expectedDeprecation SafeMarkup::format() is scheduled for removal in Drupal 9.0.0. Use \Drupal\Component\Render\FormattableMarkup. See https://www.drupal.org/node/2549395.
|
||||
*
|
||||
* @param string $string
|
||||
* The string to run through SafeMarkup::format().
|
||||
|
@ -125,10 +129,6 @@ class SafeMarkupTest extends UnitTestCase {
|
|||
$result = SafeMarkup::format($string, $args);
|
||||
$this->assertEquals($expected, (string) $result, $message);
|
||||
$this->assertEquals($expected_is_safe, $result instanceof MarkupInterface, 'SafeMarkup::format correctly sets the result as safe or not safe.');
|
||||
|
||||
foreach ($args as $arg) {
|
||||
$this->assertSame($arg instanceof SafeMarkupTestMarkup, SafeMarkup::isSafe($arg));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
namespace Drupal\Tests\Component\Utility;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\Component\Utility\SortArray;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Tests the SortArray component.
|
||||
|
@ -12,7 +12,7 @@ use Drupal\Component\Utility\SortArray;
|
|||
*
|
||||
* @coversDefaultClass \Drupal\Component\Utility\SortArray
|
||||
*/
|
||||
class SortArrayTest extends UnitTestCase {
|
||||
class SortArrayTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Tests SortArray::sortByWeightElement() input against expected output.
|
||||
|
@ -49,42 +49,42 @@ class SortArrayTest extends UnitTestCase {
|
|||
$tests[] = [
|
||||
['weight' => 1],
|
||||
['weight' => 1],
|
||||
0
|
||||
0,
|
||||
];
|
||||
|
||||
// Weights set and $a is less (lighter) than $b.
|
||||
$tests[] = [
|
||||
['weight' => 1],
|
||||
['weight' => 2],
|
||||
-1
|
||||
-1,
|
||||
];
|
||||
|
||||
// Weights set and $a is greater (heavier) than $b.
|
||||
$tests[] = [
|
||||
['weight' => 2],
|
||||
['weight' => 1],
|
||||
1
|
||||
1,
|
||||
];
|
||||
|
||||
// Weights not set.
|
||||
$tests[] = [
|
||||
[],
|
||||
[],
|
||||
0
|
||||
0,
|
||||
];
|
||||
|
||||
// Weights for $b not set.
|
||||
$tests[] = [
|
||||
['weight' => 1],
|
||||
[],
|
||||
1
|
||||
1,
|
||||
];
|
||||
|
||||
// Weights for $a not set.
|
||||
$tests[] = [
|
||||
[],
|
||||
['weight' => 1],
|
||||
-1
|
||||
-1,
|
||||
];
|
||||
|
||||
return $tests;
|
||||
|
@ -125,42 +125,42 @@ class SortArrayTest extends UnitTestCase {
|
|||
$tests[] = [
|
||||
['#weight' => 1],
|
||||
['#weight' => 1],
|
||||
0
|
||||
0,
|
||||
];
|
||||
|
||||
// Weights set and $a is less (lighter) than $b.
|
||||
$tests[] = [
|
||||
['#weight' => 1],
|
||||
['#weight' => 2],
|
||||
-1
|
||||
-1,
|
||||
];
|
||||
|
||||
// Weights set and $a is greater (heavier) than $b.
|
||||
$tests[] = [
|
||||
['#weight' => 2],
|
||||
['#weight' => 1],
|
||||
1
|
||||
1,
|
||||
];
|
||||
|
||||
// Weights not set.
|
||||
$tests[] = [
|
||||
[],
|
||||
[],
|
||||
0
|
||||
0,
|
||||
];
|
||||
|
||||
// Weights for $b not set.
|
||||
$tests[] = [
|
||||
['#weight' => 1],
|
||||
[],
|
||||
1
|
||||
1,
|
||||
];
|
||||
|
||||
// Weights for $a not set.
|
||||
$tests[] = [
|
||||
[],
|
||||
['#weight' => 1],
|
||||
-1
|
||||
-1,
|
||||
];
|
||||
|
||||
return $tests;
|
||||
|
@ -201,35 +201,35 @@ class SortArrayTest extends UnitTestCase {
|
|||
$tests[] = [
|
||||
['title' => 'test'],
|
||||
['title' => 'test'],
|
||||
0
|
||||
0,
|
||||
];
|
||||
|
||||
// Title $a not set.
|
||||
$tests[] = [
|
||||
[],
|
||||
['title' => 'test'],
|
||||
-4
|
||||
-4,
|
||||
];
|
||||
|
||||
// Title $b not set.
|
||||
$tests[] = [
|
||||
['title' => 'test'],
|
||||
[],
|
||||
4
|
||||
4,
|
||||
];
|
||||
|
||||
// Titles set but not equal.
|
||||
$tests[] = [
|
||||
['title' => 'test'],
|
||||
['title' => 'testing'],
|
||||
-1
|
||||
-1,
|
||||
];
|
||||
|
||||
// Titles set but not equal.
|
||||
$tests[] = [
|
||||
['title' => 'testing'],
|
||||
['title' => 'test'],
|
||||
1
|
||||
1,
|
||||
];
|
||||
|
||||
return $tests;
|
||||
|
@ -270,35 +270,35 @@ class SortArrayTest extends UnitTestCase {
|
|||
$tests[] = [
|
||||
['#title' => 'test'],
|
||||
['#title' => 'test'],
|
||||
0
|
||||
0,
|
||||
];
|
||||
|
||||
// Title $a not set.
|
||||
$tests[] = [
|
||||
[],
|
||||
['#title' => 'test'],
|
||||
-4
|
||||
-4,
|
||||
];
|
||||
|
||||
// Title $b not set.
|
||||
$tests[] = [
|
||||
['#title' => 'test'],
|
||||
[],
|
||||
4
|
||||
4,
|
||||
];
|
||||
|
||||
// Titles set but not equal.
|
||||
$tests[] = [
|
||||
['#title' => 'test'],
|
||||
['#title' => 'testing'],
|
||||
-1
|
||||
-1,
|
||||
];
|
||||
|
||||
// Titles set but not equal.
|
||||
$tests[] = [
|
||||
['#title' => 'testing'],
|
||||
['#title' => 'test'],
|
||||
1
|
||||
1,
|
||||
];
|
||||
|
||||
return $tests;
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
namespace Drupal\Tests\Component\Utility;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\Component\Utility\Timer;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Tests the Timer system.
|
||||
|
@ -12,7 +12,7 @@ use Drupal\Component\Utility\Timer;
|
|||
*
|
||||
* @coversDefaultClass \Drupal\Component\Utility\Timer
|
||||
*/
|
||||
class TimerTest extends UnitTestCase {
|
||||
class TimerTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Tests Timer::read() time accumulation accuracy across multiple restarts.
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
namespace Drupal\Tests\Component\Utility;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test unicode handling features implemented in Unicode component.
|
||||
|
@ -12,54 +12,14 @@ use Drupal\Component\Utility\Unicode;
|
|||
*
|
||||
* @coversDefaultClass \Drupal\Component\Utility\Unicode
|
||||
*/
|
||||
class UnicodeTest extends UnitTestCase {
|
||||
class UnicodeTest extends TestCase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @covers ::check
|
||||
* @group legacy
|
||||
* @expectedDeprecation \Drupal\Component\Utility\Unicode::setStatus() is deprecated in Drupal 8.6.0 and will be removed before Drupal 9.0.0. In Drupal 9 there will be no way to set the status and in Drupal 8 this ability has been removed because mb_*() functions are supplied using Symfony's polyfill. See https://www.drupal.org/node/2850048.
|
||||
*/
|
||||
protected function setUp() {
|
||||
// Initialize unicode component.
|
||||
Unicode::check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Getting and settings the multibyte environment status.
|
||||
*
|
||||
* @dataProvider providerTestStatus
|
||||
* @covers ::getStatus
|
||||
* @covers ::setStatus
|
||||
*/
|
||||
public function testStatus($value, $expected, $invalid = FALSE) {
|
||||
if ($invalid) {
|
||||
$this->setExpectedException('InvalidArgumentException');
|
||||
}
|
||||
Unicode::setStatus($value);
|
||||
$this->assertEquals($expected, Unicode::getStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testStatus().
|
||||
*
|
||||
* @see testStatus()
|
||||
*
|
||||
* @return array
|
||||
* An array containing:
|
||||
* - The status value to set.
|
||||
* - The status value to expect after setting the new value.
|
||||
* - (optional) Boolean indicating invalid status. Defaults to FALSE.
|
||||
*/
|
||||
public function providerTestStatus() {
|
||||
return [
|
||||
[Unicode::STATUS_SINGLEBYTE, Unicode::STATUS_SINGLEBYTE],
|
||||
[rand(10, 100), Unicode::STATUS_SINGLEBYTE, TRUE],
|
||||
[rand(10, 100), Unicode::STATUS_SINGLEBYTE, TRUE],
|
||||
[Unicode::STATUS_MULTIBYTE, Unicode::STATUS_MULTIBYTE],
|
||||
[rand(10, 100), Unicode::STATUS_MULTIBYTE, TRUE],
|
||||
[Unicode::STATUS_ERROR, Unicode::STATUS_ERROR],
|
||||
[Unicode::STATUS_MULTIBYTE, Unicode::STATUS_MULTIBYTE],
|
||||
];
|
||||
public function testSetStatus() {
|
||||
Unicode::setStatus(Unicode::STATUS_SINGLEBYTE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -96,10 +56,10 @@ class UnicodeTest extends UnitTestCase {
|
|||
* @dataProvider providerStrtolower
|
||||
* @covers ::strtolower
|
||||
* @covers ::caseFlip
|
||||
* @group legacy
|
||||
* @expectedDeprecation \Drupal\Component\Utility\Unicode::strtolower() is deprecated in Drupal 8.6.0 and will be removed before Drupal 9.0.0. Use mb_strtolower() instead. See https://www.drupal.org/node/2850048.
|
||||
*/
|
||||
public function testStrtolower($text, $expected, $multibyte = FALSE) {
|
||||
$status = $multibyte ? Unicode::STATUS_MULTIBYTE : Unicode::STATUS_SINGLEBYTE;
|
||||
Unicode::setStatus($status);
|
||||
public function testStrtolower($text, $expected) {
|
||||
$this->assertEquals($expected, Unicode::strtolower($text));
|
||||
}
|
||||
|
||||
|
@ -109,22 +69,14 @@ class UnicodeTest extends UnitTestCase {
|
|||
* @see testStrtolower()
|
||||
*
|
||||
* @return array
|
||||
* An array containing a string, its lowercase version and whether it should
|
||||
* be processed as multibyte.
|
||||
* An array containing a string and its lowercase version.
|
||||
*/
|
||||
public function providerStrtolower() {
|
||||
$cases = [
|
||||
return [
|
||||
['tHe QUIcK bRoWn', 'the quick brown'],
|
||||
['FrançAIS is ÜBER-åwesome', 'français is über-åwesome'],
|
||||
['ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΣὨ', 'αβγδεζηθικλμνξοσὠ'],
|
||||
];
|
||||
foreach ($cases as $case) {
|
||||
// Test the same string both in multibyte and singlebyte conditions.
|
||||
array_push($case, TRUE);
|
||||
$cases[] = $case;
|
||||
}
|
||||
// Add a multibyte string.
|
||||
$cases[] = ['ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΣὨ', 'αβγδεζηθικλμνξοσὠ', TRUE];
|
||||
return $cases;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -133,10 +85,10 @@ class UnicodeTest extends UnitTestCase {
|
|||
* @dataProvider providerStrtoupper
|
||||
* @covers ::strtoupper
|
||||
* @covers ::caseFlip
|
||||
* @group legacy
|
||||
* @expectedDeprecation \Drupal\Component\Utility\Unicode::strtoupper() is deprecated in Drupal 8.6.0 and will be removed before Drupal 9.0.0. Use mb_strtoupper() instead. See https://www.drupal.org/node/2850048.
|
||||
*/
|
||||
public function testStrtoupper($text, $expected, $multibyte = FALSE) {
|
||||
$status = $multibyte ? Unicode::STATUS_MULTIBYTE : Unicode::STATUS_SINGLEBYTE;
|
||||
Unicode::setStatus($status);
|
||||
public function testStrtoupper($text, $expected) {
|
||||
$this->assertEquals($expected, Unicode::strtoupper($text));
|
||||
}
|
||||
|
||||
|
@ -146,22 +98,14 @@ class UnicodeTest extends UnitTestCase {
|
|||
* @see testStrtoupper()
|
||||
*
|
||||
* @return array
|
||||
* An array containing a string, its uppercase version and whether it should
|
||||
* be processed as multibyte.
|
||||
* An array containing a string and its uppercase version.
|
||||
*/
|
||||
public function providerStrtoupper() {
|
||||
$cases = [
|
||||
return [
|
||||
['tHe QUIcK bRoWn', 'THE QUICK BROWN'],
|
||||
['FrançAIS is ÜBER-åwesome', 'FRANÇAIS IS ÜBER-ÅWESOME'],
|
||||
['αβγδεζηθικλμνξοσὠ', 'ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΣὨ'],
|
||||
];
|
||||
foreach ($cases as $case) {
|
||||
// Test the same string both in multibyte and singlebyte conditions.
|
||||
array_push($case, TRUE);
|
||||
$cases[] = $case;
|
||||
}
|
||||
// Add a multibyte string.
|
||||
$cases[] = ['αβγδεζηθικλμνξοσὠ', 'ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΣὨ', TRUE];
|
||||
return $cases;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -199,9 +143,7 @@ class UnicodeTest extends UnitTestCase {
|
|||
* @dataProvider providerLcfirst
|
||||
* @covers ::lcfirst
|
||||
*/
|
||||
public function testLcfirst($text, $expected, $multibyte = FALSE) {
|
||||
$status = $multibyte ? Unicode::STATUS_MULTIBYTE : Unicode::STATUS_SINGLEBYTE;
|
||||
Unicode::setStatus($status);
|
||||
public function testLcfirst($text, $expected) {
|
||||
$this->assertEquals($expected, Unicode::lcfirst($text));
|
||||
}
|
||||
|
||||
|
@ -211,8 +153,7 @@ class UnicodeTest extends UnitTestCase {
|
|||
* @see testLcfirst()
|
||||
*
|
||||
* @return array
|
||||
* An array containing a string, its lowercase version and whether it should
|
||||
* be processed as multibyte.
|
||||
* An array containing a string and its lowercase version.
|
||||
*/
|
||||
public function providerLcfirst() {
|
||||
return [
|
||||
|
@ -221,7 +162,7 @@ class UnicodeTest extends UnitTestCase {
|
|||
['Über', 'über'],
|
||||
['Åwesome', 'åwesome'],
|
||||
// Add a multibyte string.
|
||||
['ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΣὨ', 'αΒΓΔΕΖΗΘΙΚΛΜΝΞΟΣὨ', TRUE],
|
||||
['ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΣὨ', 'αΒΓΔΕΖΗΘΙΚΛΜΝΞΟΣὨ'],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -231,9 +172,7 @@ class UnicodeTest extends UnitTestCase {
|
|||
* @dataProvider providerUcwords
|
||||
* @covers ::ucwords
|
||||
*/
|
||||
public function testUcwords($text, $expected, $multibyte = FALSE) {
|
||||
$status = $multibyte ? Unicode::STATUS_MULTIBYTE : Unicode::STATUS_SINGLEBYTE;
|
||||
Unicode::setStatus($status);
|
||||
public function testUcwords($text, $expected) {
|
||||
$this->assertEquals($expected, Unicode::ucwords($text));
|
||||
}
|
||||
|
||||
|
@ -243,8 +182,7 @@ class UnicodeTest extends UnitTestCase {
|
|||
* @see testUcwords()
|
||||
*
|
||||
* @return array
|
||||
* An array containing a string, its capitalized version and whether it should
|
||||
* be processed as multibyte.
|
||||
* An array containing a string and its capitalized version.
|
||||
*/
|
||||
public function providerUcwords() {
|
||||
return [
|
||||
|
@ -255,7 +193,7 @@ class UnicodeTest extends UnitTestCase {
|
|||
// Make sure we don't mangle extra spaces.
|
||||
['frànçAIS is über-åwesome', 'FrànçAIS Is Über-Åwesome'],
|
||||
// Add a multibyte string.
|
||||
['σion', 'Σion', TRUE],
|
||||
['σion', 'Σion'],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -264,13 +202,10 @@ class UnicodeTest extends UnitTestCase {
|
|||
*
|
||||
* @dataProvider providerStrlen
|
||||
* @covers ::strlen
|
||||
* @group legacy
|
||||
* @expectedDeprecation \Drupal\Component\Utility\Unicode::strlen() is deprecated in Drupal 8.6.0 and will be removed before Drupal 9.0.0. Use mb_strlen() instead. See https://www.drupal.org/node/2850048.
|
||||
*/
|
||||
public function testStrlen($text, $expected) {
|
||||
// Run through multibyte code path.
|
||||
Unicode::setStatus(Unicode::STATUS_MULTIBYTE);
|
||||
$this->assertEquals($expected, Unicode::strlen($text));
|
||||
// Run through singlebyte code path.
|
||||
Unicode::setStatus(Unicode::STATUS_SINGLEBYTE);
|
||||
$this->assertEquals($expected, Unicode::strlen($text));
|
||||
}
|
||||
|
||||
|
@ -295,13 +230,10 @@ class UnicodeTest extends UnitTestCase {
|
|||
*
|
||||
* @dataProvider providerSubstr
|
||||
* @covers ::substr
|
||||
* @group legacy
|
||||
* @expectedDeprecation \Drupal\Component\Utility\Unicode::substr() is deprecated in Drupal 8.6.0 and will be removed before Drupal 9.0.0. Use mb_substr() instead. See https://www.drupal.org/node/2850048.
|
||||
*/
|
||||
public function testSubstr($text, $start, $length, $expected) {
|
||||
// Run through multibyte code path.
|
||||
Unicode::setStatus(Unicode::STATUS_MULTIBYTE);
|
||||
$this->assertEquals($expected, Unicode::substr($text, $start, $length));
|
||||
// Run through singlebyte code path.
|
||||
Unicode::setStatus(Unicode::STATUS_SINGLEBYTE);
|
||||
$this->assertEquals($expected, Unicode::substr($text, $start, $length));
|
||||
}
|
||||
|
||||
|
@ -371,7 +303,7 @@ class UnicodeTest extends UnitTestCase {
|
|||
* - (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 +349,24 @@ class UnicodeTest extends UnitTestCase {
|
|||
['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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -530,13 +480,10 @@ class UnicodeTest extends UnitTestCase {
|
|||
*
|
||||
* @dataProvider providerStrpos
|
||||
* @covers ::strpos
|
||||
* @group legacy
|
||||
* @expectedDeprecation \Drupal\Component\Utility\Unicode::strpos() is deprecated in Drupal 8.6.0 and will be removed before Drupal 9.0.0. Use mb_strpos() instead. See https://www.drupal.org/node/2850048.
|
||||
*/
|
||||
public function testStrpos($haystack, $needle, $offset, $expected) {
|
||||
// Run through multibyte code path.
|
||||
Unicode::setStatus(Unicode::STATUS_MULTIBYTE);
|
||||
$this->assertEquals($expected, Unicode::strpos($haystack, $needle, $offset));
|
||||
// Run through singlebyte code path.
|
||||
Unicode::setStatus(Unicode::STATUS_SINGLEBYTE);
|
||||
$this->assertEquals($expected, Unicode::strpos($haystack, $needle, $offset));
|
||||
}
|
||||
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
namespace Drupal\Tests\Component\Utility;
|
||||
|
||||
use Drupal\Component\Utility\UrlHelper;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @group Utility
|
||||
*
|
||||
* @coversDefaultClass \Drupal\Component\Utility\UrlHelper
|
||||
*/
|
||||
class UrlHelperTest extends UnitTestCase {
|
||||
class UrlHelperTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Provides test data for testBuildQuery().
|
||||
|
@ -269,6 +269,14 @@ class UrlHelperTest extends UnitTestCase {
|
|||
'fragment' => 'footer',
|
||||
],
|
||||
],
|
||||
'absolute fragment, no query' => [
|
||||
'http://www.example.com/my/path#footer',
|
||||
[
|
||||
'path' => 'http://www.example.com/my/path',
|
||||
'query' => [],
|
||||
'fragment' => 'footer',
|
||||
],
|
||||
],
|
||||
[
|
||||
'http://',
|
||||
[
|
||||
|
@ -295,6 +303,14 @@ class UrlHelperTest extends UnitTestCase {
|
|||
'fragment' => 'footer',
|
||||
],
|
||||
],
|
||||
'relative fragment, no query' => [
|
||||
'/my/path#footer',
|
||||
[
|
||||
'path' => '/my/path',
|
||||
'query' => [],
|
||||
'fragment' => 'footer',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -391,11 +407,11 @@ class UrlHelperTest extends UnitTestCase {
|
|||
* @covers ::filterBadProtocol
|
||||
*
|
||||
* @param string $uri
|
||||
* Protocol URI.
|
||||
* Protocol URI.
|
||||
* @param string $expected
|
||||
* Expected escaped value.
|
||||
* Expected escaped value.
|
||||
* @param array $protocols
|
||||
* Protocols to allow.
|
||||
* Protocols to allow.
|
||||
*/
|
||||
public function testFilterBadProtocol($uri, $expected, $protocols) {
|
||||
UrlHelper::setAllowedProtocols($protocols);
|
||||
|
@ -430,11 +446,11 @@ class UrlHelperTest extends UnitTestCase {
|
|||
* @covers ::stripDangerousProtocols
|
||||
*
|
||||
* @param string $uri
|
||||
* Protocol URI.
|
||||
* Protocol URI.
|
||||
* @param string $expected
|
||||
* Expected escaped value.
|
||||
* Expected escaped value.
|
||||
* @param array $protocols
|
||||
* Protocols to allow.
|
||||
* Protocols to allow.
|
||||
*/
|
||||
public function testStripDangerousProtocols($uri, $expected, $protocols) {
|
||||
UrlHelper::setAllowedProtocols($protocols);
|
||||
|
@ -547,6 +563,10 @@ class UrlHelperTest extends UnitTestCase {
|
|||
['http://example.com/foo', 'http://example.com/bar', FALSE],
|
||||
['http://example.com', 'http://example.com/bar', FALSE],
|
||||
['http://example.com/bar', 'http://example.com/bar/', FALSE],
|
||||
// Ensure \ is normalised to / since some browsers do that.
|
||||
['http://www.example.ca\@example.com', 'http://example.com', FALSE],
|
||||
// Some browsers ignore or strip leading control characters.
|
||||
["\x00//www.example.ca", 'http://example.com', FALSE],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -562,7 +582,12 @@ class UrlHelperTest extends UnitTestCase {
|
|||
* @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,8 +2,9 @@
|
|||
|
||||
namespace Drupal\Tests\Component\Utility;
|
||||
|
||||
use Drupal\Component\Utility\Random;
|
||||
use Drupal\Component\Utility\UserAgent;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Tests bytes size parsing helper methods.
|
||||
|
@ -12,7 +13,7 @@ use Drupal\Tests\UnitTestCase;
|
|||
*
|
||||
* @coversDefaultClass \Drupal\Component\Utility\UserAgent
|
||||
*/
|
||||
class UserAgentTest extends UnitTestCase {
|
||||
class UserAgentTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Helper method to supply language codes to testGetBestMatchingLangcode().
|
||||
|
@ -82,6 +83,9 @@ class UserAgentTest extends UnitTestCase {
|
|||
* - Expected best matching language code.
|
||||
*/
|
||||
public function providerTestGetBestMatchingLangcode() {
|
||||
// Random generator.
|
||||
$random = new Random();
|
||||
|
||||
return [
|
||||
// Equal qvalue for each language, choose the site preferred one.
|
||||
['en,en-US,fr-CA,fr,es-MX', 'en'],
|
||||
|
@ -141,7 +145,7 @@ class UserAgentTest extends UnitTestCase {
|
|||
['', FALSE],
|
||||
['de,pl', FALSE],
|
||||
['iecRswK4eh', FALSE],
|
||||
[$this->randomMachineName(10), FALSE],
|
||||
[$random->name(10, TRUE), FALSE],
|
||||
|
||||
// Chinese langcodes.
|
||||
['zh-cn, en-us;q=0.90, en;q=0.80, zh;q=0.70', 'zh-hans'],
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
|
||||
namespace Drupal\Tests\Component\Utility;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\Component\Utility\Variable;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test variable export functionality in Variable component.
|
||||
|
@ -18,7 +18,7 @@ use Drupal\Component\Utility\Variable;
|
|||
*
|
||||
* @coversDefaultClass \Drupal\Component\Utility\Variable
|
||||
*/
|
||||
class VariableTest extends UnitTestCase {
|
||||
class VariableTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Data provider for testExport().
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace Drupal\Tests\Component\Utility;
|
|||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Component\Utility\UrlHelper;
|
||||
use Drupal\Component\Utility\Xss;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* XSS Filtering tests.
|
||||
|
@ -20,7 +20,7 @@ use Drupal\Tests\UnitTestCase;
|
|||
* - CVE-2002-1806, ~CVE-2005-0682, ~CVE-2005-2106, CVE-2005-3973,
|
||||
* CVE-2006-1226 (= rev. 1.112?), CVE-2008-0273, CVE-2008-3740.
|
||||
*/
|
||||
class XssTest extends UnitTestCase {
|
||||
class XssTest extends TestCase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -503,31 +503,31 @@ class XssTest extends UnitTestCase {
|
|||
'<img src="http://example.com/foo.jpg" title="Example: title" alt="Example: alt">',
|
||||
'<img src="http://example.com/foo.jpg" title="Example: title" alt="Example: alt">',
|
||||
'Image tag with alt and title attribute',
|
||||
['img']
|
||||
['img'],
|
||||
],
|
||||
[
|
||||
'<a href="https://www.drupal.org/" rel="dc:publisher">Drupal</a>',
|
||||
'<a href="https://www.drupal.org/" rel="dc:publisher">Drupal</a>',
|
||||
'Link tag with rel attribute',
|
||||
['a']
|
||||
['a'],
|
||||
],
|
||||
[
|
||||
'<span property="dc:subject">Drupal 8: The best release ever.</span>',
|
||||
'<span property="dc:subject">Drupal 8: The best release ever.</span>',
|
||||
'Span tag with property attribute',
|
||||
['span']
|
||||
['span'],
|
||||
],
|
||||
[
|
||||
'<img src="http://example.com/foo.jpg" data-caption="Drupal 8: The best release ever.">',
|
||||
'<img src="http://example.com/foo.jpg" data-caption="Drupal 8: The best release ever.">',
|
||||
'Image tag with data attribute',
|
||||
['img']
|
||||
['img'],
|
||||
],
|
||||
[
|
||||
'<a data-a2a-url="foo"></a>',
|
||||
'<a data-a2a-url="foo"></a>',
|
||||
'Link tag with numeric data attribute',
|
||||
['a']
|
||||
['a'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -7,14 +7,14 @@ use Drupal\Component\Uuid\UuidInterface;
|
|||
use Drupal\Component\Uuid\Com;
|
||||
use Drupal\Component\Uuid\Pecl;
|
||||
use Drupal\Component\Uuid\Php;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Tests the handling of Universally Unique Identifiers (UUIDs).
|
||||
*
|
||||
* @group Uuid
|
||||
*/
|
||||
class UuidTest extends UnitTestCase {
|
||||
class UuidTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Tests generating valid UUIDs.
|
||||
|
|
Reference in a new issue