Update to Drupal 8.1.0. For more information, see https://www.drupal.org/drupal-8.1.0-release-notes
This commit is contained in:
parent
b11a755ba8
commit
c0a0d5a94c
6920 changed files with 64395 additions and 57312 deletions
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Access\CsrfAccessCheckTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Access;
|
||||
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Access\CsrfTokenGeneratorTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Access;
|
||||
|
||||
use Drupal\Core\Site\Settings;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Access\DefaultAccessCheckTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Access;
|
||||
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Access\RouteProcessorCsrfTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Access;
|
||||
|
||||
use Drupal\Core\Render\BubbleableMetadata;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Ajax\AjaxCommandsTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Ajax;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Ajax\AjaxResponseTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Ajax;
|
||||
|
||||
use Drupal\Core\Ajax\AjaxResponse;
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\Core\Annotation;
|
||||
|
||||
use Drupal\Core\Annotation\PluralTranslation;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Core\Annotation\PluralTranslation
|
||||
* @group Annotation
|
||||
*/
|
||||
class PluralTranslationTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @covers ::get
|
||||
*
|
||||
* @dataProvider providerTestGet
|
||||
*/
|
||||
public function testGet(array $values) {
|
||||
$annotation = new PluralTranslation($values);
|
||||
|
||||
$default_values = [
|
||||
'context' => NULL,
|
||||
];
|
||||
$this->assertEquals($values + $default_values, $annotation->get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides data to self::testGet().
|
||||
*/
|
||||
public function providerTestGet() {
|
||||
$data = [];
|
||||
$data[] = [
|
||||
[
|
||||
'singular' => $this->randomMachineName(),
|
||||
'plural' => $this->randomMachineName(),
|
||||
'context' => $this->randomMachineName(),
|
||||
],
|
||||
];
|
||||
$data[] = [
|
||||
[
|
||||
'singular' => $this->randomMachineName(),
|
||||
'plural' => $this->randomMachineName(),
|
||||
],
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerTestMissingData
|
||||
*/
|
||||
public function testMissingData($data) {
|
||||
$this->setExpectedException(\InvalidArgumentException::class);
|
||||
new PluralTranslation($data);
|
||||
}
|
||||
|
||||
public function providerTestMissingData() {
|
||||
$data = [];
|
||||
$data['all-missing'] = [[]];
|
||||
$data['singular-missing'] = [['plural' => 'muh']];
|
||||
$data['plural-missing'] = [['singular' => 'muh']];
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Annotation\TranslationTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Annotation;
|
||||
|
||||
use Drupal\Core\Annotation\Translation;
|
||||
|
|
|
@ -1,11 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Asset\CssCollectionGrouperUnitTest.
|
||||
*/
|
||||
|
||||
|
||||
namespace Drupal\Tests\Core\Asset;
|
||||
|
||||
use Drupal\Core\Asset\CssCollectionGrouper;
|
||||
|
@ -46,15 +40,15 @@ class CssCollectionGrouperUnitTest extends UnitTestCase {
|
|||
'browsers' => array('IE' => TRUE, '!IE' => TRUE),
|
||||
'basename' => 'system.base.css',
|
||||
),
|
||||
'system.theme.css' => array(
|
||||
'js.module.css' => array(
|
||||
'group' => -100,
|
||||
'type' => 'file',
|
||||
'weight' => 0.013,
|
||||
'media' => 'all',
|
||||
'preprocess' => TRUE,
|
||||
'data' => 'core/modules/system/system.theme.css',
|
||||
'data' => 'core/modules/system/js.module.css',
|
||||
'browsers' => array('IE' => TRUE, '!IE' => TRUE),
|
||||
'basename' => 'system.theme.css',
|
||||
'basename' => 'js.module.css',
|
||||
),
|
||||
'jquery.ui.core.css' => array(
|
||||
'group' => -100,
|
||||
|
@ -120,7 +114,7 @@ class CssCollectionGrouperUnitTest extends UnitTestCase {
|
|||
$this->assertSame($group['preprocess'], TRUE);
|
||||
$this->assertSame(count($group['items']), 3);
|
||||
$this->assertContains($css_assets['system.base.css'], $group['items']);
|
||||
$this->assertContains($css_assets['system.theme.css'], $group['items']);
|
||||
$this->assertContains($css_assets['js.module.css'], $group['items']);
|
||||
|
||||
// Check group 2.
|
||||
$group = $groups[1];
|
||||
|
|
|
@ -1,11 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Asset\CssCollectionRendererUnitTest.
|
||||
*/
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,11 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Asset\CssOptimizerUnitTest.
|
||||
*/
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Asset\JsOptimizerUnitTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Asset;
|
||||
|
||||
use Drupal\Core\Asset\JsOptimizer;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Asset\LibraryDependencyResolverTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Asset;
|
||||
|
||||
use Drupal\Core\Asset\LibraryDependencyResolver;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Asset\LibraryDiscoveryCollectorTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Asset;
|
||||
|
||||
use Drupal\Core\Asset\LibraryDiscoveryCollector;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Asset\LibraryDiscoveryTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Asset;
|
||||
|
||||
use Drupal\Core\Asset\LibraryDiscovery;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Batch\PercentagesTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Batch;
|
||||
|
||||
use Drupal\Core\Batch\Percentage;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Block\BlockBaseTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Block;
|
||||
|
||||
use Drupal\block_test\Plugin\Block\TestBlockInstantiation;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Breadcrumb\BreadcrumbManagerTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Breadcrumb;
|
||||
|
||||
use Drupal\Core\Breadcrumb\Breadcrumb;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Breadcrumb\BreadcrumbTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Breadcrumb;
|
||||
|
||||
use Drupal\Core\Breadcrumb\Breadcrumb;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Cache\BackendChainImplementationUnitTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Cache;
|
||||
|
||||
use Drupal\Core\Cache\BackendChain;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Cache\CacheCollectorHelper.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Cache;
|
||||
|
||||
use Drupal\Core\Cache\CacheCollector;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Cache\CacheCollectorTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Cache;
|
||||
|
||||
use Drupal\Core\Cache\Cache;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Cache\CacheFactoryTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Cache;
|
||||
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Cache\CacheTagsInvalidatorTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Cache;
|
||||
|
||||
use Drupal\Core\Cache\CacheTagsInvalidator;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Cache\CacheTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Cache;
|
||||
|
||||
use Drupal\Core\Cache\Cache;
|
||||
|
|
|
@ -1,17 +1,11 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Cache\CacheableMetadataTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Cache;
|
||||
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\Cache\CacheableMetadata;
|
||||
use Drupal\Tests\Core\Render\TestCacheableDependency;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\Core\Render\Element;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Cache\ChainedFastBackendTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Cache;
|
||||
|
||||
use Drupal\Core\Cache\ChainedFastBackend;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Cache\NullBackendTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Cache;
|
||||
|
||||
use Drupal\Core\Cache\NullBackend;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Common\AttributesTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Common;
|
||||
|
||||
use Drupal\Core\Template\Attribute;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Common\DiffArrayTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Common;
|
||||
|
||||
use Drupal\Component\Utility\DiffArray;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Common\TagsTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Common;
|
||||
|
||||
use Drupal\Component\Utility\Tags;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Config\CachedStorageTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Config;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Config\ConfigFactoryTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Config;
|
||||
|
||||
use Drupal\Core\Config\Config;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Config\ConfigTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Config;
|
||||
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Config\Entity\ConfigDependencyManagerTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Config\Entity;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Config\Entity\ConfigEntityDependencyTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Config\Entity;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Config\Entity\ConfigEntityStorageTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Config\Entity {
|
||||
|
||||
use Drupal\Core\Cache\Cache;
|
||||
|
@ -854,7 +849,8 @@ class ConfigEntityStorageTest extends UnitTestCase {
|
|||
* @covers ::doDelete
|
||||
*/
|
||||
public function testDelete() {
|
||||
// Dependencies are tested in \Drupal\config\Tests\ConfigDependencyTest.
|
||||
// Dependencies are tested in
|
||||
// \Drupal\Tests\config\Kernel\ConfigDependencyTest.
|
||||
$this->configManager->expects($this->any())
|
||||
->method('getConfigEntitiesToChangeOnDependencyRemoval')
|
||||
->willReturn(['update' => [], 'delete' => [], 'unchanged' => []]);
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Config\Entity\ConfigEntityTypeTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Config\Entity;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Config\Entity\EntityDisplayBaseTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Config\Entity;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Config\Entity\EntityDisplayModeBaseUnitTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Config\Entity;
|
||||
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Config\Entity\Fixtures\ConfigEntityBaseWithPluginCollections.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Config\Entity\Fixtures;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityBase;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Config\Entity\Query\QueryFactoryTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Config\Entity\Query;
|
||||
|
||||
use Drupal\Core\Config\Config;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Config\ImmutableConfigTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Config;
|
||||
|
||||
use Drupal\Core\Config\ImmutableConfig;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Config\StorageComparerTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Config;
|
||||
|
||||
use Drupal\Component\Uuid\Php;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Controller\ControllerBaseTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Controller;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Controller\TestController.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Controller;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
|
|
@ -12,6 +12,7 @@ use Drupal\Tests\UnitTestCase;
|
|||
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Route;
|
||||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Core\Controller\TitleResolver
|
||||
|
@ -55,13 +56,7 @@ class TitleResolverTest extends UnitTestCase {
|
|||
public function testStaticTitle() {
|
||||
$request = new Request();
|
||||
$route = new Route('/test-route', array('_title' => 'static title'));
|
||||
|
||||
$this->translationManager->expects($this->once())
|
||||
->method('translate')
|
||||
->with('static title', array(), array())
|
||||
->will($this->returnValue('translated title'));
|
||||
|
||||
$this->assertEquals('translated title', $this->titleResolver->getTitle($request, $route));
|
||||
$this->assertEquals(new TranslatableMarkup('static title', array(), array(), $this->translationManager), $this->titleResolver->getTitle($request, $route));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -72,13 +67,7 @@ class TitleResolverTest extends UnitTestCase {
|
|||
public function testStaticTitleWithContext() {
|
||||
$request = new Request();
|
||||
$route = new Route('/test-route', array('_title' => 'static title', '_title_context' => 'context'));
|
||||
|
||||
$this->translationManager->expects($this->once())
|
||||
->method('translate')
|
||||
->with('static title', array(), array('context' => 'context'))
|
||||
->will($this->returnValue('translated title with context'));
|
||||
|
||||
$this->assertEquals('translated title with context', $this->titleResolver->getTitle($request, $route));
|
||||
$this->assertEquals(new TranslatableMarkup('static title', array(), array('context' => 'context'), $this->translationManager), $this->titleResolver->getTitle($request, $route));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -94,20 +83,14 @@ class TitleResolverTest extends UnitTestCase {
|
|||
$request->attributes->set('_raw_variables', $raw_variables);
|
||||
|
||||
$route = new Route('/test-route', array('_title' => $title));
|
||||
|
||||
$this->translationManager->expects($this->once())
|
||||
->method('translate')
|
||||
->with($title, $this->logicalOr($this->arrayHasKey('@test'), $this->arrayHasKey('%test'), $this->arrayHasKey('!test')), array())
|
||||
->will($this->returnValue('static title value'));
|
||||
|
||||
$this->assertEquals($expected_title, $this->titleResolver->getTitle($request, $route));
|
||||
}
|
||||
|
||||
public function providerTestStaticTitleWithParameter() {
|
||||
$translation_manager = $this->getMock('\Drupal\Core\StringTranslation\TranslationInterface');
|
||||
return array(
|
||||
array('static title @test', 'static title value'),
|
||||
array('static title !test', 'static title value'),
|
||||
array('static title %test', 'static title value'),
|
||||
array('static title @test', new TranslatableMarkup('static title @test', ['@test' => 'value', '%test' => 'value', '@test2' => 'value2', '%test2' => 'value2'], array(), $translation_manager)),
|
||||
array('static title %test', new TranslatableMarkup('static title %test', ['@test' => 'value', '%test' => 'value', '@test2' => 'value2', '%test2' => 'value2'], array(), $translation_manager)),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Database\ConditionTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Database;
|
||||
|
||||
use Drupal\Core\Database\Connection;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Database\ConnectionTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Database;
|
||||
|
||||
use Drupal\Tests\Core\Database\Stub\StubConnection;
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Database\Driver\pgsql\PostgresqlConnectionTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Database\Driver\pgsql;
|
||||
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Database\Driver\pgsql\PostgresqlSchemaTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Database\Driver\pgsql;
|
||||
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Database\EmptyStatementTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Database;
|
||||
|
||||
use Drupal\Core\Database\StatementEmpty;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Database\OrderByTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Database;
|
||||
|
||||
use Drupal\Core\Database\Query\Select;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Database\Stub\Driver\Schema.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Database\Stub\Driver;
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Database\Stub\StubConnection.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Database\Stub;
|
||||
|
||||
use Drupal\Core\Database\Connection;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Database\Stub\StubPDO.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Database\Stub;
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Datetime\DateHelperTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Datetime;
|
||||
|
||||
use Drupal\Core\Datetime\DateHelper;
|
||||
|
|
|
@ -1,16 +1,13 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Datetime\DateTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Datetime;
|
||||
|
||||
use Drupal\Core\Datetime\DateFormatter;
|
||||
use Drupal\Core\Datetime\FormattedDateDiff;
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Core\Datetime\DateFormatter
|
||||
|
@ -96,11 +93,10 @@ class DateTest extends UnitTestCase {
|
|||
public function testFormatInterval($interval, $granularity, $expected, $langcode = NULL) {
|
||||
// Mocks a simple formatPlural implementation.
|
||||
$this->stringTranslation->expects($this->any())
|
||||
->method('formatPlural')
|
||||
->with($this->anything(), $this->anything(), $this->anything(), array(), array('langcode' => $langcode))
|
||||
->will($this->returnCallback(function($count, $one, $multiple) {
|
||||
return $count == 1 ? $one : str_replace('@count', $count, $multiple);
|
||||
}));
|
||||
->method('translateString')
|
||||
->willReturnCallback(function (TranslatableMarkup $arg) {
|
||||
return $arg->getUntranslatedString();
|
||||
});
|
||||
|
||||
// Check if the granularity is specified.
|
||||
if ($granularity) {
|
||||
|
@ -110,7 +106,7 @@ class DateTest extends UnitTestCase {
|
|||
$result = $this->dateFormatter->formatInterval($interval);
|
||||
}
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals(new TranslatableMarkup($expected, [], ['langcode' => $langcode], $this->stringTranslation), $result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -152,14 +148,8 @@ class DateTest extends UnitTestCase {
|
|||
* Tests the formatInterval method for 0 second.
|
||||
*/
|
||||
public function testFormatIntervalZeroSecond() {
|
||||
$this->stringTranslation->expects($this->once())
|
||||
->method('translate')
|
||||
->with('0 sec', array(), array('langcode' => 'xxx-lolspeak'))
|
||||
->will($this->returnValue('0 sec'));
|
||||
|
||||
$result = $this->dateFormatter->formatInterval(0, 1, 'xxx-lolspeak');
|
||||
|
||||
$this->assertEquals('0 sec', $result);
|
||||
$this->assertEquals(new TranslatableMarkup('0 sec', array(), array('langcode' => 'xxx-lolspeak'), $this->stringTranslation), $result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -194,11 +184,17 @@ class DateTest extends UnitTestCase {
|
|||
|
||||
// Mocks the formatDiff function of the dateformatter object.
|
||||
$this->dateFormatterStub
|
||||
->expects($this->any())
|
||||
->expects($this->at(0))
|
||||
->method('formatDiff')
|
||||
->with($timestamp, $request_time, $options)
|
||||
->will($this->returnValue($expected));
|
||||
|
||||
$this->dateFormatterStub
|
||||
->expects($this->at(1))
|
||||
->method('formatDiff')
|
||||
->with($timestamp, $request_time, $options + ['return_as_object' => TRUE])
|
||||
->will($this->returnValue(new FormattedDateDiff('1 second', 1)));
|
||||
|
||||
$request = Request::createFromGlobals();
|
||||
$request->server->set('REQUEST_TIME', $request_time);
|
||||
// Mocks a the request stack getting the current request.
|
||||
|
@ -207,6 +203,9 @@ class DateTest extends UnitTestCase {
|
|||
->willReturn($request);
|
||||
|
||||
$this->assertEquals($expected, $this->dateFormatterStub->formatTimeDiffSince($timestamp, $options));
|
||||
$options['return_as_object'] = TRUE;
|
||||
$expected_object = new FormattedDateDiff('1 second', 1);
|
||||
$this->assertEquals($expected_object, $this->dateFormatterStub->formatTimeDiffSince($timestamp, $options));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -222,11 +221,17 @@ class DateTest extends UnitTestCase {
|
|||
|
||||
// Mocks the formatDiff function of the dateformatter object.
|
||||
$this->dateFormatterStub
|
||||
->expects($this->any())
|
||||
->expects($this->at(0))
|
||||
->method('formatDiff')
|
||||
->with($request_time, $timestamp, $options)
|
||||
->will($this->returnValue($expected));
|
||||
|
||||
$this->dateFormatterStub
|
||||
->expects($this->at(1))
|
||||
->method('formatDiff')
|
||||
->with($request_time, $timestamp, $options + ['return_as_object' => TRUE])
|
||||
->will($this->returnValue(new FormattedDateDiff('1 second', 1)));
|
||||
|
||||
$request = Request::createFromGlobals();
|
||||
$request->server->set('REQUEST_TIME', $request_time);
|
||||
// Mocks a the request stack getting the current request.
|
||||
|
@ -235,6 +240,9 @@ class DateTest extends UnitTestCase {
|
|||
->willReturn($request);
|
||||
|
||||
$this->assertEquals($expected, $this->dateFormatterStub->formatTimeDiffUntil($timestamp, $options));
|
||||
$options['return_as_object'] = TRUE;
|
||||
$expected_object = new FormattedDateDiff('1 second', 1);
|
||||
$this->assertEquals($expected_object, $this->dateFormatterStub->formatTimeDiffUntil($timestamp, $options));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -244,25 +252,25 @@ class DateTest extends UnitTestCase {
|
|||
*
|
||||
* @covers ::formatDiff
|
||||
*/
|
||||
public function testformatDiff($expected, $timestamp1, $timestamp2, $options = array()) {
|
||||
|
||||
// Mocks a simple formatPlural implementation.
|
||||
public function testformatDiff($expected, $max_age, $timestamp1, $timestamp2, $options = array()) {
|
||||
// Mocks a simple translateString implementation.
|
||||
$this->stringTranslation->expects($this->any())
|
||||
->method('formatPlural')
|
||||
->with($this->anything(), $this->anything(), $this->anything(), array(), array('langcode' => isset($options['langcode']) ? $options['langcode'] : NULL))
|
||||
->will($this->returnCallback(function($count, $one, $multiple) {
|
||||
return $count == 1 ? $one : str_replace('@count', $count, $multiple);
|
||||
}));
|
||||
->method('translateString')
|
||||
->willReturnCallback(function (TranslatableMarkup $arg) {
|
||||
return $arg->getUntranslatedString();
|
||||
});
|
||||
|
||||
// Mocks a simple translate implementation.
|
||||
$this->stringTranslation->expects($this->any())
|
||||
->method('translate')
|
||||
->with($this->anything())
|
||||
->will($this->returnCallback(function($string, $args, $options) {
|
||||
return $string;
|
||||
}));
|
||||
if (isset($options['langcode'])) {
|
||||
$expected_markup = new TranslatableMarkup($expected, [], ['langcode' => $options['langcode']], $this->stringTranslation);
|
||||
}
|
||||
else {
|
||||
$expected_markup = new TranslatableMarkup($expected, [], [], $this->stringTranslation);
|
||||
}
|
||||
$this->assertEquals($expected_markup, $this->dateFormatter->formatDiff($timestamp1, $timestamp2, $options));
|
||||
|
||||
$this->assertEquals($expected, $this->dateFormatter->formatDiff($timestamp1, $timestamp2, $options));
|
||||
$options['return_as_object'] = TRUE;
|
||||
$expected_object = new FormattedDateDiff($expected, $max_age);
|
||||
$this->assertEquals($expected_object, $this->dateFormatter->formatDiff($timestamp1, $timestamp2, $options));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -282,103 +290,103 @@ class DateTest extends UnitTestCase {
|
|||
|
||||
$data = array(
|
||||
// Checks for equal timestamps.
|
||||
array('0 seconds', $request_time, $request_time),
|
||||
array('0 seconds', 0, $request_time, $request_time),
|
||||
|
||||
// Checks for seconds only.
|
||||
array('1 second', $this->createTimestamp('2013-12-11 10:09:07'), $request_time),
|
||||
array('1 second', $this->createTimestamp('2013-12-11 10:09:07'), $request_time),
|
||||
array('1 second', $this->createTimestamp('2013-12-11 10:09:07'), $request_time, $granularity_3 + $langcode_en),
|
||||
array('1 second', $this->createTimestamp('2013-12-11 10:09:07'), $request_time, $granularity_4 + $langcode_lolspeak),
|
||||
array('2 seconds', $this->createTimestamp('2013-12-11 10:09:06'), $request_time),
|
||||
array('59 seconds', $this->createTimestamp('2013-12-11 10:08:09'), $request_time),
|
||||
array('59 seconds', $this->createTimestamp('2013-12-11 10:08:09'), $request_time),
|
||||
array('1 second', 1, $this->createTimestamp('2013-12-11 10:09:07'), $request_time),
|
||||
array('1 second', 1, $this->createTimestamp('2013-12-11 10:09:07'), $request_time),
|
||||
array('1 second', 1, $this->createTimestamp('2013-12-11 10:09:07'), $request_time, $granularity_3 + $langcode_en),
|
||||
array('1 second', 1, $this->createTimestamp('2013-12-11 10:09:07'), $request_time, $granularity_4 + $langcode_lolspeak),
|
||||
array('2 seconds', 1, $this->createTimestamp('2013-12-11 10:09:06'), $request_time),
|
||||
array('59 seconds', 1, $this->createTimestamp('2013-12-11 10:08:09'), $request_time),
|
||||
array('59 seconds', 1, $this->createTimestamp('2013-12-11 10:08:09'), $request_time),
|
||||
|
||||
// Checks for minutes and possibly seconds.
|
||||
array('1 minute', $this->createTimestamp('2013-12-11 10:08:08'), $request_time),
|
||||
array('1 minute', $this->createTimestamp('2013-12-11 10:08:08'), $request_time),
|
||||
array('1 minute 1 second', $this->createTimestamp('2013-12-11 10:08:07'), $request_time),
|
||||
array('1 minute 59 seconds', $this->createTimestamp('2013-12-11 10:07:09'), $request_time),
|
||||
array('2 minutes', $this->createTimestamp('2013-12-11 10:07:08'), $request_time),
|
||||
array('2 minutes 1 second', $this->createTimestamp('2013-12-11 10:07:07'), $request_time),
|
||||
array('2 minutes 2 seconds', $this->createTimestamp('2013-12-11 10:07:06'), $request_time),
|
||||
array('2 minutes 2 seconds', $this->createTimestamp('2013-12-11 10:07:06'), $request_time, $granularity_3),
|
||||
array('2 minutes 2 seconds', $this->createTimestamp('2013-12-11 10:07:06'), $request_time, $granularity_4),
|
||||
array('30 minutes', $this->createTimestamp('2013-12-11 09:39:08'), $request_time),
|
||||
array('59 minutes 59 seconds', $this->createTimestamp('2013-12-11 09:09:09'), $request_time),
|
||||
array('59 minutes 59 seconds', $this->createTimestamp('2013-12-11 09:09:09'), $request_time),
|
||||
array('1 minute', 60, $this->createTimestamp('2013-12-11 10:08:08'), $request_time),
|
||||
array('1 minute', 60, $this->createTimestamp('2013-12-11 10:08:08'), $request_time),
|
||||
array('1 minute 1 second', 1, $this->createTimestamp('2013-12-11 10:08:07'), $request_time),
|
||||
array('1 minute 59 seconds', 1, $this->createTimestamp('2013-12-11 10:07:09'), $request_time),
|
||||
array('2 minutes', 60, $this->createTimestamp('2013-12-11 10:07:08'), $request_time),
|
||||
array('2 minutes 1 second', 1, $this->createTimestamp('2013-12-11 10:07:07'), $request_time),
|
||||
array('2 minutes 2 seconds', 1, $this->createTimestamp('2013-12-11 10:07:06'), $request_time),
|
||||
array('2 minutes 2 seconds', 1, $this->createTimestamp('2013-12-11 10:07:06'), $request_time, $granularity_3),
|
||||
array('2 minutes 2 seconds', 1, $this->createTimestamp('2013-12-11 10:07:06'), $request_time, $granularity_4),
|
||||
array('30 minutes', 60, $this->createTimestamp('2013-12-11 09:39:08'), $request_time),
|
||||
array('59 minutes 59 seconds', 1, $this->createTimestamp('2013-12-11 09:09:09'), $request_time),
|
||||
array('59 minutes 59 seconds', 1, $this->createTimestamp('2013-12-11 09:09:09'), $request_time),
|
||||
|
||||
// Checks for hours and possibly minutes or seconds.
|
||||
array('1 hour', $this->createTimestamp('2013-12-11 09:09:08'), $request_time),
|
||||
array('1 hour', $this->createTimestamp('2013-12-11 09:09:08'), $request_time),
|
||||
array('1 hour', $this->createTimestamp('2013-12-11 09:09:07'), $request_time),
|
||||
array('1 hour', $this->createTimestamp('2013-12-11 09:09:06'), $request_time),
|
||||
array('1 hour 1 minute', $this->createTimestamp('2013-12-11 09:08:08'), $request_time),
|
||||
array('1 hour 1 minute 1 second', $this->createTimestamp('2013-12-11 09:08:07'), $request_time, $granularity_3),
|
||||
array('1 hour 1 minute 2 seconds', $this->createTimestamp('2013-12-11 09:08:06'), $request_time, $granularity_4),
|
||||
array('1 hour 30 minutes', $this->createTimestamp('2013-12-11 08:39:08'), $request_time),
|
||||
array('2 hours', $this->createTimestamp('2013-12-11 08:09:08'), $request_time),
|
||||
array('23 hours 59 minutes', $this->createTimestamp('2013-12-10 10:10:08'), $request_time),
|
||||
array('1 hour', 3600, $this->createTimestamp('2013-12-11 09:09:08'), $request_time),
|
||||
array('1 hour', 3600, $this->createTimestamp('2013-12-11 09:09:08'), $request_time),
|
||||
array('1 hour', 3600, $this->createTimestamp('2013-12-11 09:09:07'), $request_time),
|
||||
array('1 hour', 3600, $this->createTimestamp('2013-12-11 09:09:06'), $request_time),
|
||||
array('1 hour 1 minute', 60, $this->createTimestamp('2013-12-11 09:08:08'), $request_time),
|
||||
array('1 hour 1 minute 1 second', 1, $this->createTimestamp('2013-12-11 09:08:07'), $request_time, $granularity_3),
|
||||
array('1 hour 1 minute 2 seconds', 1, $this->createTimestamp('2013-12-11 09:08:06'), $request_time, $granularity_4),
|
||||
array('1 hour 30 minutes', 60, $this->createTimestamp('2013-12-11 08:39:08'), $request_time),
|
||||
array('2 hours', 3600, $this->createTimestamp('2013-12-11 08:09:08'), $request_time),
|
||||
array('23 hours 59 minutes', 60, $this->createTimestamp('2013-12-10 10:10:08'), $request_time),
|
||||
|
||||
// Checks for days and possibly hours, minutes or seconds.
|
||||
array('1 day', $this->createTimestamp('2013-12-10 10:09:08'), $request_time),
|
||||
array('1 day', $this->createTimestamp('2013-12-10 10:09:07'), $request_time),
|
||||
array('1 day 1 hour', $this->createTimestamp('2013-12-10 09:09:08'), $request_time),
|
||||
array('1 day 1 hour 1 minute', $this->createTimestamp('2013-12-10 09:08:07'), $request_time, $granularity_3 + $langcode_en),
|
||||
array('1 day 1 hour 1 minute 1 second', $this->createTimestamp('2013-12-10 09:08:07'), $request_time, $granularity_4 + $langcode_lolspeak),
|
||||
array('1 day 2 hours 2 minutes 2 seconds', $this->createTimestamp('2013-12-10 08:07:06'), $request_time, $granularity_4),
|
||||
array('2 days', $this->createTimestamp('2013-12-09 10:09:08'), $request_time),
|
||||
array('2 days', $this->createTimestamp('2013-12-09 10:07:08'), $request_time),
|
||||
array('2 days 2 hours', $this->createTimestamp('2013-12-09 08:09:08'), $request_time),
|
||||
array('2 days 2 hours 2 minutes', $this->createTimestamp('2013-12-09 08:07:06'), $request_time, $granularity_3 + $langcode_en),
|
||||
array('2 days 2 hours 2 minutes 2 seconds', $this->createTimestamp('2013-12-09 08:07:06'), $request_time, $granularity_4 + $langcode_lolspeak),
|
||||
array('1 day', 86400, $this->createTimestamp('2013-12-10 10:09:08'), $request_time),
|
||||
array('1 day', 86400, $this->createTimestamp('2013-12-10 10:09:07'), $request_time),
|
||||
array('1 day 1 hour', 3600, $this->createTimestamp('2013-12-10 09:09:08'), $request_time),
|
||||
array('1 day 1 hour 1 minute', 60, $this->createTimestamp('2013-12-10 09:08:07'), $request_time, $granularity_3 + $langcode_en),
|
||||
array('1 day 1 hour 1 minute 1 second', 1, $this->createTimestamp('2013-12-10 09:08:07'), $request_time, $granularity_4 + $langcode_lolspeak),
|
||||
array('1 day 2 hours 2 minutes 2 seconds', 1, $this->createTimestamp('2013-12-10 08:07:06'), $request_time, $granularity_4),
|
||||
array('2 days', 86400, $this->createTimestamp('2013-12-09 10:09:08'), $request_time),
|
||||
array('2 days', 86400, $this->createTimestamp('2013-12-09 10:07:08'), $request_time),
|
||||
array('2 days 2 hours', 3600, $this->createTimestamp('2013-12-09 08:09:08'), $request_time),
|
||||
array('2 days 2 hours 2 minutes', 60, $this->createTimestamp('2013-12-09 08:07:06'), $request_time, $granularity_3 + $langcode_en),
|
||||
array('2 days 2 hours 2 minutes 2 seconds', 1, $this->createTimestamp('2013-12-09 08:07:06'), $request_time, $granularity_4 + $langcode_lolspeak),
|
||||
|
||||
// Checks for weeks and possibly days, hours, minutes or seconds.
|
||||
array('1 week', $this->createTimestamp('2013-12-04 10:09:08'), $request_time),
|
||||
array('1 week 1 day', $this->createTimestamp('2013-12-03 10:09:08'), $request_time),
|
||||
array('2 weeks', $this->createTimestamp('2013-11-27 10:09:08'), $request_time),
|
||||
array('2 weeks 2 days', $this->createTimestamp('2013-11-25 08:07:08'), $request_time),
|
||||
array('2 weeks 2 days 2 hours 2 minutes', $this->createTimestamp('2013-11-25 08:07:08'), $request_time, $granularity_4),
|
||||
array('4 weeks', $this->createTimestamp('2013-11-13 10:09:08'), $request_time),
|
||||
array('4 weeks 1 day', $this->createTimestamp('2013-11-12 10:09:08'), $request_time),
|
||||
array('1 week', 7 * 86400, $this->createTimestamp('2013-12-04 10:09:08'), $request_time),
|
||||
array('1 week 1 day', 86400, $this->createTimestamp('2013-12-03 10:09:08'), $request_time),
|
||||
array('2 weeks', 7 * 86400, $this->createTimestamp('2013-11-27 10:09:08'), $request_time),
|
||||
array('2 weeks 2 days', 86400, $this->createTimestamp('2013-11-25 08:07:08'), $request_time),
|
||||
array('2 weeks 2 days 2 hours 2 minutes', 60, $this->createTimestamp('2013-11-25 08:07:08'), $request_time, $granularity_4),
|
||||
array('4 weeks', 7 * 86400, $this->createTimestamp('2013-11-13 10:09:08'), $request_time),
|
||||
array('4 weeks 1 day', 86400, $this->createTimestamp('2013-11-12 10:09:08'), $request_time),
|
||||
|
||||
// Checks for months and possibly days, hours, minutes or seconds.
|
||||
array('1 month', $this->createTimestamp('2013-11-11 10:09:08'), $request_time),
|
||||
array('1 month', $this->createTimestamp('2013-11-11 10:09:07'), $request_time),
|
||||
array('1 month', $this->createTimestamp('2013-11-11 09:09:08'), $request_time),
|
||||
array('1 month', $this->createTimestamp('2013-11-11 09:08:07'), $request_time, $granularity_3),
|
||||
array('1 month', $this->createTimestamp('2013-11-11 09:08:07'), $request_time, $granularity_4),
|
||||
array('1 month 4 weeks', $this->createTimestamp('2013-10-13 10:09:08'), $request_time),
|
||||
array('1 month 4 weeks 1 day', $this->createTimestamp('2013-10-13 10:09:08'), $request_time, $granularity_3),
|
||||
array('1 month 4 weeks', $this->createTimestamp('2013-10-12 10:09:08'), $request_time),
|
||||
array('1 month 4 weeks 2 days', $this->createTimestamp('2013-10-12 10:09:08'), $request_time, $granularity_3),
|
||||
array('2 months', $this->createTimestamp('2013-10-11 10:09:08'), $request_time),
|
||||
array('2 months', $this->createTimestamp('2013-10-10 10:09:08'), $request_time),
|
||||
array('2 months', $this->createTimestamp('2013-10-09 08:07:06'), $request_time),
|
||||
array('2 months', $this->createTimestamp('2013-10-09 08:07:06'), $request_time, $granularity_3),
|
||||
array('2 months', $this->createTimestamp('2013-10-09 08:07:06'), $request_time, $granularity_4),
|
||||
array('6 months', $this->createTimestamp('2013-06-09 10:09:08'), $request_time),
|
||||
array('11 months', $this->createTimestamp('2013-01-11 07:09:08'), $request_time),
|
||||
array('11 months 4 weeks', $this->createTimestamp('2012-12-12 10:09:08'), $request_time),
|
||||
array('11 months 4 weeks 2 days', $this->createTimestamp('2012-12-12 10:09:08'), $request_time, $granularity_3),
|
||||
array('1 month', 30 * 86400, $this->createTimestamp('2013-11-11 10:09:08'), $request_time),
|
||||
array('1 month', 30 * 86400, $this->createTimestamp('2013-11-11 10:09:07'), $request_time),
|
||||
array('1 month', 30 * 86400, $this->createTimestamp('2013-11-11 09:09:08'), $request_time),
|
||||
array('1 month', 30 * 86400, $this->createTimestamp('2013-11-11 09:08:07'), $request_time, $granularity_3),
|
||||
array('1 month', 30 * 86400, $this->createTimestamp('2013-11-11 09:08:07'), $request_time, $granularity_4),
|
||||
array('1 month 4 weeks', 7 * 86400, $this->createTimestamp('2013-10-13 10:09:08'), $request_time),
|
||||
array('1 month 4 weeks 1 day', 86400, $this->createTimestamp('2013-10-13 10:09:08'), $request_time, $granularity_3),
|
||||
array('1 month 4 weeks', 7 * 86400, $this->createTimestamp('2013-10-12 10:09:08'), $request_time),
|
||||
array('1 month 4 weeks 2 days', 86400, $this->createTimestamp('2013-10-12 10:09:08'), $request_time, $granularity_3),
|
||||
array('2 months', 30 * 86400, $this->createTimestamp('2013-10-11 10:09:08'), $request_time),
|
||||
array('2 months', 30 * 86400, $this->createTimestamp('2013-10-10 10:09:08'), $request_time),
|
||||
array('2 months', 30 * 86400, $this->createTimestamp('2013-10-09 08:07:06'), $request_time),
|
||||
array('2 months', 30 * 86400, $this->createTimestamp('2013-10-09 08:07:06'), $request_time, $granularity_3),
|
||||
array('2 months', 30 * 86400, $this->createTimestamp('2013-10-09 08:07:06'), $request_time, $granularity_4),
|
||||
array('6 months', 30 * 86400, $this->createTimestamp('2013-06-09 10:09:08'), $request_time),
|
||||
array('11 months', 30 * 86400, $this->createTimestamp('2013-01-11 07:09:08'), $request_time),
|
||||
array('11 months 4 weeks', 7 * 86400, $this->createTimestamp('2012-12-12 10:09:08'), $request_time),
|
||||
array('11 months 4 weeks 2 days', 86400, $this->createTimestamp('2012-12-12 10:09:08'), $request_time, $granularity_3),
|
||||
|
||||
// Checks for years and possibly months, days, hours, minutes or seconds.
|
||||
array('1 year', $this->createTimestamp('2012-12-11 10:09:08'), $request_time),
|
||||
array('1 year', $this->createTimestamp('2012-12-11 10:08:08'), $request_time),
|
||||
array('1 year', $this->createTimestamp('2012-12-10 10:09:08'), $request_time),
|
||||
array('2 years', $this->createTimestamp('2011-12-11 10:09:08'), $request_time),
|
||||
array('2 years', $this->createTimestamp('2011-12-11 10:07:08'), $request_time),
|
||||
array('2 years', $this->createTimestamp('2011-12-09 10:09:08'), $request_time),
|
||||
array('2 years 2 months', $this->createTimestamp('2011-10-09 08:07:06'), $request_time, $granularity_3),
|
||||
array('2 years 2 months', $this->createTimestamp('2011-10-09 08:07:06'), $request_time, $granularity_4),
|
||||
array('10 years', $this->createTimestamp('2003-12-11 10:09:08'), $request_time),
|
||||
array('100 years', $this->createTimestamp('1913-12-11 10:09:08'), $request_time),
|
||||
array('1 year', 365 * 86400, $this->createTimestamp('2012-12-11 10:09:08'), $request_time),
|
||||
array('1 year', 365 * 86400, $this->createTimestamp('2012-12-11 10:08:08'), $request_time),
|
||||
array('1 year', 365 * 86400, $this->createTimestamp('2012-12-10 10:09:08'), $request_time),
|
||||
array('2 years', 365 * 86400, $this->createTimestamp('2011-12-11 10:09:08'), $request_time),
|
||||
array('2 years', 365 * 86400, $this->createTimestamp('2011-12-11 10:07:08'), $request_time),
|
||||
array('2 years', 365 * 86400, $this->createTimestamp('2011-12-09 10:09:08'), $request_time),
|
||||
array('2 years 2 months', 30 * 86400, $this->createTimestamp('2011-10-09 08:07:06'), $request_time, $granularity_3),
|
||||
array('2 years 2 months', 30 * 86400, $this->createTimestamp('2011-10-09 08:07:06'), $request_time, $granularity_4),
|
||||
array('10 years', 365 * 86400, $this->createTimestamp('2003-12-11 10:09:08'), $request_time),
|
||||
array('100 years', 365 * 86400, $this->createTimestamp('1913-12-11 10:09:08'), $request_time),
|
||||
|
||||
// Checks the non-strict option vs. strict (default).
|
||||
array('1 second', $this->createTimestamp('2013-12-11 10:09:08'), $this->createTimestamp('2013-12-11 10:09:07'), $non_strict),
|
||||
array('0 seconds', $this->createTimestamp('2013-12-11 10:09:08'), $this->createTimestamp('2013-12-11 10:09:07')),
|
||||
array('1 second', 1, $this->createTimestamp('2013-12-11 10:09:08'), $this->createTimestamp('2013-12-11 10:09:07'), $non_strict),
|
||||
array('0 seconds', 0, $this->createTimestamp('2013-12-11 10:09:08'), $this->createTimestamp('2013-12-11 10:09:07')),
|
||||
|
||||
// Checks granularity limit.
|
||||
array('2 years 3 months 1 week', $this->createTimestamp('2011-08-30 11:15:57'), $request_time, $granularity_3),
|
||||
array('2 years 3 months 1 week', 7 * 86400, $this->createTimestamp('2011-08-30 11:15:57'), $request_time, $granularity_3),
|
||||
);
|
||||
|
||||
return $data;
|
||||
|
|
|
@ -72,7 +72,8 @@ class BackendCompilerPassTest extends UnitTestCase {
|
|||
|
||||
// Configure a manual alias for the service, so ensure that it is not
|
||||
// overridden by the default backend.
|
||||
$container = clone $container;
|
||||
$container = $this->getMysqlContainer($service);
|
||||
$container->setParameter('default_backend', 'mysql');
|
||||
$container->setDefinition('mariadb.service', new Definition($prefix . 'MariaDb'));
|
||||
$container->setAlias('service', new Alias('mariadb.service'));
|
||||
$data[] = array($prefix . 'MariaDb', $container);
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\DependencyInjection\Compiler\ProxyServicesPassTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\DependencyInjection\Compiler;
|
||||
|
||||
use Drupal\Core\DependencyInjection\Compiler\ProxyServicesPass;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\DependencyInjection\Compiler\StackedKernelPassTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\DependencyInjection\Compiler;
|
||||
|
||||
use Drupal\Core\DependencyInjection\Compiler\StackedKernelPass;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\DependencyInjection\ContainerBuilderTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\DependencyInjection;
|
||||
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\DependencyInjection\ContainerTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\DependencyInjection;
|
||||
|
||||
use Drupal\Core\DependencyInjection\Container;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\DependencyInjection\Fixture\BarClass.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\DependencyInjection\Fixture;
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\DependencyInjection\Fixture\BazClass.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\DependencyInjection\Fixture;
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Display\DisplayVariantTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Display;
|
||||
|
||||
use Drupal\Core\Form\FormState;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\DrupalKernel\DiscoverServiceProvidersTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\DrupalKernel;
|
||||
|
||||
use Drupal\Core\DrupalKernel;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\DrupalKernel\DrupalKernelTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\DrupalKernel {
|
||||
|
||||
use Drupal\Core\DrupalKernel;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\DrupalKernel\ValidateHostnameTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\DrupalKernel;
|
||||
|
||||
use Drupal\Core\DrupalKernel;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\DrupalTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\Core\Enhancer;
|
||||
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Routing\Enhancer\EntityRevisionRouteEnhancer;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Core\Routing\Enhancer\EntityRevisionRouteEnhancer
|
||||
* @group Entity
|
||||
*/
|
||||
class EntityRevisionRouteEnhancerTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\entity\RouteEnhancer\EntityRevisionRouteEnhancer
|
||||
*/
|
||||
protected $routeEnhancer;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->routeEnhancer = new EntityRevisionRouteEnhancer();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::applies
|
||||
* @dataProvider providerTestApplies
|
||||
*/
|
||||
public function testApplies(Route $route, $expected) {
|
||||
$this->assertEquals($expected, $this->routeEnhancer->applies($route));
|
||||
}
|
||||
|
||||
public function providerTestApplies() {
|
||||
$data = [];
|
||||
$data['no-parameter'] = [new Route('/test-path'), FALSE];
|
||||
$data['none-revision-parameters'] = [new Route('/test-path/{entity_test}', [], [], ['parameters' => ['entity_test' => ['type' => 'entity:entity_test']]]), FALSE];
|
||||
$data['with-revision-parameter'] = [new Route('/test-path/{entity_test_revision}', [], [], ['parameters' => ['entity_test_revision' => ['type' => 'entity_revision:entity_test']]]), TRUE];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::enhance
|
||||
*/
|
||||
public function testEnhanceWithoutEntityRevision() {
|
||||
$route = new Route('/test-path/{entity_test}', [], [], ['parameters' => ['entity_test' => ['type' => 'entity:entity_test']]]);
|
||||
$request = Request::create('/test-path/123');
|
||||
$entity = $this->prophesize(EntityInterface::class);
|
||||
|
||||
$defaults = [];
|
||||
$defaults['entity_test'] = $entity->reveal();
|
||||
$defaults[RouteObjectInterface::ROUTE_OBJECT] = $route;
|
||||
$this->assertEquals($defaults, $this->routeEnhancer->enhance($defaults, $request));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::enhance
|
||||
*/
|
||||
public function testEnhanceWithEntityRevision() {
|
||||
$route = new Route('/test-path/{entity_test_revision}', [], [], ['parameters' => ['entity_test_revision' => ['type' => 'entity_revision:entity_test']]]);
|
||||
$request = Request::create('/test-path/123');
|
||||
$entity = $this->prophesize(EntityInterface::class);
|
||||
|
||||
$defaults = [];
|
||||
$defaults['entity_test_revision'] = $entity->reveal();
|
||||
$defaults[RouteObjectInterface::ROUTE_OBJECT] = $route;
|
||||
|
||||
$expected = $defaults;
|
||||
$expected['_entity_revision'] = $defaults['entity_test_revision'];
|
||||
$this->assertEquals($expected, $this->routeEnhancer->enhance($defaults, $request));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Enhancer\ParamConversionEnhancerTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Enhancer;
|
||||
|
||||
use Drupal\Core\Routing\Enhancer\ParamConversionEnhancer;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Entity\BaseFieldDefinitionTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Entity;
|
||||
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Entity\ContentEntityBaseUnitTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Entity;
|
||||
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Entity\Enhancer\EntityRouteEnhancerTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Entity\Enhancer;
|
||||
|
||||
use Drupal\Core\Entity\Enhancer\EntityRouteEnhancer;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Entity\EntityAccessCheckTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Entity;
|
||||
|
||||
use Drupal\Core\Cache\Context\CacheContextsManager;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Entity\EntityConstraintViolationListTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Entity;
|
||||
|
||||
use Drupal\Core\Entity\EntityConstraintViolationList;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Entity\EntityCreateAccessCheckTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Entity;
|
||||
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Entity\EntityFormBuilderTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Entity;
|
||||
|
||||
use Drupal\Core\Entity\EntityFormBuilder;
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Entity\EntityFormTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Entity;
|
||||
|
||||
use Drupal\Core\Entity\EntityForm;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Entity\EntityType;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Form\FormState;
|
||||
use Drupal\Core\Routing\RouteMatch;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Core\Entity\EntityForm
|
||||
|
@ -24,6 +25,13 @@ class EntityFormTest extends UnitTestCase {
|
|||
*/
|
||||
protected $entityForm;
|
||||
|
||||
/**
|
||||
* A fake entity type used in the test.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeInterface
|
||||
*/
|
||||
protected $entityType;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -31,6 +39,7 @@ class EntityFormTest extends UnitTestCase {
|
|||
parent::setUp();
|
||||
|
||||
$this->entityForm = new EntityForm();
|
||||
$this->entityType = new EntityType(['id' => 'entity_test']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -41,17 +50,13 @@ class EntityFormTest extends UnitTestCase {
|
|||
* @dataProvider providerTestFormIds
|
||||
*/
|
||||
public function testFormId($expected, $definition) {
|
||||
$entity_type = $this->getMock('Drupal\Core\Entity\EntityTypeInterface');
|
||||
$entity_type->expects($this->any())
|
||||
->method('hasKey')
|
||||
->with('bundle')
|
||||
->will($this->returnValue($definition['bundle']));
|
||||
$this->entityType->set('entity_keys', ['bundle' => $definition['bundle']]);
|
||||
|
||||
$entity = $this->getMockForAbstractClass('Drupal\Core\Entity\Entity', array(array(), $definition['entity_type']), '', TRUE, TRUE, TRUE, array('getEntityType', 'bundle'));
|
||||
|
||||
$entity->expects($this->any())
|
||||
->method('getEntityType')
|
||||
->will($this->returnValue($entity_type));
|
||||
->will($this->returnValue($this->entityType));
|
||||
$entity->expects($this->any())
|
||||
->method('bundle')
|
||||
->will($this->returnValue($definition['bundle']));
|
||||
|
@ -123,4 +128,115 @@ class EntityFormTest extends UnitTestCase {
|
|||
$this->assertNull($result->get('key_controlled_by_plugin_collection'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests EntityForm::getEntityFromRouteMatch() for edit and delete forms.
|
||||
*
|
||||
* @covers ::getEntityFromRouteMatch
|
||||
*/
|
||||
public function testGetEntityFromRouteMatchEditDelete() {
|
||||
$entity = $this->prophesize(EntityInterface::class)->reveal();
|
||||
$id = $this->entityType->id();
|
||||
$route_match = new RouteMatch(
|
||||
'test_route',
|
||||
new Route('/entity-test/manage/{' . $id . '}/edit'),
|
||||
[$id => $entity],
|
||||
[$id => 1]
|
||||
);
|
||||
$actual = $this->entityForm->getEntityFromRouteMatch($route_match, $id);
|
||||
$this->assertEquals($entity, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests EntityForm::getEntityFromRouteMatch() for add forms without a bundle.
|
||||
*
|
||||
* @covers ::getEntityFromRouteMatch
|
||||
*/
|
||||
public function testGetEntityFromRouteMatchAdd() {
|
||||
$entity = $this->prophesize(EntityInterface::class)->reveal();
|
||||
$this->setUpStorage()->create([])->willReturn($entity);
|
||||
$route_match = new RouteMatch('test_route', new Route('/entity-test/add'));
|
||||
$actual = $this->entityForm->getEntityFromRouteMatch($route_match, $this->entityType->id());
|
||||
$this->assertEquals($entity, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests EntityForm::getEntityFromRouteMatch() with a static bundle.
|
||||
*
|
||||
* @covers ::getEntityFromRouteMatch
|
||||
*/
|
||||
public function testGetEntityFromRouteMatchAddStatic() {
|
||||
$entity = $this->prophesize(EntityInterface::class)->reveal();
|
||||
$bundle_key = 'bundle';
|
||||
$bundle = 'test_bundle';
|
||||
$this->entityType->set('entity_keys', ['bundle' => $bundle_key]);
|
||||
$storage = $this->setUpStorage();
|
||||
|
||||
// Test without a bundle parameter in the route.
|
||||
$storage->create([])->willReturn($entity);
|
||||
$route_match = new RouteMatch('test_route', new Route('/entity-test/add'));
|
||||
$actual = $this->entityForm->getEntityFromRouteMatch($route_match, $this->entityType->id());
|
||||
$this->assertEquals($entity, $actual);
|
||||
|
||||
// Test with a static bundle parameter.
|
||||
$storage->create([$bundle_key => 'test_bundle'])->willReturn($entity);
|
||||
$route_match = new RouteMatch(
|
||||
'test_route',
|
||||
new Route('/entity-test/add/{' . $bundle_key . '}'),
|
||||
[$bundle_key => $bundle],
|
||||
[$bundle_key => $bundle]
|
||||
);
|
||||
$actual = $this->entityForm->getEntityFromRouteMatch($route_match, $this->entityType->id());
|
||||
$this->assertEquals($entity, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests EntityForm::getEntityFromRouteMatch() with a config entity bundle.
|
||||
*
|
||||
* @covers ::getEntityFromRouteMatch
|
||||
*/
|
||||
public function testGetEntityFromRouteMatchAddEntity() {
|
||||
$entity = $this->prophesize(EntityInterface::class)->reveal();
|
||||
$bundle_entity_type_id = 'entity_test_bundle';
|
||||
$bundle = 'test_entity_bundle';
|
||||
$this->entityType->set('bundle_entity_type', $bundle_entity_type_id);
|
||||
$storage = $this->setUpStorage();
|
||||
|
||||
// Test without a bundle parameter in the route.
|
||||
$storage->create([])->willReturn($entity);
|
||||
$route_match = new RouteMatch('test_route', new Route('/entity-test/add'));
|
||||
$actual = $this->entityForm->getEntityFromRouteMatch($route_match, $this->entityType->id());
|
||||
$this->assertEquals($entity, $actual);
|
||||
|
||||
// Test with an entity bundle parameter.
|
||||
$storage->create(['bundle' => $bundle])->willReturn($entity);
|
||||
$bundle_entity = $this->prophesize(EntityInterface::class);
|
||||
$bundle_entity->id()->willReturn('test_entity_bundle');
|
||||
$route_match = new RouteMatch(
|
||||
'test_route',
|
||||
new Route('/entity-test/add/{entity_test_bundle}'),
|
||||
[$bundle_entity_type_id => $bundle_entity->reveal()],
|
||||
[$bundle_entity_type_id => $bundle]
|
||||
);
|
||||
$actual = $this->entityForm->getEntityFromRouteMatch($route_match, $this->entityType->id());
|
||||
$this->assertEquals($entity, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the storage accessed via the entity type manager in the form.
|
||||
*
|
||||
* @return \Prophecy\Prophecy\ObjectProphecy
|
||||
* The storage prophecy.
|
||||
*/
|
||||
protected function setUpStorage() {
|
||||
$storage = $this->prophesize(EntityStorageInterface::class);
|
||||
|
||||
$entity_type_manager = $this->prophesize(EntityTypeManagerInterface::class);
|
||||
$entity_type_manager->getDefinition($this->entityType->id())->willReturn($this->entityType);
|
||||
$entity_type_manager->getStorage($this->entityType->id())->willReturn($storage->reveal());
|
||||
|
||||
$this->entityForm->setEntityTypeManager($entity_type_manager->reveal());
|
||||
|
||||
return $storage;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Entity\EntityLinkTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Entity;
|
||||
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Entity\EntityManagerTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Entity;
|
||||
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
|
@ -14,7 +9,6 @@ use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
|
|||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Entity\EntityTypeRepositoryInterface;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Prophecy\Argument;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Core\Entity\EntityManager
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Entity\EntityRepositoryTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Entity;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Entity\EntityTypeBundleInfoTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Entity;
|
||||
|
||||
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Entity\EntityTypeRepositoryTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Entity;
|
||||
|
||||
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
|
||||
|
|
|
@ -1,16 +1,10 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Entity\EntityTypeTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Entity;
|
||||
|
||||
use Drupal\Core\Entity\EntityType;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
use Drupal\Core\StringTranslation\TranslationInterface;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
|
@ -311,18 +305,70 @@ class EntityTypeTest extends UnitTestCase {
|
|||
$this->assertSame($default_label, $entity_type->getGroupLabel());
|
||||
|
||||
$default_label = new TranslatableMarkup('Other', array(), array('context' => 'Entity type group'));
|
||||
$entity_type = $this->setUpEntityType([]);
|
||||
|
||||
$string_translation = $this->getMock(TranslationInterface::class);
|
||||
$string_translation->expects($this->atLeastOnce())
|
||||
->method('translate')
|
||||
->with('Other', array(), array('context' => 'Entity type group'))
|
||||
->willReturn($default_label);
|
||||
$entity_type->setStringTranslation($string_translation);
|
||||
|
||||
$entity_type = $this->setUpEntityType(array('group_label' => $default_label));
|
||||
$this->assertSame($default_label, $entity_type->getGroupLabel());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getSingularLabel
|
||||
*/
|
||||
public function testGetSingularLabel() {
|
||||
$translatable_label = new TranslatableMarkup('entity test singular', [], [], $this->getStringTranslationStub());
|
||||
$entity_type = $this->setUpEntityType(['label_singular' => $translatable_label]);
|
||||
$entity_type->setStringTranslation($this->getStringTranslationStub());
|
||||
$this->assertEquals('entity test singular', $entity_type->getSingularLabel());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getSingularLabel
|
||||
*/
|
||||
public function testGetSingularLabelDefault() {
|
||||
$entity_type = $this->setUpEntityType(['label' => 'Entity test Singular']);
|
||||
$entity_type->setStringTranslation($this->getStringTranslationStub());
|
||||
$this->assertEquals('entity test singular', $entity_type->getSingularLabel());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getPluralLabel
|
||||
*/
|
||||
public function testGetPluralLabel() {
|
||||
$translatable_label = new TranslatableMarkup('entity test plural', [], [], $this->getStringTranslationStub());
|
||||
$entity_type = $this->setUpEntityType(['label_plural' => $translatable_label]);
|
||||
$entity_type->setStringTranslation($this->getStringTranslationStub());
|
||||
$this->assertEquals('entity test plural', $entity_type->getPluralLabel());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getPluralLabel
|
||||
*/
|
||||
public function testGetPluralLabelDefault() {
|
||||
$entity_type = $this->setUpEntityType(['label' => 'Entity test Plural']);
|
||||
$entity_type->setStringTranslation($this->getStringTranslationStub());
|
||||
$this->assertEquals('entity test plural entities', $entity_type->getPluralLabel());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getCountLabel
|
||||
*/
|
||||
public function testGetCountLabel() {
|
||||
$entity_type = $this->setUpEntityType(['label_count' => ['singular' => 'one entity test', 'plural' => '@count entity test']]);
|
||||
$entity_type->setStringTranslation($this->getStringTranslationStub());
|
||||
$this->assertEquals('one entity test', $entity_type->getCountLabel(1));
|
||||
$this->assertEquals('2 entity test', $entity_type->getCountLabel(2));
|
||||
$this->assertEquals('200 entity test', $entity_type->getCountLabel(200));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getCountLabel
|
||||
*/
|
||||
public function testGetCountLabelDefault() {
|
||||
$entity_type = $this->setUpEntityType(['label' => 'Entity test Plural']);
|
||||
$entity_type->setStringTranslation($this->getStringTranslationStub());
|
||||
$this->assertEquals('1 entity test plural', $entity_type->getCountLabel(1));
|
||||
$this->assertEquals('2 entity test plural entities', $entity_type->getCountLabel(2));
|
||||
$this->assertEquals('200 entity test plural entities', $entity_type->getCountLabel(200));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a mock controller class name.
|
||||
*
|
||||
|
|
|
@ -1,18 +1,11 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Entity\EntityUnitTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Entity;
|
||||
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\Core\Entity\Entity;
|
||||
use Drupal\Core\Language\Language;
|
||||
use Drupal\entity_test\Entity\EntityTestMul;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Entity\EntityUrlTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Entity;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityInterface;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Entity\KeyValueStore\KeyValueEntityStorageTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Entity\KeyValueStore {
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityInterface;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Entity\Query\Sql\QueryTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Entity\Query\Sql;
|
||||
|
||||
use Drupal\Core\Entity\EntityType;
|
||||
|
|
|
@ -7,13 +7,16 @@
|
|||
|
||||
namespace Drupal\Tests\Core\Entity\Routing;
|
||||
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Config\Entity\ConfigEntityTypeInterface;
|
||||
use Drupal\Core\Entity\EntityFieldManagerInterface;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
use Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider;
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Prophecy\Argument;
|
||||
use Prophecy\Prophecy\ObjectProphecy;
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
||||
/**
|
||||
|
@ -22,24 +25,247 @@ use Symfony\Component\Routing\Route;
|
|||
*/
|
||||
class DefaultHtmlRouteProviderTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* The entity type manager prophecy used in the test.
|
||||
*
|
||||
* @var \Prophecy\Prophecy\ProphecyInterface|\Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* The entity field manager prophecy used in the test.
|
||||
*
|
||||
* @var \Prophecy\Prophecy\ProphecyInterface|\Drupal\Core\Entity\EntityFieldManagerInterface
|
||||
*/
|
||||
protected $entityFieldManager;
|
||||
|
||||
/**
|
||||
* The HTML route provider used in the test.
|
||||
*
|
||||
* @var \Drupal\Tests\Core\Entity\Routing\TestDefaultHtmlRouteProvider
|
||||
*/
|
||||
protected $routeProvider;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->entityTypeManager = $this->prophesize(EntityTypeManagerInterface::class);
|
||||
$this->entityFieldManager = $this->prophesize(EntityFieldManagerInterface::class);
|
||||
|
||||
$this->routeProvider = new TestDefaultHtmlRouteProvider($this->entityTypeManager->reveal(), $this->entityFieldManager->reveal());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getAddPageRoute
|
||||
* @dataProvider providerTestGetAddPageRoute
|
||||
*/
|
||||
public function testGetAddPageRoute(Route $expected = NULL, EntityTypeInterface $entity_type) {
|
||||
$route = $this->routeProvider->getAddPageRoute($entity_type);
|
||||
$this->assertEquals($expected, $route);
|
||||
}
|
||||
|
||||
public function providerTestGetAddPageRoute() {
|
||||
$data = [];
|
||||
|
||||
$entity_type1 = $this->getEntityType();
|
||||
$entity_type1->hasLinkTemplate('add-page')->willReturn(FALSE);
|
||||
$data['no_add_page_link_template'] = [NULL, $entity_type1->reveal()];
|
||||
|
||||
$entity_type2 = $this->getEntityType();
|
||||
$entity_type2->hasLinkTemplate('add-page')->willReturn(TRUE);
|
||||
$entity_type2->getKey('bundle')->willReturn(NULL);
|
||||
$data['no_bundle'] = [NULL, $entity_type2->reveal()];
|
||||
|
||||
$entity_type3 = $this->getEntityType();
|
||||
$entity_type3->hasLinkTemplate('add-page')->willReturn(TRUE);
|
||||
$entity_type3->getLinkTemplate('add-page')->willReturn('/the/add/page/link/template');
|
||||
$entity_type3->id()->willReturn('the_entity_type_id');
|
||||
$entity_type3->getKey('bundle')->willReturn('type');
|
||||
$route = new Route('/the/add/page/link/template');
|
||||
$route->setDefaults([
|
||||
'_controller' => 'Drupal\Core\Entity\Controller\EntityController::addPage',
|
||||
'_title_callback' => 'Drupal\Core\Entity\Controller\EntityController::addTitle',
|
||||
'entity_type_id' => 'the_entity_type_id',
|
||||
]);
|
||||
$route->setRequirement('_entity_create_any_access', 'the_entity_type_id');
|
||||
$data['add_page'] = [clone $route, $entity_type3->reveal()];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getAddFormRoute
|
||||
* @dataProvider providerTestGetAddFormRoute
|
||||
*/
|
||||
public function testGetAddFormRoute(Route $expected = NULL, EntityTypeInterface $entity_type, EntityTypeInterface $bundle_entity_type = NULL, FieldStorageDefinitionInterface $field_storage_definition = NULL) {
|
||||
if ($bundle_entity_type) {
|
||||
$this->entityTypeManager->getDefinition('the_bundle_entity_type_id')->willReturn($bundle_entity_type);
|
||||
|
||||
if ($field_storage_definition) {
|
||||
$this->entityFieldManager->getFieldStorageDefinitions('the_bundle_entity_type_id')
|
||||
->willReturn(['id' => $field_storage_definition]);
|
||||
}
|
||||
}
|
||||
|
||||
$route = $this->routeProvider->getAddFormRoute($entity_type);
|
||||
$this->assertEquals($expected, $route);
|
||||
}
|
||||
|
||||
public function providerTestGetAddFormRoute() {
|
||||
$data = [];
|
||||
|
||||
$entity_type1 = $this->getEntityType();
|
||||
$entity_type1->hasLinkTemplate('add-form')->willReturn(FALSE);
|
||||
|
||||
$data['no_add_form_link_template'] = [NULL, $entity_type1->reveal()];
|
||||
|
||||
$entity_type2 = $this->getEntityType();
|
||||
$entity_type2->getBundleEntityType()->willReturn(NULL);
|
||||
$entity_type2->hasLinkTemplate('add-form')->willReturn(TRUE);
|
||||
$entity_type2->id()->willReturn('the_entity_type_id');
|
||||
$entity_type2->getLinkTemplate('add-form')->willReturn('/the/add/form/link/template');
|
||||
$entity_type2->getFormClass('add')->willReturn(NULL);
|
||||
$entity_type2->getKey('bundle')->willReturn(NULL);
|
||||
$route = (new Route('/the/add/form/link/template'))
|
||||
->setDefaults([
|
||||
'_entity_form' => 'the_entity_type_id.default',
|
||||
'entity_type_id' => 'the_entity_type_id',
|
||||
'_title_callback' => 'Drupal\Core\Entity\Controller\EntityController::addTitle',
|
||||
])
|
||||
->setRequirement('_entity_create_access', 'the_entity_type_id')
|
||||
;
|
||||
$data['no_add_form_no_bundle'] = [clone $route, $entity_type2->reveal()];
|
||||
|
||||
$entity_type3 = $this->getEntityType($entity_type2);
|
||||
$entity_type3->getFormClass('add')->willReturn('Drupal\Core\Entity\EntityForm');
|
||||
$route->setDefault('_entity_form', 'the_entity_type_id.add');
|
||||
$data['add_form_no_bundle'] = [clone $route, $entity_type3->reveal()];
|
||||
|
||||
$entity_type4 = $this->getEntityType($entity_type3);
|
||||
$entity_type4->getKey('bundle')->willReturn('the_bundle_key');
|
||||
$entity_type4->getBundleEntityType()->willReturn(NULL);
|
||||
$entity_type4->getLinkTemplate('add-form')->willReturn('/the/add/form/link/template/{the_bundle_key}');
|
||||
$route->setPath('/the/add/form/link/template/{the_bundle_key}');
|
||||
$route
|
||||
->setDefault('_title_callback', 'Drupal\Core\Entity\Controller\EntityController::addBundleTitle')
|
||||
->setDefault('bundle_parameter', 'the_bundle_key')
|
||||
->setRequirement('_entity_create_access', 'the_entity_type_id:{the_bundle_key}');
|
||||
$data['add_form_bundle_static'] = [clone $route, $entity_type4->reveal()];
|
||||
|
||||
$entity_type5 = $this->getEntityType($entity_type4);
|
||||
$entity_type5->getBundleEntityType()->willReturn('the_bundle_entity_type_id');
|
||||
$entity_type5->getLinkTemplate('add-form')->willReturn('/the/add/form/link/template/{the_bundle_entity_type_id}');
|
||||
$bundle_entity_type = $this->getEntityType();
|
||||
$bundle_entity_type->isSubclassOf(FieldableEntityInterface::class)->willReturn(FALSE);
|
||||
$route->setPath('/the/add/form/link/template/{the_bundle_entity_type_id}');
|
||||
$route
|
||||
->setDefault('bundle_parameter', 'the_bundle_entity_type_id')
|
||||
->setRequirement('_entity_create_access', 'the_entity_type_id:{the_bundle_entity_type_id}')
|
||||
->setOption('parameters', ['the_bundle_entity_type_id' => [
|
||||
'type' => 'entity:the_bundle_entity_type_id',
|
||||
]]);
|
||||
$data['add_form_bundle_entity_id_key_type_null'] = [clone $route, $entity_type5->reveal(), $bundle_entity_type->reveal()];
|
||||
|
||||
$entity_type6 = $this->getEntityType($entity_type5);
|
||||
$bundle_entity_type = $this->getEntityType();
|
||||
$bundle_entity_type->isSubclassOf(FieldableEntityInterface::class)->willReturn(TRUE);
|
||||
$field_storage_definition = $this->prophesize(FieldStorageDefinitionInterface::class);
|
||||
$field_storage_definition->getType()->willReturn('integer');
|
||||
$route->setRequirement('the_entity_type_id', '\d+');
|
||||
$data['add_form_bundle_entity_id_key_type_integer'] = [clone $route, $entity_type6->reveal(), $bundle_entity_type->reveal(), $field_storage_definition->reveal()];
|
||||
|
||||
$entity_type7 = $this->getEntityType($entity_type6);
|
||||
$bundle_entity_type = $this->prophesize(ConfigEntityTypeInterface::class);
|
||||
$bundle_entity_type->isSubclassOf(FieldableEntityInterface::class)->willReturn(FALSE);
|
||||
$field_storage_definition = $this->prophesize(FieldStorageDefinitionInterface::class);
|
||||
$route
|
||||
// Unset the 'the_entity_type_id' requirement.
|
||||
->setRequirements(['_entity_create_access' => $route->getRequirement('_entity_create_access')])
|
||||
->setOption('parameters', ['the_bundle_entity_type_id' => [
|
||||
'type' => 'entity:the_bundle_entity_type_id',
|
||||
'with_config_overrides' => TRUE,
|
||||
]]);
|
||||
$data['add_form_bundle_entity_id_key_type_integer'] = [clone $route, $entity_type7->reveal(), $bundle_entity_type->reveal(), $field_storage_definition->reveal()];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getCanonicalRoute
|
||||
* @dataProvider providerTestGetCanonicalRoute
|
||||
*/
|
||||
public function testGetCanonicalRoute(Route $expected = NULL, EntityTypeInterface $entity_type, FieldStorageDefinitionInterface $field_storage_definition = NULL) {
|
||||
if ($field_storage_definition) {
|
||||
$this->entityFieldManager->getFieldStorageDefinitions($entity_type->id())
|
||||
->willReturn([$entity_type->getKey('id') => $field_storage_definition]);
|
||||
}
|
||||
|
||||
$route = $this->routeProvider->getCanonicalRoute($entity_type);
|
||||
$this->assertEquals($expected, $route);
|
||||
}
|
||||
|
||||
public function providerTestGetCanonicalRoute() {
|
||||
$data = [];
|
||||
|
||||
$entity_type1 = $this->getEntityType();
|
||||
$entity_type1->hasLinkTemplate('canonical')->willReturn(FALSE);
|
||||
$data['no_canonical_link_template'] = [NULL, $entity_type1->reveal()];
|
||||
|
||||
$entity_type2 = $this->getEntityType();;
|
||||
$entity_type2->hasLinkTemplate('canonical')->willReturn(TRUE);
|
||||
$entity_type2->hasViewBuilderClass()->willReturn(FALSE);
|
||||
$data['no_view_builder'] = [NULL, $entity_type2->reveal()];
|
||||
|
||||
$entity_type3 = $this->getEntityType($entity_type2);
|
||||
$entity_type3->hasViewBuilderClass()->willReturn(TRUE);
|
||||
$entity_type3->id()->willReturn('the_entity_type_id');
|
||||
$entity_type3->getLinkTemplate('canonical')->willReturn('/the/canonical/link/template');
|
||||
$entity_type3->isSubclassOf(FieldableEntityInterface::class)->willReturn(FALSE);
|
||||
$route = (new Route('/the/canonical/link/template'))
|
||||
->setDefaults([
|
||||
'_entity_view' => 'the_entity_type_id.full',
|
||||
'_title_callback' => '\Drupal\Core\Entity\Controller\EntityController::title',
|
||||
])
|
||||
->setRequirements([
|
||||
'_entity_access' => 'the_entity_type_id.view',
|
||||
])
|
||||
->setOptions([
|
||||
'parameters' => [
|
||||
'the_entity_type_id' => [
|
||||
'type' => 'entity:the_entity_type_id',
|
||||
],
|
||||
],
|
||||
]);
|
||||
$data['id_key_type_null'] = [clone $route, $entity_type3->reveal()];
|
||||
|
||||
$entity_type4 = $this->getEntityType($entity_type3);
|
||||
$entity_type4->isSubclassOf(FieldableEntityInterface::class)->willReturn(TRUE);
|
||||
$entity_type4->getKey('id')->willReturn('id');
|
||||
$route->setRequirement('the_entity_type_id', '\d+');
|
||||
$field_storage_definition = $this->prophesize(FieldStorageDefinitionInterface::class);
|
||||
$field_storage_definition->getType()->willReturn('integer');
|
||||
$data['id_key_type_integer'] = [clone $route, $entity_type4->reveal(), $field_storage_definition->reveal()];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getEntityTypeIdKeyType
|
||||
*/
|
||||
public function testGetEntityTypeIdKeyType() {
|
||||
$entity_manager = $this->prophesize(EntityManagerInterface::class);
|
||||
$route_provider = new TestDefaultHtmlRouteProvider($entity_manager->reveal());
|
||||
|
||||
$entity_type = $this->prophesize(EntityTypeInterface::class);
|
||||
$entity_type->isSubclassOf(FieldableEntityInterface::class)->willReturn(TRUE);
|
||||
$entity_type_id = 'the_entity_type_id';
|
||||
$entity_type->id()->willReturn($entity_type_id);
|
||||
$entity_type->id()->willReturn('the_entity_type_id');
|
||||
$entity_type->getKey('id')->willReturn('id');
|
||||
|
||||
$field_storage_definition = $this->prophesize(FieldStorageDefinitionInterface::class);
|
||||
$field_storage_definition->getType()->willReturn('integer');
|
||||
$entity_manager->getFieldStorageDefinitions($entity_type_id)->willReturn(['id' => $field_storage_definition]);
|
||||
$this->entityFieldManager->getFieldStorageDefinitions('the_entity_type_id')->willReturn(['id' => $field_storage_definition]);
|
||||
|
||||
$type = $route_provider->getEntityTypeIdKeyType($entity_type->reveal());
|
||||
$type = $this->routeProvider->getEntityTypeIdKeyType($entity_type->reveal());
|
||||
$this->assertSame('integer', $type);
|
||||
}
|
||||
|
||||
|
@ -47,98 +273,28 @@ class DefaultHtmlRouteProviderTest extends UnitTestCase {
|
|||
* @covers ::getEntityTypeIdKeyType
|
||||
*/
|
||||
public function testGetEntityTypeIdKeyTypeNotFieldable() {
|
||||
$entity_manager = $this->prophesize(EntityManagerInterface::class);
|
||||
$route_provider = new TestDefaultHtmlRouteProvider($entity_manager->reveal());
|
||||
|
||||
$entity_type = $this->prophesize(EntityTypeInterface::class);
|
||||
$entity_type->isSubclassOf(FieldableEntityInterface::class)->willReturn(FALSE);
|
||||
$entity_manager->getFieldStorageDefinitions(Argument::any())->shouldNotBeCalled();
|
||||
$this->entityFieldManager->getFieldStorageDefinitions(Argument::any())->shouldNotBeCalled();
|
||||
|
||||
$type = $route_provider->getEntityTypeIdKeyType($entity_type->reveal());
|
||||
$type = $this->routeProvider->getEntityTypeIdKeyType($entity_type->reveal());
|
||||
$this->assertNull($type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getCanonicalRoute
|
||||
* @dataProvider providerTestGetCanonicalRoute
|
||||
* @param \Prophecy\Prophecy\ObjectProphecy $base_entity_type
|
||||
* @return \Prophecy\Prophecy\ObjectProphecy
|
||||
*/
|
||||
public function testGetCanonicalRoute($entity_type_prophecy, $expected, $field_storage_definition = NULL) {
|
||||
$entity_manager = $this->prophesize(EntityManagerInterface::class);
|
||||
$route_provider = new TestDefaultHtmlRouteProvider($entity_manager->reveal());
|
||||
$entity_type = $entity_type_prophecy->reveal();
|
||||
|
||||
if ($field_storage_definition) {
|
||||
$entity_manager->getFieldStorageDefinitions($entity_type->id())
|
||||
->willReturn([$entity_type->getKey('id') => $field_storage_definition]);
|
||||
protected function getEntityType(ObjectProphecy $base_entity_type = NULL) {
|
||||
$entity_type = $this->prophesize(EntityTypeInterface::class);
|
||||
if ($base_entity_type) {
|
||||
foreach ($base_entity_type->getMethodProphecies() as $method => $prophecies) {
|
||||
foreach ($prophecies as $prophecy) {
|
||||
$entity_type->addMethodProphecy(clone $prophecy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$route = $route_provider->getCanonicalRoute($entity_type);
|
||||
$this->assertEquals($expected, $route);
|
||||
}
|
||||
|
||||
public function providerTestGetCanonicalRoute() {
|
||||
$data = [];
|
||||
|
||||
$entity_type1 = $this->prophesize(EntityTypeInterface::class);
|
||||
$entity_type1->hasLinkTemplate('canonical')->willReturn(FALSE);
|
||||
$data['no_canonical_link_template'] = [$entity_type1, NULL];
|
||||
|
||||
$entity_type2 = $this->prophesize(EntityTypeInterface::class);
|
||||
$entity_type2->hasLinkTemplate('canonical')->willReturn(TRUE);
|
||||
$entity_type2->hasViewBuilderClass()->willReturn(FALSE);
|
||||
$data['no_view_builder'] = [$entity_type2, NULL];
|
||||
|
||||
$entity_type3 = $this->prophesize(EntityTypeInterface::class);
|
||||
$entity_type3->hasLinkTemplate('canonical')->willReturn(TRUE);
|
||||
$entity_type3->hasViewBuilderClass()->willReturn(TRUE);
|
||||
$entity_type3->id()->willReturn('the_entity_type_id');
|
||||
$entity_type3->getLinkTemplate('canonical')->willReturn('/the/canonical/link/template');
|
||||
$entity_type3->isSubclassOf(FieldableEntityInterface::class)->willReturn(FALSE);
|
||||
$route3 = (new Route('/the/canonical/link/template'))
|
||||
->setDefaults([
|
||||
'_entity_view' => 'the_entity_type_id.full',
|
||||
'_title_callback' => '\Drupal\Core\Entity\Controller\EntityController::title',
|
||||
])
|
||||
->setRequirements([
|
||||
'_entity_access' => 'the_entity_type_id.view',
|
||||
])
|
||||
->setOptions([
|
||||
'parameters' => [
|
||||
'the_entity_type_id' => [
|
||||
'type' => 'entity:the_entity_type_id',
|
||||
],
|
||||
],
|
||||
]);
|
||||
$data['id_key_type_null'] = [$entity_type3, $route3];
|
||||
|
||||
$entity_type4 = $this->prophesize(EntityTypeInterface::class);
|
||||
$entity_type4->hasLinkTemplate('canonical')->willReturn(TRUE);
|
||||
$entity_type4->hasViewBuilderClass()->willReturn(TRUE);
|
||||
$entity_type4->id()->willReturn('the_entity_type_id');
|
||||
$entity_type4->getLinkTemplate('canonical')->willReturn('/the/canonical/link/template');
|
||||
$entity_type4->isSubclassOf(FieldableEntityInterface::class)->willReturn(TRUE);
|
||||
$entity_type4->getKey('id')->willReturn('id');
|
||||
$route4 = (new Route('/the/canonical/link/template'))
|
||||
->setDefaults([
|
||||
'_entity_view' => 'the_entity_type_id.full',
|
||||
'_title_callback' => '\Drupal\Core\Entity\Controller\EntityController::title',
|
||||
])
|
||||
->setRequirements([
|
||||
'_entity_access' => 'the_entity_type_id.view',
|
||||
'the_entity_type_id' => '\d+',
|
||||
])
|
||||
->setOptions([
|
||||
'parameters' => [
|
||||
'the_entity_type_id' => [
|
||||
'type' => 'entity:the_entity_type_id',
|
||||
],
|
||||
],
|
||||
]);
|
||||
$field_storage_definition = $this->prophesize(FieldStorageDefinitionInterface::class);
|
||||
$field_storage_definition->getType()->willReturn('integer');
|
||||
$data['id_key_type_integer'] = [$entity_type4, $route4, $field_storage_definition];
|
||||
|
||||
return $data;
|
||||
return $entity_type;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -148,6 +304,12 @@ class TestDefaultHtmlRouteProvider extends DefaultHtmlRouteProvider {
|
|||
public function getEntityTypeIdKeyType(EntityTypeInterface $entity_type) {
|
||||
return parent::getEntityTypeIdKeyType($entity_type);
|
||||
}
|
||||
public function getAddPageRoute(EntityTypeInterface $entity_type) {
|
||||
return parent::getAddPageRoute($entity_type);
|
||||
}
|
||||
public function getAddFormRoute(EntityTypeInterface $entity_type) {
|
||||
return parent::getAddFormRoute($entity_type);
|
||||
}
|
||||
public function getCanonicalRoute(EntityTypeInterface $entity_type) {
|
||||
return parent::getCanonicalRoute($entity_type);
|
||||
}
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Entity\Sql\DefaultTableMappingTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Entity\Sql;
|
||||
|
||||
use Drupal\Core\Entity\Sql\DefaultTableMapping;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageSchemaTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Entity\Sql;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityType;
|
||||
|
|
|
@ -466,6 +466,42 @@ class SqlContentEntityStorageTest extends UnitTestCase {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests getTableMapping() with a base field that requires a dedicated table.
|
||||
*
|
||||
* @covers ::__construct
|
||||
* @covers ::getTableMapping
|
||||
*/
|
||||
public function testGetTableMappingSimpleWithDedicatedStorageFields() {
|
||||
$base_field_names = ['multi_valued_base_field'];
|
||||
|
||||
// Set up one entity key in order to have a base table.
|
||||
$this->fieldDefinitions = $this->mockFieldDefinitions(['test_id']);
|
||||
|
||||
// Set up the multi-valued base field.
|
||||
$this->fieldDefinitions += $this->mockFieldDefinitions($base_field_names, [
|
||||
'hasCustomStorage' => FALSE,
|
||||
'isMultiple' => TRUE,
|
||||
'getTargetEntityTypeId' => 'entity_test',
|
||||
]);
|
||||
|
||||
$this->setUpEntityStorage();
|
||||
|
||||
$mapping = $this->entityStorage->getTableMapping();
|
||||
$this->assertEquals(['entity_test', 'entity_test__multi_valued_base_field'], $mapping->getTableNames());
|
||||
$this->assertEquals($base_field_names, $mapping->getFieldNames('entity_test__multi_valued_base_field'));
|
||||
|
||||
$extra_columns = array(
|
||||
'bundle',
|
||||
'deleted',
|
||||
'entity_id',
|
||||
'revision_id',
|
||||
'langcode',
|
||||
'delta',
|
||||
);
|
||||
$this->assertEquals($extra_columns, $mapping->getExtraColumns('entity_test__multi_valued_base_field'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests getTableMapping() with a revisionable, non-translatable entity type.
|
||||
*
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Entity\TypedData\EntityAdapterUnitTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Entity\TypedData;
|
||||
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\EventSubscriber\ActiveLinkResponseFilterTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\EventSubscriber;
|
||||
|
||||
use Drupal\Component\Serialization\Json;
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\EventSubscriber\CustomPageExceptionHtmlSubscriberTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\EventSubscriber;
|
||||
|
||||
use Drupal\Component\Utility\UrlHelper;
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\Core\EventSubscriber\CustomPageExceptionHtmlSubscriber;
|
||||
use Drupal\Core\Render\HtmlResponse;
|
||||
use Drupal\Core\Routing\AccessAwareRouterInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
@ -35,13 +35,6 @@ class CustomPageExceptionHtmlSubscriberTest extends UnitTestCase {
|
|||
*/
|
||||
protected $configFactory;
|
||||
|
||||
/**
|
||||
* The mocked alias manager.
|
||||
*
|
||||
* @var \Drupal\Core\Path\AliasManagerInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $aliasManager;
|
||||
|
||||
/**
|
||||
* The mocked logger.
|
||||
*
|
||||
|
@ -70,22 +63,51 @@ class CustomPageExceptionHtmlSubscriberTest extends UnitTestCase {
|
|||
*/
|
||||
protected $redirectDestination;
|
||||
|
||||
/**
|
||||
* The mocked access unaware router.
|
||||
* @var \Symfony\Component\Routing\Matcher\UrlMatcherInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $accessUnawareRouter;
|
||||
|
||||
/**
|
||||
* The access manager.
|
||||
*
|
||||
* @var \Drupal\Core\Access\AccessManagerInterface
|
||||
*/
|
||||
protected $accessManager;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->configFactory = $this->getConfigFactoryStub(['system.site' => ['page.403' => 'access-denied-page', 'page.404' => 'not-found-page']]);
|
||||
$this->configFactory = $this->getConfigFactoryStub(['system.site' => ['page.403' => '/access-denied-page', 'page.404' => '/not-found-page']]);
|
||||
|
||||
$this->aliasManager = $this->getMock('Drupal\Core\Path\AliasManagerInterface');
|
||||
$this->kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
|
||||
$this->logger = $this->getMock('Psr\Log\LoggerInterface');
|
||||
$this->redirectDestination = $this->getMock('\Drupal\Core\Routing\RedirectDestinationInterface');
|
||||
|
||||
$this->redirectDestination->expects($this->any())
|
||||
->method('getAsArray')
|
||||
->willReturn(['destination' => 'test']);
|
||||
$this->accessUnawareRouter = $this->getMock('Symfony\Component\Routing\Matcher\UrlMatcherInterface');
|
||||
$this->accessUnawareRouter->expects($this->any())
|
||||
->method('match')
|
||||
->willReturn([
|
||||
'_controller' => 'mocked',
|
||||
]);
|
||||
$this->accessManager = $this->getMock('Drupal\Core\Access\AccessManagerInterface');
|
||||
$this->accessManager->expects($this->any())
|
||||
->method('checkNamedRoute')
|
||||
->willReturn(AccessResult::allowed()->addCacheTags(['foo', 'bar']));
|
||||
|
||||
$this->customPageSubscriber = new CustomPageExceptionHtmlSubscriber($this->configFactory, $this->aliasManager, $this->kernel, $this->logger, $this->redirectDestination);
|
||||
$this->customPageSubscriber = new CustomPageExceptionHtmlSubscriber($this->configFactory, $this->kernel, $this->logger, $this->redirectDestination, $this->accessUnawareRouter, $this->accessManager);
|
||||
|
||||
$path_validator = $this->getMock('Drupal\Core\Path\PathValidatorInterface');
|
||||
$path_validator->expects($this->any())
|
||||
->method('getUrlIfValidWithoutAccessCheck')
|
||||
->willReturn(Url::fromRoute('foo', ['foo' => 'bar']));
|
||||
$container = new ContainerBuilder();
|
||||
$container->set('path.validator', $path_validator);
|
||||
\Drupal::setContainer($container);
|
||||
|
||||
// You can't create an exception in PHP without throwing it. Store the
|
||||
// current error_log, and disable it temporarily.
|
||||
|
@ -99,25 +121,14 @@ class CustomPageExceptionHtmlSubscriberTest extends UnitTestCase {
|
|||
ini_set('error_log', $this->errorLog);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up an alias manager that does nothing.
|
||||
*/
|
||||
protected function setupStubAliasManager() {
|
||||
$this->aliasManager->expects($this->any())
|
||||
->method('getPathByAlias')
|
||||
->willReturnArgument(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests onHandleException with a POST request.
|
||||
*/
|
||||
public function testHandleWithPostRequest() {
|
||||
$this->setupStubAliasManager();
|
||||
|
||||
$request = Request::create('/test', 'POST', array('name' => 'druplicon', 'pass' => '12345'));
|
||||
|
||||
$this->kernel->expects($this->once())->method('handle')->will($this->returnCallback(function (Request $request) {
|
||||
return new Response($request->getMethod());
|
||||
return new HtmlResponse($request->getMethod());
|
||||
}));
|
||||
|
||||
$event = new GetResponseForExceptionEvent($this->kernel, $request, 'foo', new NotFoundHttpException('foo'));
|
||||
|
@ -127,15 +138,15 @@ class CustomPageExceptionHtmlSubscriberTest extends UnitTestCase {
|
|||
$response = $event->getResponse();
|
||||
$result = $response->getContent() . " " . UrlHelper::buildQuery($request->request->all());
|
||||
$this->assertEquals('POST name=druplicon&pass=12345', $result);
|
||||
$this->assertEquals(AccessResult::allowed()->addCacheTags(['foo', 'bar']), $request->attributes->get(AccessAwareRouterInterface::ACCESS_RESULT));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests onHandleException with a GET request.
|
||||
*/
|
||||
public function testHandleWithGetRequest() {
|
||||
$this->setupStubAliasManager();
|
||||
|
||||
$request = Request::create('/test', 'GET', array('name' => 'druplicon', 'pass' => '12345'));
|
||||
$request->attributes->set(AccessAwareRouterInterface::ACCESS_RESULT, AccessResult::forbidden()->addCacheTags(['druplicon']));
|
||||
|
||||
$this->kernel->expects($this->once())->method('handle')->will($this->returnCallback(function (Request $request) {
|
||||
return new Response($request->getMethod() . ' ' . UrlHelper::buildQuery($request->query->all()));
|
||||
|
@ -147,6 +158,7 @@ class CustomPageExceptionHtmlSubscriberTest extends UnitTestCase {
|
|||
$response = $event->getResponse();
|
||||
$result = $response->getContent() . " " . UrlHelper::buildQuery($request->request->all());
|
||||
$this->assertEquals('GET name=druplicon&pass=12345&destination=test&_exception_statuscode=404 ', $result);
|
||||
$this->assertEquals(AccessResult::forbidden()->addCacheTags(['druplicon', 'foo', 'bar']), $request->attributes->get(AccessAwareRouterInterface::ACCESS_RESULT));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\Core\EventSubscriber;
|
||||
|
||||
use Drupal\Core\EventSubscriber\DefaultExceptionSubscriber;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
|
||||
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Core\EventSubscriber\DefaultExceptionSubscriber
|
||||
* @group EventSubscriber
|
||||
*/
|
||||
class DefaultExceptionSubscriberTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @covers ::onException
|
||||
* @covers ::onFormatUnknown
|
||||
*/
|
||||
public function testOnExceptionWithUnknownFormat() {
|
||||
$config_factory = $this->getConfigFactoryStub();
|
||||
|
||||
// Format 'bananas' requested, yet only 'json' allowed.
|
||||
$kernel = $this->prophesize(HttpKernelInterface::class);
|
||||
$request = Request::create('/test?_format=bananas');
|
||||
$e = new MethodNotAllowedHttpException(['json'], 'test message');
|
||||
$event = new GetResponseForExceptionEvent($kernel->reveal(), $request, 'GET', $e);
|
||||
$subscriber = new DefaultExceptionSubscriber($config_factory);
|
||||
$subscriber->onException($event);
|
||||
$response = $event->getResponse();
|
||||
|
||||
$this->assertInstanceOf(Response::class, $response);
|
||||
$this->assertEquals('test message', $response->getContent());
|
||||
$this->assertEquals(405, $response->getStatusCode());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\EventSubscriber\ModuleRouteSubscriberTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\EventSubscriber;
|
||||
|
||||
use Drupal\Core\Routing\RouteBuildEvent;
|
||||
|
|
|
@ -0,0 +1,109 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\Core\EventSubscriber;
|
||||
|
||||
use Drupal\Core\EventSubscriber\OptionsRequestSubscriber;
|
||||
use Symfony\Cmf\Component\Routing\RouteProviderInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\Routing\Route;
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\Core\EventSubscriber\OptionsRequestSubscriber
|
||||
* @group EventSubscriber
|
||||
*/
|
||||
class OptionsRequestSubscriberTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
/**
|
||||
* @covers ::onRequest
|
||||
*/
|
||||
public function testWithNonOptionRequest() {
|
||||
$kernel = $this->prophesize(HttpKernelInterface::class);
|
||||
$request = Request::create('/example', 'GET');
|
||||
|
||||
$route_provider = $this->prophesize(RouteProviderInterface::class);
|
||||
$route_provider->getRouteCollectionForRequest($request)->shouldNotBeCalled();
|
||||
|
||||
$subscriber = new OptionsRequestSubscriber($route_provider->reveal());
|
||||
$event = new GetResponseEvent($kernel->reveal(), $request, HttpKernelInterface::MASTER_REQUEST);
|
||||
$subscriber->onRequest($event);
|
||||
|
||||
$this->assertFalse($event->hasResponse());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::onRequest
|
||||
*/
|
||||
public function testWithoutMatchingRoutes() {
|
||||
$kernel = $this->prophesize(HttpKernelInterface::class);
|
||||
$request = Request::create('/example', 'OPTIONS');
|
||||
|
||||
$route_provider = $this->prophesize(RouteProviderInterface::class);
|
||||
$route_provider->getRouteCollectionForRequest($request)->willReturn(new RouteCollection())->shouldBeCalled();
|
||||
|
||||
$subscriber = new OptionsRequestSubscriber($route_provider->reveal());
|
||||
$event = new GetResponseEvent($kernel->reveal(), $request, HttpKernelInterface::MASTER_REQUEST);
|
||||
$subscriber->onRequest($event);
|
||||
|
||||
$this->assertFalse($event->hasResponse());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::onRequest
|
||||
* @dataProvider providerTestOnRequestWithOptionsRequest
|
||||
*/
|
||||
public function testWithOptionsRequest(RouteCollection $collection, $expected_header) {
|
||||
$kernel = $this->prophesize(HttpKernelInterface::class);
|
||||
$request = Request::create('/example', 'OPTIONS');
|
||||
|
||||
$route_provider = $this->prophesize(RouteProviderInterface::class);
|
||||
$route_provider->getRouteCollectionForRequest($request)->willReturn($collection)->shouldBeCalled();
|
||||
|
||||
$subscriber = new OptionsRequestSubscriber($route_provider->reveal());
|
||||
$event = new GetResponseEvent($kernel->reveal(), $request, HttpKernelInterface::MASTER_REQUEST);
|
||||
$subscriber->onRequest($event);
|
||||
|
||||
$this->assertTrue($event->hasResponse());
|
||||
$response = $event->getResponse();
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$this->assertEquals($expected_header, $response->headers->get('Allow'));
|
||||
}
|
||||
|
||||
public function providerTestOnRequestWithOptionsRequest() {
|
||||
$data = [];
|
||||
|
||||
foreach (['GET', 'POST', 'PATCH', 'PUT', 'DELETE'] as $method) {
|
||||
$collection = new RouteCollection();
|
||||
$collection->add('example.1', new Route('/example', [], [], [], '', [], [$method]));
|
||||
$data['one_route_' . $method] = [$collection, $method];
|
||||
}
|
||||
|
||||
foreach (['GET', 'POST', 'PATCH', 'PUT', 'DELETE'] as $method_a) {
|
||||
foreach (['GET', 'POST', 'PATCH', 'PUT', 'DELETE'] as $method_b) {
|
||||
if ($method_a != $method_b) {
|
||||
$collection = new RouteCollection();
|
||||
$collection->add('example.1', new Route('/example', [], [], [], '', [], [$method_a, $method_b]));
|
||||
$data['one_route_' . $method_a . '_' . $method_b] = [$collection, $method_a . ', ' . $method_b];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (['GET', 'POST', 'PATCH', 'PUT', 'DELETE'] as $method_a) {
|
||||
foreach (['GET', 'POST', 'PATCH', 'PUT', 'DELETE'] as $method_b) {
|
||||
foreach (['GET', 'POST', 'PATCH', 'PUT', 'DELETE'] as $method_c) {
|
||||
$collection = new RouteCollection();
|
||||
$collection->add('example.1', new Route('/example', [], [], [], '', [], [$method_a]));
|
||||
$collection->add('example.2', new Route('/example', [], [], [], '', [], [$method_a, $method_b]));
|
||||
$collection->add('example.3', new Route('/example', [], [], [], '', [], [$method_b, $method_c]));
|
||||
$methods = array_unique([$method_a, $method_b, $method_c]);
|
||||
$data['multiple_routes_' . $method_a . '_' . $method_b . '_' . $method_c] = [$collection, implode(', ', $methods)];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Reference in a new issue