Move into nested docroot
This commit is contained in:
parent
83a0d3a149
commit
c8b70abde9
13405 changed files with 0 additions and 0 deletions
|
@ -0,0 +1,10 @@
|
|||
name: 'Content translation tests'
|
||||
type: module
|
||||
description: 'Provides content translation tests.'
|
||||
package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- content_translation
|
||||
- language
|
||||
- entity_test
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\content_translation_test\Entity;
|
||||
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
|
||||
/**
|
||||
* Defines the test entity class.
|
||||
*
|
||||
* @ContentEntityType(
|
||||
* id = "entity_test_translatable_no_skip",
|
||||
* label = @Translation("Test entity - Translatable check UI"),
|
||||
* base_table = "entity_test_mul",
|
||||
* data_table = "entity_test_mul_property_data",
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "uuid" = "uuid",
|
||||
* "bundle" = "type",
|
||||
* "label" = "name",
|
||||
* "langcode" = "langcode",
|
||||
* },
|
||||
* translatable = TRUE,
|
||||
* )
|
||||
*/
|
||||
class EntityTestTranslatableNoUISkip extends EntityTest {
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\content_translation_test\Entity;
|
||||
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
|
||||
/**
|
||||
* Defines the test entity class.
|
||||
*
|
||||
* @ContentEntityType(
|
||||
* id = "entity_test_translatable_UI_skip",
|
||||
* label = @Translation("Test entity - Translatable skip UI check"),
|
||||
* base_table = "entity_test_mul",
|
||||
* data_table = "entity_test_mul_property_data",
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "uuid" = "uuid",
|
||||
* "bundle" = "type",
|
||||
* "label" = "name",
|
||||
* "langcode" = "langcode",
|
||||
* },
|
||||
* translatable = TRUE,
|
||||
* content_translation_ui_skip = TRUE,
|
||||
* )
|
||||
*/
|
||||
class EntityTestTranslatableUISkip extends EntityTest {
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
name: 'Content translation test views'
|
||||
type: module
|
||||
description: 'Provides default views for views content translation tests.'
|
||||
package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- content_translation
|
||||
- views
|
|
@ -0,0 +1,112 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
module:
|
||||
- content_translation
|
||||
- user
|
||||
id: test_entity_translations_link
|
||||
label: People
|
||||
module: views
|
||||
description: ''
|
||||
tag: ''
|
||||
base_table: users_field_data
|
||||
base_field: uid
|
||||
core: 8.x
|
||||
display:
|
||||
default:
|
||||
display_plugin: default
|
||||
id: default
|
||||
display_title: Master
|
||||
position: null
|
||||
display_options:
|
||||
access:
|
||||
type: none
|
||||
cache:
|
||||
type: tag
|
||||
query:
|
||||
type: views_query
|
||||
exposed_form:
|
||||
type: basic
|
||||
options:
|
||||
submit_button: Filter
|
||||
reset_button: true
|
||||
reset_button_label: Reset
|
||||
pager:
|
||||
type: full
|
||||
options:
|
||||
items_per_page: 50
|
||||
style:
|
||||
type: table
|
||||
options:
|
||||
columns:
|
||||
name: name
|
||||
translation_link: translation_link
|
||||
default: created
|
||||
row:
|
||||
type: fields
|
||||
fields:
|
||||
name:
|
||||
id: name
|
||||
table: users_field_data
|
||||
field: name
|
||||
label: Username
|
||||
plugin_id: field
|
||||
type: user_name
|
||||
entity_type: user
|
||||
entity_field: name
|
||||
translation_link:
|
||||
id: translation_link
|
||||
table: users
|
||||
field: translation_link
|
||||
label: 'Translation link'
|
||||
exclude: false
|
||||
alter:
|
||||
alter_text: false
|
||||
element_class: ''
|
||||
element_default_classes: true
|
||||
empty: ''
|
||||
hide_empty: false
|
||||
empty_zero: false
|
||||
hide_alter_empty: true
|
||||
text: Translate
|
||||
plugin_id: content_translation_link
|
||||
entity_type: user
|
||||
filters:
|
||||
uid_raw:
|
||||
id: uid_raw
|
||||
table: users_field_data
|
||||
field: uid_raw
|
||||
operator: '!='
|
||||
value:
|
||||
value: '0'
|
||||
group: 1
|
||||
exposed: false
|
||||
plugin_id: numeric
|
||||
entity_type: user
|
||||
sorts:
|
||||
created:
|
||||
id: created
|
||||
table: users_field_data
|
||||
field: created
|
||||
order: DESC
|
||||
plugin_id: date
|
||||
entity_type: user
|
||||
entity_field: created
|
||||
title: People
|
||||
empty:
|
||||
area:
|
||||
id: area
|
||||
table: views
|
||||
field: area
|
||||
empty: true
|
||||
content:
|
||||
value: 'No people available.'
|
||||
format: plain_text
|
||||
plugin_id: text
|
||||
page_1:
|
||||
display_plugin: page
|
||||
id: page_1
|
||||
display_title: Page
|
||||
position: null
|
||||
display_options:
|
||||
path: test-entity-translations-link
|
|
@ -0,0 +1,106 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\content_translation\Kernel;
|
||||
|
||||
use Drupal\Core\Config\ConfigImporter;
|
||||
use Drupal\Core\Config\StorageComparer;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
* Tests content translation updates performed during config import.
|
||||
*
|
||||
* @group content_translation
|
||||
*/
|
||||
class ContentTranslationConfigImportTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* Config Importer object used for testing.
|
||||
*
|
||||
* @var \Drupal\Core\Config\ConfigImporter
|
||||
*/
|
||||
protected $configImporter;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('system', 'user', 'entity_test', 'language', 'content_translation');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installEntitySchema('entity_test_mul');
|
||||
$this->copyConfig($this->container->get('config.storage'), $this->container->get('config.storage.sync'));
|
||||
|
||||
// Set up the ConfigImporter object for testing.
|
||||
$storage_comparer = new StorageComparer(
|
||||
$this->container->get('config.storage.sync'),
|
||||
$this->container->get('config.storage'),
|
||||
$this->container->get('config.manager')
|
||||
);
|
||||
$this->configImporter = new ConfigImporter(
|
||||
$storage_comparer->createChangelist(),
|
||||
$this->container->get('event_dispatcher'),
|
||||
$this->container->get('config.manager'),
|
||||
$this->container->get('lock'),
|
||||
$this->container->get('config.typed'),
|
||||
$this->container->get('module_handler'),
|
||||
$this->container->get('module_installer'),
|
||||
$this->container->get('theme_handler'),
|
||||
$this->container->get('string_translation')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests config import updates.
|
||||
*/
|
||||
function testConfigImportUpdates() {
|
||||
$entity_type_id = 'entity_test_mul';
|
||||
$config_id = $entity_type_id . '.' . $entity_type_id;
|
||||
$config_name = 'language.content_settings.' . $config_id;
|
||||
$storage = $this->container->get('config.storage');
|
||||
$sync = $this->container->get('config.storage.sync');
|
||||
|
||||
// Verify the configuration to create does not exist yet.
|
||||
$this->assertIdentical($storage->exists($config_name), FALSE, $config_name . ' not found.');
|
||||
|
||||
// Create new config entity.
|
||||
$data = array(
|
||||
'uuid' => 'a019d89b-c4d9-4ed4-b859-894e4e2e93cf',
|
||||
'langcode' => 'en',
|
||||
'status' => TRUE,
|
||||
'dependencies' => array(
|
||||
'module' => array('content_translation')
|
||||
),
|
||||
'id' => $config_id,
|
||||
'target_entity_type_id' => 'entity_test_mul',
|
||||
'target_bundle' => 'entity_test_mul',
|
||||
'default_langcode' => 'site_default',
|
||||
'language_alterable' => FALSE,
|
||||
'third_party_settings' => array(
|
||||
'content_translation' => array('enabled' => TRUE),
|
||||
),
|
||||
);
|
||||
$sync->write($config_name, $data);
|
||||
$this->assertIdentical($sync->exists($config_name), TRUE, $config_name . ' found.');
|
||||
|
||||
// Import.
|
||||
$this->configImporter->reset()->import();
|
||||
|
||||
// Verify the values appeared.
|
||||
$config = $this->config($config_name);
|
||||
$this->assertIdentical($config->get('id'), $config_id);
|
||||
|
||||
// Verify that updates were performed.
|
||||
$entity_type = $this->container->get('entity.manager')->getDefinition($entity_type_id);
|
||||
$table = $entity_type->getDataTable();
|
||||
$db_schema = $this->container->get('database')->schema();
|
||||
$result = $db_schema->fieldExists($table, 'content_translation_source') && $db_schema->fieldExists($table, 'content_translation_outdated');
|
||||
$this->assertTrue($result, 'Content translation updates were successfully performed during config import.');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\content_translation\Kernel;
|
||||
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
* Tests the content translation settings API.
|
||||
*
|
||||
* @group content_translation
|
||||
*/
|
||||
class ContentTranslationSettingsApiTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('language', 'content_translation', 'user', 'entity_test');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installEntitySchema('entity_test_mul');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that enabling translation via the API triggers schema updates.
|
||||
*/
|
||||
function testSettingsApi() {
|
||||
$this->container->get('content_translation.manager')->setEnabled('entity_test_mul', 'entity_test_mul', TRUE);
|
||||
$result =
|
||||
db_field_exists('entity_test_mul_property_data', 'content_translation_source') &&
|
||||
db_field_exists('entity_test_mul_property_data', 'content_translation_outdated');
|
||||
$this->assertTrue($result, 'Schema updates correctly performed.');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,252 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\content_translation\Kernel;
|
||||
|
||||
use Drupal\content_translation\FieldTranslationSynchronizer;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
* Tests the field synchronization logic.
|
||||
*
|
||||
* @group content_translation
|
||||
*/
|
||||
class ContentTranslationSyncUnitTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* The synchronizer class to be tested.
|
||||
*
|
||||
* @var \Drupal\content_translation\FieldTranslationSynchronizer
|
||||
*/
|
||||
protected $synchronizer;
|
||||
|
||||
/**
|
||||
* The columns to be synchronized.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $synchronized;
|
||||
|
||||
/**
|
||||
* All the field columns.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $columns;
|
||||
|
||||
/**
|
||||
* The available language codes.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $langcodes;
|
||||
|
||||
/**
|
||||
* The field cardinality.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $cardinality;
|
||||
|
||||
/**
|
||||
* The unchanged field values.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $unchangedFieldValues;
|
||||
|
||||
public static $modules = array('language', 'content_translation');
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->synchronizer = new FieldTranslationSynchronizer($this->container->get('entity.manager'));
|
||||
$this->synchronized = array('sync1', 'sync2');
|
||||
$this->columns = array_merge($this->synchronized, array('var1', 'var2'));
|
||||
$this->langcodes = array('en', 'it', 'fr', 'de', 'es');
|
||||
$this->cardinality = 4;
|
||||
$this->unchangedFieldValues = array();
|
||||
|
||||
// Set up an initial set of values in the correct state, that is with
|
||||
// "synchronized" values being equal.
|
||||
foreach ($this->langcodes as $langcode) {
|
||||
for ($delta = 0; $delta < $this->cardinality; $delta++) {
|
||||
foreach ($this->columns as $column) {
|
||||
$sync = in_array($column, $this->synchronized) && $langcode != $this->langcodes[0];
|
||||
$value = $sync ? $this->unchangedFieldValues[$this->langcodes[0]][$delta][$column] : $langcode . '-' . $delta . '-' . $column;
|
||||
$this->unchangedFieldValues[$langcode][$delta][$column] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the field synchronization algorithm.
|
||||
*/
|
||||
public function testFieldSync() {
|
||||
// Add a new item to the source items and check that its added to all the
|
||||
// translations.
|
||||
$sync_langcode = $this->langcodes[2];
|
||||
$unchanged_items = $this->unchangedFieldValues[$sync_langcode];
|
||||
$field_values = $this->unchangedFieldValues;
|
||||
$item = array();
|
||||
foreach ($this->columns as $column) {
|
||||
$item[$column] = $this->randomMachineName();
|
||||
}
|
||||
$field_values[$sync_langcode][] = $item;
|
||||
$this->synchronizer->synchronizeItems($field_values, $unchanged_items, $sync_langcode, $this->langcodes, $this->synchronized);
|
||||
$result = TRUE;
|
||||
foreach ($this->unchangedFieldValues as $langcode => $items) {
|
||||
// Check that the old values are still in place.
|
||||
for ($delta = 0; $delta < $this->cardinality; $delta++) {
|
||||
foreach ($this->columns as $column) {
|
||||
$result = $result && ($this->unchangedFieldValues[$langcode][$delta][$column] == $field_values[$langcode][$delta][$column]);
|
||||
}
|
||||
}
|
||||
// Check that the new item is available in all languages.
|
||||
foreach ($this->columns as $column) {
|
||||
$result = $result && ($field_values[$langcode][$delta][$column] == $field_values[$sync_langcode][$delta][$column]);
|
||||
}
|
||||
}
|
||||
$this->assertTrue($result, 'A new item has been correctly synchronized.');
|
||||
|
||||
// Remove an item from the source items and check that its removed from all
|
||||
// the translations.
|
||||
$sync_langcode = $this->langcodes[1];
|
||||
$unchanged_items = $this->unchangedFieldValues[$sync_langcode];
|
||||
$field_values = $this->unchangedFieldValues;
|
||||
$sync_delta = mt_rand(0, count($field_values[$sync_langcode]) - 1);
|
||||
unset($field_values[$sync_langcode][$sync_delta]);
|
||||
// Renumber deltas to start from 0.
|
||||
$field_values[$sync_langcode] = array_values($field_values[$sync_langcode]);
|
||||
$this->synchronizer->synchronizeItems($field_values, $unchanged_items, $sync_langcode, $this->langcodes, $this->synchronized);
|
||||
$result = TRUE;
|
||||
foreach ($this->unchangedFieldValues as $langcode => $items) {
|
||||
$new_delta = 0;
|
||||
// Check that the old values are still in place.
|
||||
for ($delta = 0; $delta < $this->cardinality; $delta++) {
|
||||
// Skip the removed item.
|
||||
if ($delta != $sync_delta) {
|
||||
foreach ($this->columns as $column) {
|
||||
$result = $result && ($this->unchangedFieldValues[$langcode][$delta][$column] == $field_values[$langcode][$new_delta][$column]);
|
||||
}
|
||||
$new_delta++;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->assertTrue($result, 'A removed item has been correctly synchronized.');
|
||||
|
||||
// Move the items around in the source items and check that they are moved
|
||||
// in all the translations.
|
||||
$sync_langcode = $this->langcodes[3];
|
||||
$unchanged_items = $this->unchangedFieldValues[$sync_langcode];
|
||||
$field_values = $this->unchangedFieldValues;
|
||||
$field_values[$sync_langcode] = array();
|
||||
// Scramble the items.
|
||||
foreach ($unchanged_items as $delta => $item) {
|
||||
$new_delta = ($delta + 1) % $this->cardinality;
|
||||
$field_values[$sync_langcode][$new_delta] = $item;
|
||||
}
|
||||
// Renumber deltas to start from 0.
|
||||
ksort($field_values[$sync_langcode]);
|
||||
$this->synchronizer->synchronizeItems($field_values, $unchanged_items, $sync_langcode, $this->langcodes, $this->synchronized);
|
||||
$result = TRUE;
|
||||
foreach ($field_values as $langcode => $items) {
|
||||
for ($delta = 0; $delta < $this->cardinality; $delta++) {
|
||||
foreach ($this->columns as $column) {
|
||||
$value = $field_values[$langcode][$delta][$column];
|
||||
if (in_array($column, $this->synchronized)) {
|
||||
// If we are dealing with a synchronize column the current value is
|
||||
// supposed to be the same of the source items.
|
||||
$result = $result && $field_values[$sync_langcode][$delta][$column] == $value;
|
||||
}
|
||||
else {
|
||||
// Otherwise the values should be unchanged.
|
||||
$old_delta = ($delta > 0 ? $delta : $this->cardinality) - 1;
|
||||
$result = $result && $this->unchangedFieldValues[$langcode][$old_delta][$column] == $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->assertTrue($result, 'Scrambled items have been correctly synchronized.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that items holding the same values are correctly synchronized.
|
||||
*/
|
||||
public function testMultipleSyncedValues() {
|
||||
$sync_langcode = $this->langcodes[1];
|
||||
$unchanged_items = $this->unchangedFieldValues[$sync_langcode];
|
||||
|
||||
// Determine whether the unchanged values should be altered depending on
|
||||
// their delta.
|
||||
$delta_callbacks = array(
|
||||
// Continuous field values: all values are equal.
|
||||
function($delta) { return TRUE; },
|
||||
// Alternated field values: only the even ones are equal.
|
||||
function($delta) { return $delta % 2 !== 0; },
|
||||
// Sparse field values: only the "middle" ones are equal.
|
||||
function($delta) { return $delta === 1 || $delta === 2; },
|
||||
// Sparse field values: only the "extreme" ones are equal.
|
||||
function($delta) { return $delta === 0 || $delta === 3; },
|
||||
);
|
||||
|
||||
foreach ($delta_callbacks as $delta_callback) {
|
||||
$field_values = $this->unchangedFieldValues;
|
||||
|
||||
for ($delta = 0; $delta < $this->cardinality; $delta++) {
|
||||
if ($delta_callback($delta)) {
|
||||
foreach ($this->columns as $column) {
|
||||
if (in_array($column, $this->synchronized)) {
|
||||
$field_values[$sync_langcode][$delta][$column] = $field_values[$sync_langcode][0][$column];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$changed_items = $field_values[$sync_langcode];
|
||||
$this->synchronizer->synchronizeItems($field_values, $unchanged_items, $sync_langcode, $this->langcodes, $this->synchronized);
|
||||
|
||||
foreach ($this->unchangedFieldValues as $langcode => $unchanged_items) {
|
||||
for ($delta = 0; $delta < $this->cardinality; $delta++) {
|
||||
foreach ($this->columns as $column) {
|
||||
// The first item is always unchanged hence it is retained by the
|
||||
// synchronization process. The other ones are retained or synced
|
||||
// depending on the logic implemented by the delta callback and
|
||||
// whether it is a sync column or not.
|
||||
$value = $delta > 0 && $delta_callback($delta) && in_array($column, $this->synchronized) ? $changed_items[0][$column] : $unchanged_items[$delta][$column];
|
||||
$this->assertEqual($field_values[$langcode][$delta][$column], $value, "Item $delta column $column for langcode $langcode synced correctly");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that one change in a synchronized column triggers a change in all columns.
|
||||
*/
|
||||
public function testDifferingSyncedColumns() {
|
||||
$sync_langcode = $this->langcodes[2];
|
||||
$unchanged_items = $this->unchangedFieldValues[$sync_langcode];
|
||||
$field_values = $this->unchangedFieldValues;
|
||||
|
||||
for ($delta = 0; $delta < $this->cardinality; $delta++) {
|
||||
$index = ($delta % 2) + 1;
|
||||
$field_values[$sync_langcode][$delta]['sync' . $index] .= '-updated';
|
||||
}
|
||||
|
||||
$changed_items = $field_values[$sync_langcode];
|
||||
$this->synchronizer->synchronizeItems($field_values, $unchanged_items, $sync_langcode, $this->langcodes, $this->synchronized);
|
||||
|
||||
foreach ($this->unchangedFieldValues as $langcode => $unchanged_items) {
|
||||
for ($delta = 0; $delta < $this->cardinality; $delta++) {
|
||||
foreach ($this->columns as $column) {
|
||||
// If the column is synchronized, the value should have been synced,
|
||||
// for unsychronized columns, the value must not change.
|
||||
$expected_value = in_array($column, $this->synchronized) ? $changed_items[$delta][$column] : $this->unchangedFieldValues[$langcode][$delta][$column];
|
||||
$this->assertEqual($field_values[$langcode][$delta][$column], $expected_value, "Differing Item $delta column $column for langcode $langcode synced correctly");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,133 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\content_translation\Unit\Access;
|
||||
|
||||
use Drupal\content_translation\Access\ContentTranslationManageAccessCheck;
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\Language\Language;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
||||
/**
|
||||
* Tests for content translation manage check.
|
||||
*
|
||||
* @coversDefaultClass \Drupal\content_translation\Access\ContentTranslationManageAccessCheck
|
||||
* @group Access
|
||||
* @group content_translation
|
||||
*/
|
||||
class ContentTranslationManageAccessCheckTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* The cache contexts manager.
|
||||
*
|
||||
* @var \Drupal\Core\Cache\Context\CacheContextsManager|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $cacheContextsManager;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->cacheContextsManager = $this->getMockBuilder('Drupal\Core\Cache\Context\CacheContextsManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->cacheContextsManager->method('assertValidTokens')->willReturn(TRUE);
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
$container->set('cache_contexts_manager', $this->cacheContextsManager);
|
||||
\Drupal::setContainer($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the create access method.
|
||||
*
|
||||
* @covers ::access
|
||||
*/
|
||||
public function testCreateAccess() {
|
||||
// Set the mock translation handler.
|
||||
$translation_handler = $this->getMock('\Drupal\content_translation\ContentTranslationHandlerInterface');
|
||||
$translation_handler->expects($this->once())
|
||||
->method('getTranslationAccess')
|
||||
->will($this->returnValue(AccessResult::allowed()));
|
||||
|
||||
$entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
|
||||
$entity_manager->expects($this->once())
|
||||
->method('getHandler')
|
||||
->withAnyParameters()
|
||||
->will($this->returnValue($translation_handler));
|
||||
|
||||
// Set our source and target languages.
|
||||
$source = 'en';
|
||||
$target = 'it';
|
||||
|
||||
// Set the mock language manager.
|
||||
$language_manager = $this->getMock('Drupal\Core\Language\LanguageManagerInterface');
|
||||
$language_manager->expects($this->at(0))
|
||||
->method('getLanguage')
|
||||
->with($this->equalTo($source))
|
||||
->will($this->returnValue(new Language(array('id' => 'en'))));
|
||||
$language_manager->expects($this->at(1))
|
||||
->method('getLanguages')
|
||||
->will($this->returnValue(array('en' => array(), 'it' => array())));
|
||||
$language_manager->expects($this->at(2))
|
||||
->method('getLanguage')
|
||||
->with($this->equalTo($source))
|
||||
->will($this->returnValue(new Language(array('id' => 'en'))));
|
||||
$language_manager->expects($this->at(3))
|
||||
->method('getLanguage')
|
||||
->with($this->equalTo($target))
|
||||
->will($this->returnValue(new Language(array('id' => 'it'))));
|
||||
|
||||
// Set the mock entity. We need to use ContentEntityBase for mocking due to
|
||||
// issues with phpunit and multiple interfaces.
|
||||
$entity = $this->getMockBuilder('Drupal\Core\Entity\ContentEntityBase')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$entity->expects($this->once())
|
||||
->method('getEntityTypeId');
|
||||
$entity->expects($this->once())
|
||||
->method('getTranslationLanguages')
|
||||
->with()
|
||||
->will($this->returnValue(array()));
|
||||
$entity->expects($this->once())
|
||||
->method('getCacheContexts')
|
||||
->willReturn([]);
|
||||
$entity->expects($this->once())
|
||||
->method('getCacheMaxAge')
|
||||
->willReturn(Cache::PERMANENT);
|
||||
$entity->expects($this->once())
|
||||
->method('getCacheTags')
|
||||
->will($this->returnValue(array('node:1337')));
|
||||
$entity->expects($this->once())
|
||||
->method('getCacheContexts')
|
||||
->willReturn(array());
|
||||
|
||||
// Set the route requirements.
|
||||
$route = new Route('test_route');
|
||||
$route->setRequirement('_access_content_translation_manage', 'create');
|
||||
|
||||
// Set up the route match.
|
||||
$route_match = $this->getMock('Drupal\Core\Routing\RouteMatchInterface');
|
||||
$route_match->expects($this->once())
|
||||
->method('getParameter')
|
||||
->with('node')
|
||||
->will($this->returnValue($entity));
|
||||
|
||||
// Set the mock account.
|
||||
$account = $this->getMock('Drupal\Core\Session\AccountInterface');
|
||||
|
||||
// The access check under test.
|
||||
$check = new ContentTranslationManageAccessCheck($entity_manager, $language_manager);
|
||||
|
||||
// The request params.
|
||||
$language = 'en';
|
||||
$entity_type_id = 'node';
|
||||
|
||||
$this->assertTrue($check->access($route, $route_match, $account, $source, $target, $language, $entity_type_id)->isAllowed(), "The access check matches");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\content_translation\Unit\Menu;
|
||||
|
||||
use Drupal\Tests\Core\Menu\LocalTaskIntegrationTestBase;
|
||||
|
||||
/**
|
||||
* Tests content translation local tasks.
|
||||
*
|
||||
* @group content_translation
|
||||
*/
|
||||
class ContentTranslationLocalTasksTest extends LocalTaskIntegrationTestBase {
|
||||
|
||||
protected function setUp() {
|
||||
$this->directoryList = array(
|
||||
'content_translation' => 'core/modules/content_translation',
|
||||
'node' => 'core/modules/node',
|
||||
);
|
||||
parent::setUp();
|
||||
|
||||
$entity_type = $this->getMock('Drupal\Core\Entity\EntityTypeInterface');
|
||||
$entity_type->expects($this->any())
|
||||
->method('getLinkTemplate')
|
||||
->will($this->returnValueMap(array(
|
||||
array('canonical', 'entity.node.canonical'),
|
||||
array('drupal:content-translation-overview', 'entity.node.content_translation_overview'),
|
||||
)));
|
||||
$content_translation_manager = $this->getMock('Drupal\content_translation\ContentTranslationManagerInterface');
|
||||
$content_translation_manager->expects($this->any())
|
||||
->method('getSupportedEntityTypes')
|
||||
->will($this->returnValue(array(
|
||||
'node' => $entity_type,
|
||||
)));
|
||||
\Drupal::getContainer()->set('content_translation.manager', $content_translation_manager);
|
||||
\Drupal::getContainer()->set('string_translation', $this->getStringTranslationStub());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the block admin display local tasks.
|
||||
*
|
||||
* @dataProvider providerTestBlockAdminDisplay
|
||||
*/
|
||||
public function testBlockAdminDisplay($route, $expected) {
|
||||
$this->assertLocalTasks($route, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a list of routes to test.
|
||||
*/
|
||||
public function providerTestBlockAdminDisplay() {
|
||||
return array(
|
||||
array('entity.node.canonical', array(array(
|
||||
'content_translation.local_tasks:entity.node.content_translation_overview',
|
||||
'entity.node.canonical',
|
||||
'entity.node.edit_form',
|
||||
'entity.node.delete_form',
|
||||
'entity.node.version_history',
|
||||
))),
|
||||
array('entity.node.content_translation_overview', array(array(
|
||||
'content_translation.local_tasks:entity.node.content_translation_overview',
|
||||
'entity.node.canonical',
|
||||
'entity.node.edit_form',
|
||||
'entity.node.delete_form',
|
||||
'entity.node.version_history',
|
||||
))),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue