Update to Drupal 8.0.0 beta 14. For more information, see https://drupal.org/node/2544542
This commit is contained in:
parent
3b2511d96d
commit
81ccda77eb
2155 changed files with 54307 additions and 46870 deletions
241
core/tests/Drupal/Tests/Component/Assertion/InspectorTest.php
Normal file
241
core/tests/Drupal/Tests/Component/Assertion/InspectorTest.php
Normal file
|
@ -0,0 +1,241 @@
|
|||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Component\InspectorTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Component\Assertion;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use Drupal\Component\Assertion\Inspector;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Component\Assertion\Inspector
|
||||
* @group Inspector
|
||||
*/
|
||||
class InspectorTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
/**
|
||||
* Tests asserting argument is an array or traversable object.
|
||||
*
|
||||
* @covers ::assertTraversable
|
||||
*/
|
||||
public function testAssertTraversable() {
|
||||
$this->assertTrue(Inspector::assertTraversable([]));
|
||||
$this->assertTrue(Inspector::assertTraversable(new \ArrayObject()));
|
||||
$this->assertFalse(Inspector::assertTraversable(new \stdClass()));
|
||||
$this->assertFalse(Inspector::assertTraversable('foo'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests asserting all members are strings.
|
||||
*
|
||||
* @covers ::assertAllStrings
|
||||
*/
|
||||
public function testAssertAllStrings() {
|
||||
$this->assertTrue(Inspector::assertAllStrings([]));
|
||||
$this->assertTrue(Inspector::assertAllStrings(['foo', 'bar']));
|
||||
$this->assertFalse(Inspector::assertAllStrings('foo'));
|
||||
$this->assertFalse(Inspector::assertAllStrings(['foo', new StringObject()]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests asserting all members are strings or objects with __toString().
|
||||
*
|
||||
* @covers ::assertAllStringable
|
||||
*/
|
||||
public function testAssertAllStringable() {
|
||||
$this->assertTrue(Inspector::assertAllStringable([]));
|
||||
$this->assertTrue(Inspector::assertAllStringable(['foo', 'bar']));
|
||||
$this->assertFalse(Inspector::assertAllStringable('foo'));
|
||||
$this->assertTrue(Inspector::assertAllStringable(['foo', new StringObject()]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests asserting all members are arrays.
|
||||
*
|
||||
* @covers ::assertAllArrays
|
||||
*/
|
||||
public function testAssertAllArrays() {
|
||||
$this->assertTrue(Inspector::assertAllArrays([]));
|
||||
$this->assertTrue(Inspector::assertAllArrays([[], []]));
|
||||
$this->assertFalse(Inspector::assertAllArrays([[], 'foo']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests asserting array is 0-indexed - the strict definition of array.
|
||||
*
|
||||
* @covers ::assertStrictArray
|
||||
*/
|
||||
public function testAssertStrictArray() {
|
||||
$this->assertTrue(Inspector::assertStrictArray([]));
|
||||
$this->assertTrue(Inspector::assertStrictArray(['bar', 'foo']));
|
||||
$this->assertFalse(Inspector::assertStrictArray(['foo' => 'bar', 'bar' => 'foo']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests asserting all members are strict arrays.
|
||||
*
|
||||
* @covers ::assertAllStrictArrays
|
||||
*/
|
||||
public function testAssertAllStrictArrays() {
|
||||
$this->assertTrue(Inspector::assertAllStrictArrays([]));
|
||||
$this->assertTrue(Inspector::assertAllStrictArrays([[], []]));
|
||||
$this->assertFalse(Inspector::assertAllStrictArrays([['foo' => 'bar', 'bar' => 'foo']]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests asserting all members have specified keys.
|
||||
*
|
||||
* @covers ::assertAllHaveKey
|
||||
*/
|
||||
public function testAssertAllHaveKey() {
|
||||
$this->assertTrue(Inspector::assertAllHaveKey([]));
|
||||
$this->assertTrue(Inspector::assertAllHaveKey([['foo' => 'bar', 'bar' => 'foo']]));
|
||||
$this->assertTrue(Inspector::assertAllHaveKey([['foo' => 'bar', 'bar' => 'foo']], 'foo'));
|
||||
$this->assertTrue(Inspector::assertAllHaveKey([['foo' => 'bar', 'bar' => 'foo']], 'bar', 'foo'));
|
||||
$this->assertFalse(Inspector::assertAllHaveKey([['foo' => 'bar', 'bar' => 'foo']], 'bar', 'foo', 'moo'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests asserting all members are integers.
|
||||
*
|
||||
* @covers ::assertAllIntegers
|
||||
*/
|
||||
public function testAssertAllIntegers() {
|
||||
$this->assertTrue(Inspector::assertAllIntegers([]));
|
||||
$this->assertTrue(Inspector::assertAllIntegers([1, 2, 3]));
|
||||
$this->assertFalse(Inspector::assertAllIntegers([1, 2, 3.14]));
|
||||
$this->assertFalse(Inspector::assertAllIntegers([1, '2', 3]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests asserting all members are floating point variables.
|
||||
*
|
||||
* @covers ::assertAllFloat
|
||||
*/
|
||||
public function testAssertAllFloat() {
|
||||
$this->assertTrue(Inspector::assertAllFloat([]));
|
||||
$this->assertTrue(Inspector::assertAllFloat([1.0, 2.1, 3.14]));
|
||||
$this->assertFalse(Inspector::assertAllFloat([1, 2.1, 3.14]));
|
||||
$this->assertFalse(Inspector::assertAllFloat([1.0, '2', 3]));
|
||||
$this->assertFalse(Inspector::assertAllFloat(['Titanic']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests asserting all members are callable.
|
||||
*
|
||||
* @covers ::assertAllCallable
|
||||
*/
|
||||
public function testAllCallable() {
|
||||
$this->assertTrue(Inspector::assertAllCallable([
|
||||
'strchr',
|
||||
[$this, 'callMe'],
|
||||
[__CLASS__, 'callMeStatic'],
|
||||
function() {
|
||||
return TRUE;
|
||||
}
|
||||
]));
|
||||
|
||||
$this->assertFalse(Inspector::assertAllCallable([
|
||||
'strchr',
|
||||
[$this, 'callMe'],
|
||||
[__CLASS__, 'callMeStatic'],
|
||||
function() {
|
||||
return TRUE;
|
||||
},
|
||||
"I'm not callable"
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests asserting all members are !empty().
|
||||
*
|
||||
* @covers ::assertAllNotEmpty
|
||||
*/
|
||||
public function testAllNotEmpty() {
|
||||
$this->assertTrue(Inspector::assertAllNotEmpty([1, 'two']));
|
||||
$this->assertFalse(Inspector::assertAllNotEmpty(['']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests asserting all arguments are numbers or strings castable to numbers.
|
||||
*
|
||||
* @covers ::assertAllNumeric
|
||||
*/
|
||||
public function testAssertAllNumeric() {
|
||||
$this->assertTrue(Inspector::assertAllNumeric([1, '2', 3.14]));
|
||||
$this->assertFalse(Inspector::assertAllNumeric([1, 'two', 3.14]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests asserting strstr() or stristr() match.
|
||||
*
|
||||
* @covers ::assertAllMatch
|
||||
*/
|
||||
public function testAssertAllMatch() {
|
||||
$this->assertTrue(Inspector::assertAllMatch('f', ['fee', 'fi', 'fo']));
|
||||
$this->assertTrue(Inspector::assertAllMatch('F', ['fee', 'fi', 'fo']));
|
||||
$this->assertTrue(Inspector::assertAllMatch('f', ['fee', 'fi', 'fo'], TRUE));
|
||||
$this->assertFalse(Inspector::assertAllMatch('F', ['fee', 'fi', 'fo'], TRUE));
|
||||
$this->assertFalse(Inspector::assertAllMatch('e', ['fee', 'fi', 'fo']));
|
||||
$this->assertFalse(Inspector::assertAllMatch('1', [12]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests asserting regular expression match.
|
||||
*
|
||||
* @covers ::assertAllRegularExpressionMatch
|
||||
*/
|
||||
public function testAssertAllRegularExpressionMatch() {
|
||||
$this->assertTrue(Inspector::assertAllRegularExpressionMatch('/f/i', ['fee', 'fi', 'fo']));
|
||||
$this->assertTrue(Inspector::assertAllRegularExpressionMatch('/F/i', ['fee', 'fi', 'fo']));
|
||||
$this->assertTrue(Inspector::assertAllRegularExpressionMatch('/f/', ['fee', 'fi', 'fo']));
|
||||
$this->assertFalse(Inspector::assertAllRegularExpressionMatch('/F/', ['fee', 'fi', 'fo']));
|
||||
$this->assertFalse(Inspector::assertAllRegularExpressionMatch('/e/', ['fee', 'fi', 'fo']));
|
||||
$this->assertFalse(Inspector::assertAllRegularExpressionMatch('/1/', [12]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests asserting all members are objects.
|
||||
*
|
||||
* @covers ::assertAllObjects
|
||||
*/
|
||||
public function testAssertAllObjects() {
|
||||
$this->assertTrue(Inspector::assertAllObjects([new \ArrayObject(), new \ArrayObject()]));
|
||||
$this->assertFalse(Inspector::assertAllObjects([new \ArrayObject(), new \ArrayObject(), 'foo']));
|
||||
$this->assertTrue(Inspector::assertAllObjects([new \ArrayObject(), new \ArrayObject()], '\\Traversable'));
|
||||
$this->assertFalse(Inspector::assertAllObjects([new \ArrayObject(), new \ArrayObject(), 'foo'], '\\Traversable'));
|
||||
$this->assertFalse(Inspector::assertAllObjects([new \ArrayObject(), new StringObject()], '\\Traversable'));
|
||||
$this->assertTrue(Inspector::assertAllObjects([new \ArrayObject(), new StringObject()], '\\Traversable', '\\Drupal\\Tests\\Component\\Assertion\\StringObject'));
|
||||
$this->assertFalse(Inspector::assertAllObjects([new \ArrayObject(), new StringObject(), new \stdClass()], '\\ArrayObject', '\\Drupal\\Tests\\Component\\Assertion\\StringObject'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method referenced by ::testAllCallable().
|
||||
*/
|
||||
public function callMe() {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method referenced by ::testAllCallable().
|
||||
*/
|
||||
public static function callMeStatic() {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Quick class for testing for objects with __toString.
|
||||
*/
|
||||
class StringObject {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __toString() {
|
||||
return 'foo';
|
||||
}
|
||||
|
||||
}
|
|
@ -37,7 +37,23 @@ class ProxyBuilderTest extends UnitTestCase {
|
|||
*/
|
||||
public function testBuildProxyClassName() {
|
||||
$class_name = $this->proxyBuilder->buildProxyClassName('Drupal\Tests\Component\ProxyBuilder\TestServiceNoMethod');
|
||||
$this->assertEquals('Drupal_Tests_Component_ProxyBuilder_TestServiceNoMethod_Proxy', $class_name);
|
||||
$this->assertEquals('Drupal\Tests\ProxyClass\Component\ProxyBuilder\TestServiceNoMethod', $class_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::buildProxyClassName
|
||||
*/
|
||||
public function testBuildProxyClassNameForModule() {
|
||||
$class_name = $this->proxyBuilder->buildProxyClassName('Drupal\views_ui\ParamConverter\ViewUIConverter');
|
||||
$this->assertEquals('Drupal\views_ui\ProxyClass\ParamConverter\ViewUIConverter', $class_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::buildProxyNamespace
|
||||
*/
|
||||
public function testBuildProxyNamespace() {
|
||||
$class_name = $this->proxyBuilder->buildProxyNamespace('Drupal\Tests\Component\ProxyBuilder\TestServiceNoMethod');
|
||||
$this->assertEquals('Drupal\Tests\ProxyClass\Component\ProxyBuilder', $class_name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -65,10 +81,13 @@ class ProxyBuilderTest extends UnitTestCase {
|
|||
|
||||
$method_body = <<<'EOS'
|
||||
|
||||
public function method()
|
||||
{
|
||||
return $this->lazyLoadItself()->method();
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function method()
|
||||
{
|
||||
return $this->lazyLoadItself()->method();
|
||||
}
|
||||
|
||||
EOS;
|
||||
$this->assertEquals($this->buildExpectedClass($class, $method_body), $result);
|
||||
|
@ -86,10 +105,13 @@ EOS;
|
|||
|
||||
$method_body = <<<'EOS'
|
||||
|
||||
public function methodWithParameter($parameter)
|
||||
{
|
||||
return $this->lazyLoadItself()->methodWithParameter($parameter);
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function methodWithParameter($parameter)
|
||||
{
|
||||
return $this->lazyLoadItself()->methodWithParameter($parameter);
|
||||
}
|
||||
|
||||
EOS;
|
||||
$this->assertEquals($this->buildExpectedClass($class, $method_body), $result);
|
||||
|
@ -108,11 +130,14 @@ EOS;
|
|||
// @todo Solve the silly linebreak for array()
|
||||
$method_body = <<<'EOS'
|
||||
|
||||
public function complexMethod($parameter, callable $function, \Drupal\Tests\Component\ProxyBuilder\TestServiceNoMethod $test_service = NULL, array &$elements = array (
|
||||
))
|
||||
{
|
||||
return $this->lazyLoadItself()->complexMethod($parameter, $function, $test_service, $elements);
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function complexMethod($parameter, callable $function, \Drupal\Tests\Component\ProxyBuilder\TestServiceNoMethod $test_service = NULL, array &$elements = array (
|
||||
))
|
||||
{
|
||||
return $this->lazyLoadItself()->complexMethod($parameter, $function, $test_service, $elements);
|
||||
}
|
||||
|
||||
EOS;
|
||||
|
||||
|
@ -131,10 +156,13 @@ EOS;
|
|||
// @todo Solve the silly linebreak for array()
|
||||
$method_body = <<<'EOS'
|
||||
|
||||
public function &returnReference()
|
||||
{
|
||||
return $this->lazyLoadItself()->returnReference();
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function &returnReference()
|
||||
{
|
||||
return $this->lazyLoadItself()->returnReference();
|
||||
}
|
||||
|
||||
EOS;
|
||||
|
||||
|
@ -153,10 +181,13 @@ EOS;
|
|||
|
||||
$method_body = <<<'EOS'
|
||||
|
||||
public function testMethod($parameter)
|
||||
{
|
||||
return $this->lazyLoadItself()->testMethod($parameter);
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function testMethod($parameter)
|
||||
{
|
||||
return $this->lazyLoadItself()->testMethod($parameter);
|
||||
}
|
||||
|
||||
EOS;
|
||||
|
||||
|
@ -189,10 +220,13 @@ EOS;
|
|||
|
||||
$method_body = <<<'EOS'
|
||||
|
||||
public function testMethod($parameter)
|
||||
{
|
||||
return $this->lazyLoadItself()->testMethod($parameter);
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function testMethod($parameter)
|
||||
{
|
||||
return $this->lazyLoadItself()->testMethod($parameter);
|
||||
}
|
||||
|
||||
EOS;
|
||||
|
||||
|
@ -212,10 +246,13 @@ $this->assertEquals($this->buildExpectedClass($class, $method_body), $result);
|
|||
// Ensure that the static method is not wrapped.
|
||||
$method_body = <<<'EOS'
|
||||
|
||||
public static function testMethod($parameter)
|
||||
{
|
||||
\Drupal\Tests\Component\ProxyBuilder\TestServiceWithPublicStaticMethod::testMethod($parameter);
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function testMethod($parameter)
|
||||
{
|
||||
\Drupal\Tests\Component\ProxyBuilder\TestServiceWithPublicStaticMethod::testMethod($parameter);
|
||||
}
|
||||
|
||||
EOS;
|
||||
|
||||
|
@ -232,53 +269,87 @@ EOS;
|
|||
* The code of the entire proxy.
|
||||
*/
|
||||
protected function buildExpectedClass($class, $expected_methods_body, $interface_string = '') {
|
||||
$proxy_class = $this->proxyBuilder->buildProxyClassName($class);
|
||||
$namespace = ProxyBuilder::buildProxyNamespace($class);
|
||||
$reflection = new \ReflectionClass($class);
|
||||
$proxy_class = $reflection->getShortName();
|
||||
|
||||
$expected_string = <<<'EOS'
|
||||
/**
|
||||
* Provides a proxy class for \{{ class }}.
|
||||
*
|
||||
* @see \Drupal\Component\ProxyBuilder
|
||||
*/
|
||||
class {{ proxy_class }}{{ interface_string }}
|
||||
{
|
||||
|
||||
namespace {{ namespace }} {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $serviceId;
|
||||
|
||||
/**
|
||||
* @var \{{ class }}
|
||||
*/
|
||||
protected $service;
|
||||
|
||||
/**
|
||||
* The service container.
|
||||
* Provides a proxy class for \{{ class }}.
|
||||
*
|
||||
* @var \Symfony\Component\DependencyInjection\ContainerInterface
|
||||
* @see \Drupal\Component\ProxyBuilder
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
public function __construct(\Symfony\Component\DependencyInjection\ContainerInterface $container, $serviceId)
|
||||
class {{ proxy_class }}{{ interface_string }}
|
||||
{
|
||||
$this->container = $container;
|
||||
$this->serviceId = $serviceId;
|
||||
}
|
||||
|
||||
protected function lazyLoadItself()
|
||||
{
|
||||
if (!isset($this->service)) {
|
||||
$method_name = 'get' . Container::camelize($this->serviceId) . 'Service';
|
||||
$this->service = $this->container->$method_name(false);
|
||||
/**
|
||||
* The id of the original proxied service.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $drupalProxyOriginalServiceId;
|
||||
|
||||
/**
|
||||
* The real proxied service, after it was lazy loaded.
|
||||
*
|
||||
* @var \{{ class }}
|
||||
*/
|
||||
protected $service;
|
||||
|
||||
/**
|
||||
* The service container.
|
||||
*
|
||||
* @var \Symfony\Component\DependencyInjection\ContainerInterface
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
* Constructs a ProxyClass Drupal proxy object.
|
||||
*
|
||||
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
|
||||
* The container.
|
||||
* @param string $drupal_proxy_original_service_id
|
||||
* The service ID of the original service.
|
||||
*/
|
||||
public function __construct(\Symfony\Component\DependencyInjection\ContainerInterface $container, $drupal_proxy_original_service_id)
|
||||
{
|
||||
$this->container = $container;
|
||||
$this->drupalProxyOriginalServiceId = $drupal_proxy_original_service_id;
|
||||
}
|
||||
|
||||
return $this->service;
|
||||
}
|
||||
/**
|
||||
* Lazy loads the real service from the container.
|
||||
*
|
||||
* @return object
|
||||
* Returns the constructed real service.
|
||||
*/
|
||||
protected function lazyLoadItself()
|
||||
{
|
||||
if (!isset($this->service)) {
|
||||
$this->service = $this->container->get($this->drupalProxyOriginalServiceId);
|
||||
}
|
||||
|
||||
return $this->service;
|
||||
}
|
||||
{{ expected_methods_body }}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
EOS;
|
||||
|
||||
$expected_methods_body = implode("\n", array_map(function ($value) {
|
||||
if ($value === '') {
|
||||
return $value;
|
||||
}
|
||||
return " $value";
|
||||
}, explode("\n", $expected_methods_body)));
|
||||
|
||||
$expected_string = str_replace('{{ proxy_class }}', $proxy_class, $expected_string);
|
||||
$expected_string = str_replace('{{ namespace }}', $namespace, $expected_string);
|
||||
$expected_string = str_replace('{{ class }}', $class, $expected_string);
|
||||
$expected_string = str_replace('{{ expected_methods_body }}', $expected_methods_body, $expected_string);
|
||||
$expected_string = str_replace('{{ interface_string }}', $interface_string, $expected_string);
|
||||
|
|
|
@ -1,129 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Component\ProxyBuilder\ProxyDumperTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Component\ProxyBuilder;
|
||||
|
||||
use Drupal\Component\ProxyBuilder\ProxyDumper;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Component\ProxyBuilder\ProxyDumper
|
||||
* @group proxy_builder
|
||||
*/
|
||||
class ProxyDumperTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* The mocked proxy builder.
|
||||
*
|
||||
* @var \Drupal\Component\ProxyBuilder\ProxyBuilder|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $proxyBuilder;
|
||||
|
||||
/**
|
||||
* The tested proxy dumper.
|
||||
*
|
||||
* @var \Drupal\Component\ProxyBuilder\ProxyDumper
|
||||
*/
|
||||
protected $proxyDumper;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->proxyBuilder = $this->getMockBuilder('Drupal\Component\ProxyBuilder\ProxyBuilder')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['build'])
|
||||
->getMock();
|
||||
$this->proxyDumper = new ProxyDumper($this->proxyBuilder);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerTestIsProxyCandidate
|
||||
* @covers ::isProxyCandidate
|
||||
*/
|
||||
public function testIsProxyCandidate(Definition $definition, $expected) {
|
||||
$this->assertSame($expected, $this->proxyDumper->isProxyCandidate($definition));
|
||||
}
|
||||
|
||||
public function providerTestIsProxyCandidate() {
|
||||
// Not lazy service.
|
||||
$data = [];
|
||||
$definition = new Definition('Drupal\Tests\Component\ProxyBuilder\TestService');
|
||||
$data[] = [$definition, FALSE];
|
||||
// Not existing service.
|
||||
$definition = new Definition('Drupal\Tests\Component\ProxyBuilder\TestNotExistingService');
|
||||
$definition->setLazy(TRUE);
|
||||
$data[] = [$definition, FALSE];
|
||||
// Existing and lazy service.
|
||||
$definition = new Definition('Drupal\Tests\Component\ProxyBuilder\TestService');
|
||||
$definition->setLazy(TRUE);
|
||||
$data[] = [$definition, TRUE];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function testGetProxyFactoryCode() {
|
||||
$definition = new Definition('Drupal\Tests\Component\ProxyBuilder\TestService');
|
||||
$definition->setLazy(TRUE);
|
||||
|
||||
$result = $this->proxyDumper->getProxyFactoryCode($definition, 'test_service');
|
||||
|
||||
$expected = <<<'EOS'
|
||||
if ($lazyLoad) {
|
||||
return $this->services['test_service'] = new Drupal_Tests_Component_ProxyBuilder_TestService_Proxy($this, 'test_service');
|
||||
}
|
||||
|
||||
EOS;
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getProxyCode
|
||||
*/
|
||||
public function testGetProxyCode() {
|
||||
$definition = new Definition('Drupal\Tests\Component\ProxyBuilder\TestService');
|
||||
$definition->setLazy(TRUE);
|
||||
|
||||
$class = 'class Drupal_Tests_Component_ProxyBuilder_TestService_Proxy {}';
|
||||
$this->proxyBuilder->expects($this->once())
|
||||
->method('build')
|
||||
->with('Drupal\Tests\Component\ProxyBuilder\TestService')
|
||||
->willReturn($class);
|
||||
|
||||
$result = $this->proxyDumper->getProxyCode($definition);
|
||||
$this->assertEquals($class, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getProxyCode
|
||||
*/
|
||||
public function testGetProxyCodeWithSameClassMultipleTimes() {
|
||||
$definition = new Definition('Drupal\Tests\Component\ProxyBuilder\TestService');
|
||||
$definition->setLazy(TRUE);
|
||||
|
||||
$class = 'class Drupal_Tests_Component_ProxyBuilder_TestService_Proxy {}';
|
||||
$this->proxyBuilder->expects($this->once())
|
||||
->method('build')
|
||||
->with('Drupal\Tests\Component\ProxyBuilder\TestService')
|
||||
->willReturn($class);
|
||||
|
||||
$result = $this->proxyDumper->getProxyCode($definition);
|
||||
$this->assertEquals($class, $result);
|
||||
|
||||
$result = $this->proxyDumper->getProxyCode($definition);
|
||||
$this->assertEquals('', $result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class TestService {
|
||||
|
||||
}
|
|
@ -8,6 +8,7 @@
|
|||
namespace Drupal\Tests\Component\Utility;
|
||||
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Component\Utility\Xss;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
|
@ -212,6 +213,41 @@ class SafeMarkupTest extends UnitTestCase {
|
|||
$this->assertEquals($is_safe, SafeMarkup::isSafe($result));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the interaction between the safe list and XSS filtering.
|
||||
*
|
||||
* @covers ::xssFilter
|
||||
* @covers ::escape
|
||||
*/
|
||||
public function testAdminXss() {
|
||||
// Use the predefined XSS admin tag list. This strips the <marquee> tags.
|
||||
$this->assertEquals('text', SafeMarkup::xssFilter('<marquee>text</marquee>', Xss::getAdminTagList()));
|
||||
$this->assertTrue(SafeMarkup::isSafe('text'), 'The string \'text\' is marked as safe.');
|
||||
|
||||
// This won't strip the <marquee> tags and the string with HTML will be
|
||||
// marked as safe.
|
||||
$filtered = SafeMarkup::xssFilter('<marquee>text</marquee>', array('marquee'));
|
||||
$this->assertEquals('<marquee>text</marquee>', $filtered);
|
||||
$this->assertTrue(SafeMarkup::isSafe('<marquee>text</marquee>'), 'The string \'<marquee>text</marquee>\' is marked as safe.');
|
||||
|
||||
// SafeMarkup::xssFilter() with the default tag list will strip the
|
||||
// <marquee> tag even though the string was marked safe above.
|
||||
$this->assertEquals('text', SafeMarkup::xssFilter('<marquee>text</marquee>'));
|
||||
|
||||
// SafeMarkup::escape() will not escape the markup tag since the string was
|
||||
// marked safe above.
|
||||
$this->assertEquals('<marquee>text</marquee>', SafeMarkup::escape($filtered));
|
||||
|
||||
// SafeMarkup::checkPlain() will escape the markup tag even though the
|
||||
// string was marked safe above.
|
||||
$this->assertEquals('<marquee>text</marquee>', SafeMarkup::checkPlain($filtered));
|
||||
|
||||
// Ensure that SafeMarkup::xssFilter strips all tags when passed an empty
|
||||
// array and uses the default tag list when not passed a tag list.
|
||||
$this->assertEquals('text', SafeMarkup::xssFilter('<em>text</em>', []));
|
||||
$this->assertEquals('<em>text</em>', SafeMarkup::xssFilter('<em>text</em>'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testReplace().
|
||||
*
|
||||
|
|
Reference in a new issue