Drupal 8.0.0 beta 12. More info: https://www.drupal.org/node/2514176
This commit is contained in:
commit
9921556621
13277 changed files with 1459781 additions and 0 deletions
38
core/modules/language/tests/src/ConfigurableLanguageTest.php
Normal file
38
core/modules/language/tests/src/ConfigurableLanguageTest.php
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\language\ConfigurableLanguageTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\language;
|
||||
|
||||
use Drupal\simpletest\KernelTestBase;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
|
||||
/**
|
||||
* Tests the ConfigurableLanguage entity.
|
||||
*
|
||||
* @group language
|
||||
* @see \Drupal\language\Entity\ConfigurableLanguage.
|
||||
*/
|
||||
class ConfigurableLanguageTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('language');
|
||||
|
||||
/**
|
||||
* Tests configurable language name methods.
|
||||
*/
|
||||
public function testName() {
|
||||
$name = $this->randomMachineName();
|
||||
$language_code = $this->randomMachineName(2);
|
||||
$configurableLanguage = new ConfigurableLanguage(array('label' => $name, 'id' => $language_code), 'configurable_language');
|
||||
$this->assertEqual($configurableLanguage->getName(), $name);
|
||||
$this->assertEqual($configurableLanguage->setName('Test language')->getName(), 'Test language');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\language\Unit\Config\LanguageConfigOverrideTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\language\Unit\Config;
|
||||
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\language\Config\LanguageConfigOverride;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\language\Config\LanguageConfigOverride
|
||||
* @group Config
|
||||
* @group language
|
||||
*/
|
||||
class LanguageConfigOverrideTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* Language configuration override.
|
||||
*
|
||||
* @var \Drupal\language\Config\LanguageConfigOverride
|
||||
*/
|
||||
protected $configTranslation;
|
||||
|
||||
/**
|
||||
* Storage.
|
||||
*
|
||||
* @var \Drupal\Core\Config\StorageInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $storage;
|
||||
|
||||
/**
|
||||
* Event Dispatcher.
|
||||
*
|
||||
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $eventDispatcher;
|
||||
|
||||
/**
|
||||
* Typed Config.
|
||||
*
|
||||
* @var \Drupal\Core\Config\TypedConfigManagerInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $typedConfig;
|
||||
|
||||
/**
|
||||
* The mocked cache tags invalidator.
|
||||
*
|
||||
* @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $cacheTagsInvalidator;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setUp() {
|
||||
$this->storage = $this->getMock('Drupal\Core\Config\StorageInterface');
|
||||
$this->eventDispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
|
||||
$this->typedConfig = $this->getMock('\Drupal\Core\Config\TypedConfigManagerInterface');
|
||||
$this->configTranslation = new LanguageConfigOverride('config.test', $this->storage, $this->typedConfig, $this->eventDispatcher);
|
||||
$this->cacheTagsInvalidator = $this->getMock('Drupal\Core\Cache\CacheTagsInvalidatorInterface');
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
$container->set('cache_tags.invalidator', $this->cacheTagsInvalidator);
|
||||
\Drupal::setContainer($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::save
|
||||
*/
|
||||
public function testSaveNew() {
|
||||
$this->cacheTagsInvalidator->expects($this->once())
|
||||
->method('invalidateTags')
|
||||
->with(['config:config.test']);
|
||||
$this->assertTrue($this->configTranslation->isNew());
|
||||
$this->configTranslation->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::save
|
||||
*/
|
||||
public function testSaveExisting() {
|
||||
$this->cacheTagsInvalidator->expects($this->once())
|
||||
->method('invalidateTags')
|
||||
->with(['config:config.test']);
|
||||
$this->configTranslation->initWithData([]);
|
||||
$this->configTranslation->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::delete
|
||||
*/
|
||||
public function testDelete() {
|
||||
$this->cacheTagsInvalidator->expects($this->once())
|
||||
->method('invalidateTags')
|
||||
->with(['config:config.test']);
|
||||
$this->configTranslation->initWithData([]);
|
||||
$this->configTranslation->delete();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\language\Unit\ConfigurableLanguageUnitTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\language\Unit;
|
||||
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\Core\Entity\EntityType;
|
||||
use Drupal\Core\Language\Language;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* Tests the ConfigurableLanguage entity class.
|
||||
*
|
||||
* @group language
|
||||
* @coversDefaultClass \Drupal\language\Entity\ConfigurableLanguage
|
||||
* @see \Drupal\language\Entity\ConfigurableLanguage.
|
||||
*/
|
||||
class ConfigurableLanguageUnitTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @covers ::getDirection
|
||||
*/
|
||||
public function testDirection() {
|
||||
// Direction of language writing, an integer. Usually either
|
||||
// ConfigurableLanguage::DIRECTION_LTR or
|
||||
// ConfigurableLanguage::DIRECTION_RTL.
|
||||
$configurableLanguage = new ConfigurableLanguage(array('direction' => ConfigurableLanguage::DIRECTION_LTR), 'configurable_language');
|
||||
$this->assertEquals(ConfigurableLanguage::DIRECTION_LTR, $configurableLanguage->getDirection());
|
||||
|
||||
// Test direction again, setting direction to RTL.
|
||||
$configurableLanguage = new ConfigurableLanguage(array('direction' => ConfigurableLanguage::DIRECTION_RTL), 'configurable_language');
|
||||
$this->assertEquals(ConfigurableLanguage::DIRECTION_RTL, $configurableLanguage->getDirection());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getWeight
|
||||
* @covers ::setWeight
|
||||
*/
|
||||
public function testWeight() {
|
||||
// The weight, an integer. Used to order languages with larger positive
|
||||
// weights sinking items toward the bottom of lists.
|
||||
$configurableLanguage = new ConfigurableLanguage(array('weight' => -5), 'configurable_language');
|
||||
$this->assertEquals($configurableLanguage->getWeight(), -5);
|
||||
$this->assertEquals($configurableLanguage->setWeight(13)->getWeight(), 13);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,321 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\language\Unit\ContentLanguageSettingsUnitTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\language\Unit;
|
||||
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\language\Entity\ContentLanguageSettings;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\language\Entity\ContentLanguageSettings
|
||||
* @group language
|
||||
*/
|
||||
class ContentLanguageSettingsUnitTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* The entity type used for testing.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $entityType;
|
||||
|
||||
/**
|
||||
* The entity manager used for testing.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $entityManager;
|
||||
|
||||
/**
|
||||
* The ID of the type of the entity under test.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $entityTypeId;
|
||||
|
||||
/**
|
||||
* The UUID generator used for testing.
|
||||
*
|
||||
* @var \Drupal\Component\Uuid\UuidInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $uuid;
|
||||
|
||||
/**
|
||||
* The typed configuration manager used for testing.
|
||||
*
|
||||
* @var \Drupal\Core\Config\TypedConfigManagerInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $typedConfigManager;
|
||||
|
||||
/**
|
||||
* The typed configuration manager used for testing.
|
||||
*
|
||||
* @var \Drupal\Core\Config\Entity\ConfigEntityStorage|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $configEntityStorageInterface;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->entityTypeId = $this->randomMachineName();
|
||||
$this->entityType = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface');
|
||||
|
||||
$this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface');
|
||||
|
||||
$this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface');
|
||||
|
||||
$this->typedConfigManager = $this->getMock('Drupal\Core\Config\TypedConfigManagerInterface');
|
||||
|
||||
$this->configEntityStorageInterface = $this->getMock('Drupal\Core\Entity\EntityStorageInterface');
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
$container->set('entity.manager', $this->entityManager);
|
||||
$container->set('uuid', $this->uuid);
|
||||
$container->set('config.typed', $this->typedConfigManager);
|
||||
$container->set('config.storage', $this->configEntityStorageInterface);
|
||||
\Drupal::setContainer($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::calculateDependencies
|
||||
*/
|
||||
public function testCalculateDependencies() {
|
||||
// Mock the interfaces necessary to create a dependency on a bundle entity.
|
||||
$bundle_entity = $this->getMock('Drupal\Core\Config\Entity\ConfigEntityInterface');
|
||||
$bundle_entity->expects($this->any())
|
||||
->method('getConfigDependencyName')
|
||||
->will($this->returnValue('test.test_entity_type.id'));
|
||||
|
||||
$storage = $this->getMock('\Drupal\Core\Config\Entity\ConfigEntityStorageInterface');
|
||||
$storage->expects($this->any())
|
||||
->method('load')
|
||||
->with('test_bundle')
|
||||
->will($this->returnValue($bundle_entity));
|
||||
|
||||
$this->entityManager->expects($this->any())
|
||||
->method('getStorage')
|
||||
->with('bundle_entity_type')
|
||||
->will($this->returnValue($storage));
|
||||
|
||||
$target_entity_type = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface');
|
||||
$target_entity_type->expects($this->any())
|
||||
->method('getBundleEntityType')
|
||||
->will($this->returnValue('bundle_entity_type'));
|
||||
|
||||
$this->entityManager->expects($this->any())
|
||||
->method('getDefinition')
|
||||
->with('test_entity_type')
|
||||
->will($this->returnValue($target_entity_type));
|
||||
|
||||
$config = new ContentLanguageSettings(array(
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_bundle',
|
||||
), 'language_content_settings');
|
||||
$dependencies = $config->calculateDependencies();
|
||||
$this->assertContains('test.test_entity_type.id', $dependencies['config']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::id
|
||||
*/
|
||||
public function testId() {
|
||||
$config = new ContentLanguageSettings(array(
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_bundle',
|
||||
), 'language_content_settings');
|
||||
$this->assertSame('test_entity_type.test_bundle', $config->id());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getTargetEntityTypeId
|
||||
*/
|
||||
public function testTargetEntityTypeId() {
|
||||
$config = new ContentLanguageSettings(array(
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_bundle',
|
||||
), 'language_content_settings');
|
||||
$this->assertSame('test_entity_type', $config->getTargetEntityTypeId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getTargetBundle
|
||||
*/
|
||||
public function testTargetBundle() {
|
||||
$config = new ContentLanguageSettings(array(
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_bundle',
|
||||
), 'language_content_settings');
|
||||
$this->assertSame('test_bundle', $config->getTargetBundle());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getDefaultLangcode
|
||||
* @covers ::setDefaultLangcode
|
||||
*
|
||||
* @dataProvider providerDefaultLangcode
|
||||
*/
|
||||
public function testDefaultLangcode(ContentLanguageSettings $config, $expected) {
|
||||
$this->assertSame($expected, $config->getDefaultLangcode());
|
||||
}
|
||||
|
||||
public function providerDefaultLangcode() {
|
||||
$langcode = $this->randomMachineName();
|
||||
$config = new ContentLanguageSettings(array(
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_bundle',
|
||||
), 'language_content_settings');
|
||||
$config->setDefaultLangcode($langcode);
|
||||
|
||||
$defaultConfig = new ContentLanguageSettings(array(
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_default_language_bundle',
|
||||
), 'language_content_settings');
|
||||
|
||||
return [
|
||||
[$config, $langcode],
|
||||
[$defaultConfig, LanguageInterface::LANGCODE_SITE_DEFAULT],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::setLanguageAlterable
|
||||
* @covers ::isLanguageAlterable
|
||||
*
|
||||
* @dataProvider providerLanguageAlterable
|
||||
*/
|
||||
public function testLanguageAlterable(ContentLanguageSettings $config, $expected) {
|
||||
$this->assertSame($expected, $config->isLanguageAlterable());
|
||||
}
|
||||
|
||||
public function providerLanguageAlterable() {
|
||||
$alterableConfig = new ContentLanguageSettings(array(
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_bundle',
|
||||
), 'language_content_settings');
|
||||
$alterableConfig->setLanguageAlterable(true);
|
||||
|
||||
$nonAlterableConfig = new ContentLanguageSettings(array(
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_fixed_language_bundle',
|
||||
), 'language_content_settings');
|
||||
$nonAlterableConfig->setLanguageAlterable(false);
|
||||
|
||||
$defaultConfig = new ContentLanguageSettings(array(
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_default_language_bundle',
|
||||
), 'language_content_settings');
|
||||
|
||||
return [
|
||||
[$alterableConfig, true],
|
||||
[$nonAlterableConfig, false],
|
||||
[$defaultConfig, false],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::isDefaultConfiguration
|
||||
*
|
||||
* @dataProvider providerIsDefaultConfiguration
|
||||
*/
|
||||
public function testIsDefaultConfiguration(ContentLanguageSettings $config, $expected) {
|
||||
$this->assertSame($expected, $config->isDefaultConfiguration());
|
||||
}
|
||||
|
||||
public function providerIsDefaultConfiguration() {
|
||||
$alteredLanguage= new ContentLanguageSettings(array(
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_bundle',
|
||||
), 'language_content_settings');
|
||||
$alteredLanguage->setLanguageAlterable(true);
|
||||
|
||||
$alteredDefaultLangcode = new ContentLanguageSettings(array(
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_fixed_language_bundle',
|
||||
), 'language_content_settings');
|
||||
$alteredDefaultLangcode->setDefaultLangcode($this->randomMachineName());
|
||||
|
||||
$defaultConfig = new ContentLanguageSettings(array(
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_default_language_bundle',
|
||||
), 'language_content_settings');
|
||||
|
||||
return [
|
||||
[$alteredLanguage, false],
|
||||
[$alteredDefaultLangcode, false],
|
||||
[$defaultConfig, true],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::loadByEntityTypeBundle
|
||||
*
|
||||
* @dataProvider providerLoadByEntityTypeBundle
|
||||
*/
|
||||
public function testLoadByEntityTypeBundle($config_id, ContentLanguageSettings $existing_config = NULL, $expected_langcode, $expected_language_alterable) {
|
||||
list($type, $bundle) = explode('.', $config_id);
|
||||
|
||||
$nullConfig = new ContentLanguageSettings(array(
|
||||
'target_entity_type_id' => $type,
|
||||
'target_bundle' => $bundle,
|
||||
), 'language_content_settings');
|
||||
$this->configEntityStorageInterface
|
||||
->expects($this->any())
|
||||
->method('load')
|
||||
->with($config_id)
|
||||
->will($this->returnValue($existing_config));
|
||||
$this->configEntityStorageInterface
|
||||
->expects($this->any())
|
||||
->method('create')
|
||||
->will($this->returnValue($nullConfig));
|
||||
|
||||
$this->entityManager
|
||||
->expects($this->any())
|
||||
->method('getStorage')
|
||||
->with('language_content_settings')
|
||||
->will($this->returnValue($this->configEntityStorageInterface));
|
||||
$this->entityManager->expects($this->any())
|
||||
->method('getEntityTypeFromClass')
|
||||
->with('Drupal\language\Entity\ContentLanguageSettings')
|
||||
->willReturn('language_content_settings');
|
||||
|
||||
$config = ContentLanguageSettings::loadByEntityTypeBundle($type, $bundle);
|
||||
|
||||
$this->assertSame($expected_langcode, $config->getDefaultLangcode());
|
||||
$this->assertSame($expected_language_alterable, $config->isLanguageAlterable());
|
||||
}
|
||||
|
||||
public function providerLoadByEntityTypeBundle() {
|
||||
$alteredLanguage= new ContentLanguageSettings(array(
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_bundle',
|
||||
), 'language_content_settings');
|
||||
$alteredLanguage->setLanguageAlterable(true);
|
||||
|
||||
$langcode = $this->randomMachineName();
|
||||
$alteredDefaultLangcode = new ContentLanguageSettings(array(
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_fixed_language_bundle',
|
||||
), 'language_content_settings');
|
||||
$alteredDefaultLangcode->setDefaultLangcode($langcode);
|
||||
|
||||
$defaultConfig = new ContentLanguageSettings(array(
|
||||
'target_entity_type_id' => 'test_entity_type',
|
||||
'target_bundle' => 'test_default_language_bundle',
|
||||
), 'language_content_settings');
|
||||
|
||||
return [
|
||||
['test_entity_type.test_bundle', $alteredLanguage, LanguageInterface::LANGCODE_SITE_DEFAULT, true],
|
||||
['test_entity_type.test_fixed_language_bundle', $alteredDefaultLangcode, $langcode, false],
|
||||
['test_entity_type.test_default_language_bundle', $defaultConfig, LanguageInterface::LANGCODE_SITE_DEFAULT, false],
|
||||
['test_entity_type.null_bundle', NULL, LanguageInterface::LANGCODE_SITE_DEFAULT, false],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,268 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\language\Unit\LanguageNegotiationUrlTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\language\Unit {
|
||||
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\Cache\CacheableMetadata;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\Core\Session\UserSession;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl
|
||||
* @group language
|
||||
*/
|
||||
class LanguageNegotiationUrlTest extends UnitTestCase {
|
||||
|
||||
protected $languageManager;
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
|
||||
// Set up some languages to be used by the language-based path processor.
|
||||
$language_de = $this->getMock('\Drupal\Core\Language\LanguageInterface');
|
||||
$language_de->expects($this->any())
|
||||
->method('getId')
|
||||
->will($this->returnValue('de'));
|
||||
$language_en = $this->getMock('\Drupal\Core\Language\LanguageInterface');
|
||||
$language_en->expects($this->any())
|
||||
->method('getId')
|
||||
->will($this->returnValue('en'));
|
||||
$languages = array(
|
||||
'de' => $language_de,
|
||||
'en' => $language_en,
|
||||
);
|
||||
$this->languages = $languages;
|
||||
|
||||
// Create a language manager stub.
|
||||
$language_manager = $this->getMockBuilder('Drupal\language\ConfigurableLanguageManagerInterface')
|
||||
->getMock();
|
||||
$language_manager->expects($this->any())
|
||||
->method('getLanguages')
|
||||
->will($this->returnValue($languages));
|
||||
$this->languageManager = $language_manager;
|
||||
|
||||
// Create a user stub.
|
||||
$this->user = $this->getMockBuilder('Drupal\Core\Session\AccountInterface')
|
||||
->getMock();
|
||||
|
||||
$cache_contexts_manager = $this->getMockBuilder('Drupal\Core\Cache\Context\CacheContextsManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$container = new ContainerBuilder();
|
||||
$container->set('cache_contexts_manager', $cache_contexts_manager);
|
||||
\Drupal::setContainer($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test path prefix language negotiation and outbound path processing.
|
||||
*
|
||||
* @dataProvider providerTestPathPrefix
|
||||
*/
|
||||
public function testPathPrefix($prefix, $prefixes, $expected_langcode) {
|
||||
$this->languageManager->expects($this->any())
|
||||
->method('getCurrentLanguage')
|
||||
->will($this->returnValue($this->languages[(in_array($expected_langcode, ['en', 'de'])) ? $expected_langcode : 'en']));
|
||||
|
||||
$config = $this->getConfigFactoryStub([
|
||||
'language.negotiation' => [
|
||||
'url' => [
|
||||
'source' => LanguageNegotiationUrl::CONFIG_PATH_PREFIX,
|
||||
'prefixes' => $prefixes,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$request = Request::create('/' . $prefix . '/foo', 'GET');
|
||||
$method = new LanguageNegotiationUrl();
|
||||
$method->setLanguageManager($this->languageManager);
|
||||
$method->setConfig($config);
|
||||
$method->setCurrentUser($this->user);
|
||||
$this->assertEquals($expected_langcode, $method->getLangcode($request));
|
||||
|
||||
$cacheability = new CacheableMetadata();
|
||||
$options = [];
|
||||
$method->processOutbound('foo', $options, $request, $cacheability);
|
||||
$expected_cacheability = new CacheableMetadata();
|
||||
if ($expected_langcode) {
|
||||
$this->assertSame($prefix . '/', $options['prefix']);
|
||||
$expected_cacheability->setCacheContexts(['languages:' . LanguageInterface::TYPE_URL]);
|
||||
}
|
||||
else {
|
||||
$this->assertFalse(isset($options['prefix']));
|
||||
}
|
||||
$this->assertEquals($expected_cacheability, $cacheability);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides data for the path prefix test.
|
||||
*
|
||||
* @return array
|
||||
* An array of data for checking path prefix negotiation.
|
||||
*/
|
||||
public function providerTestPathPrefix() {
|
||||
$path_prefix_configuration[] = [
|
||||
'prefix' => 'de',
|
||||
'prefixes' => [
|
||||
'de' => 'de',
|
||||
'en-uk' => 'en',
|
||||
],
|
||||
'expected_langcode' => 'de',
|
||||
];
|
||||
$path_prefix_configuration[] = [
|
||||
'prefix' => 'en-uk',
|
||||
'prefixes' => [
|
||||
'de' => 'de',
|
||||
'en' => 'en-uk',
|
||||
],
|
||||
'expected_langcode' => 'en',
|
||||
];
|
||||
// No configuration.
|
||||
$path_prefix_configuration[] = [
|
||||
'prefix' => 'de',
|
||||
'prefixes' => array(),
|
||||
'expected_langcode' => FALSE,
|
||||
];
|
||||
// Non-matching prefix.
|
||||
$path_prefix_configuration[] = [
|
||||
'prefix' => 'de',
|
||||
'prefixes' => [
|
||||
'en-uk' => 'en',
|
||||
],
|
||||
'expected_langcode' => FALSE,
|
||||
];
|
||||
// Non-existing language.
|
||||
$path_prefix_configuration[] = [
|
||||
'prefix' => 'it',
|
||||
'prefixes' => [
|
||||
'it' => 'it',
|
||||
'en-uk' => 'en',
|
||||
],
|
||||
'expected_langcode' => FALSE,
|
||||
];
|
||||
return $path_prefix_configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test domain language negotiation and outbound path processing.
|
||||
*
|
||||
* @dataProvider providerTestDomain
|
||||
*/
|
||||
public function testDomain($http_host, $domains, $expected_langcode) {
|
||||
$this->languageManager->expects($this->any())
|
||||
->method('getCurrentLanguage')
|
||||
->will($this->returnValue($this->languages['en']));
|
||||
|
||||
$config = $this->getConfigFactoryStub([
|
||||
'language.negotiation' => [
|
||||
'url' => [
|
||||
'source' => LanguageNegotiationUrl::CONFIG_DOMAIN,
|
||||
'domains' => $domains,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$request = Request::create('', 'GET', array(), array(), array(), array('HTTP_HOST' => $http_host));
|
||||
$method = new LanguageNegotiationUrl();
|
||||
$method->setLanguageManager($this->languageManager);
|
||||
$method->setConfig($config);
|
||||
$method->setCurrentUser($this->user);
|
||||
$this->assertEquals($expected_langcode, $method->getLangcode($request));
|
||||
|
||||
$cacheability = new CacheableMetadata();
|
||||
$options = [];
|
||||
$this->assertSame('foo', $method->processOutbound('foo', $options, $request, $cacheability));
|
||||
$expected_cacheability = new CacheableMetadata();
|
||||
if ($expected_langcode !== FALSE && count($domains) > 1) {
|
||||
$expected_cacheability->setCacheMaxAge(Cache::PERMANENT)->setCacheContexts(['languages:' . LanguageInterface::TYPE_URL, 'url.site']);
|
||||
}
|
||||
$this->assertEquals($expected_cacheability, $cacheability);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides data for the domain test.
|
||||
*
|
||||
* @return array
|
||||
* An array of data for checking domain negotiation.
|
||||
*/
|
||||
public function providerTestDomain() {
|
||||
|
||||
$domain_configuration[] = array(
|
||||
'http_host' => 'example.de',
|
||||
'domains' => array(
|
||||
'de' => 'http://example.de',
|
||||
),
|
||||
'expected_langcode' => 'de',
|
||||
);
|
||||
// No configuration.
|
||||
$domain_configuration[] = array(
|
||||
'http_host' => 'example.de',
|
||||
'domains' => array(),
|
||||
'expected_langcode' => FALSE,
|
||||
);
|
||||
// HTTP host with a port.
|
||||
$domain_configuration[] = array(
|
||||
'http_host' => 'example.de:8080',
|
||||
'domains' => array(
|
||||
'de' => 'http://example.de',
|
||||
),
|
||||
'expected_langcode' => 'de',
|
||||
);
|
||||
// Domain configuration with https://.
|
||||
$domain_configuration[] = array(
|
||||
'http_host' => 'example.de',
|
||||
'domains' => array(
|
||||
'de' => 'https://example.de',
|
||||
),
|
||||
'expected_langcode' => 'de',
|
||||
);
|
||||
// Non-matching HTTP host.
|
||||
$domain_configuration[] = array(
|
||||
'http_host' => 'example.com',
|
||||
'domains' => array(
|
||||
'de' => 'http://example.com',
|
||||
),
|
||||
'expected_langcode' => 'de',
|
||||
);
|
||||
// Testing a non-existing language.
|
||||
$domain_configuration[] = array(
|
||||
'http_host' => 'example.com',
|
||||
'domains' => array(
|
||||
'it' => 'http://example.it',
|
||||
),
|
||||
'expected_langcode' => FALSE,
|
||||
);
|
||||
// Multiple domain configurations.
|
||||
$domain_configuration[] = array(
|
||||
'http_host' => 'example.com',
|
||||
'domains' => array(
|
||||
'de' => 'http://example.de',
|
||||
'en' => 'http://example.com',
|
||||
),
|
||||
'expected_langcode' => 'en',
|
||||
);
|
||||
return $domain_configuration;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// @todo Remove as part of https://www.drupal.org/node/2481833.
|
||||
namespace {
|
||||
if (!function_exists('base_path')) {
|
||||
function base_path() {
|
||||
return '/';
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\language\Unit\Menu\LanguageLocalTasksTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\language\Unit\Menu;
|
||||
|
||||
use Drupal\Tests\Core\Menu\LocalTaskIntegrationTestBase;
|
||||
|
||||
/**
|
||||
* Tests existence of language local tasks.
|
||||
*
|
||||
* @group language
|
||||
*/
|
||||
class LanguageLocalTasksTest extends LocalTaskIntegrationTestBase {
|
||||
|
||||
protected function setUp() {
|
||||
$this->directoryList = array(
|
||||
'language' => 'core/modules/language',
|
||||
);
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests language admin overview local tasks existence.
|
||||
*
|
||||
* @dataProvider getLanguageAdminOverviewRoutes
|
||||
*/
|
||||
public function testLanguageAdminLocalTasks($route, $expected) {
|
||||
$this->assertLocalTasks($route, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a list of routes to test.
|
||||
*/
|
||||
public function getLanguageAdminOverviewRoutes() {
|
||||
return array(
|
||||
array('entity.configurable_language.collection', array(array('entity.configurable_language.collection', 'language.negotiation'))),
|
||||
array('language.negotiation', array(array('entity.configurable_language.collection', 'language.negotiation'))),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests language edit local tasks existence.
|
||||
*/
|
||||
public function testLanguageEditLocalTasks() {
|
||||
$this->assertLocalTasks('entity.configurable_language.edit_form', array(
|
||||
0 => array('entity.configurable_language.edit_form'),
|
||||
));
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue