updated core to 8.6.3

This commit is contained in:
2018-11-21 12:49:46 +01:00
parent 8ca34853a3
commit c92c348eee
521 changed files with 12199 additions and 4578 deletions
@@ -51,6 +51,21 @@ process:
'settings/handler_settings/target_bundles/0': '@field_name'
'settings/handler_settings/auto_create': 'constants/auto_create'
required: required
# Get the i18n taxonomy translation setting for this vocabulary.
# 0 - No multilingual options
# 1 - Localizable terms. Run through the localization system.
# 2 - Predefined language for a vocabulary and its terms.
# 3 - Per-language terms, translatable (referencing terms with different
# languages) but not localizable.
translatable:
plugin: static_map
source: i18ntaxonomy_vocabulary
default_value: 0
map:
0: false
1: false
2: false
3: true
destination:
plugin: entity:field_config
migration_dependencies:
@@ -34,6 +34,7 @@ process:
source: '@parent_id'
forum_container: is_container
changed: timestamp
langcode: language
destination:
plugin: entity:taxonomy_term
migration_dependencies:
@@ -87,7 +87,7 @@ class Vocabulary extends ConfigEntityBundleBase implements VocabularyInterface {
* Possible values:
* - VocabularyInterface::HIERARCHY_DISABLED: No parents.
* - VocabularyInterface::HIERARCHY_SINGLE: Single parent.
* - VocabularyInterface::HIERARCHY_MULTIPL: Multiple parents.
* - VocabularyInterface::HIERARCHY_MULTIPLE: Multiple parents.
*
* @var int
*/
@@ -2,6 +2,8 @@
namespace Drupal\taxonomy\Plugin\migrate\source\d6;
use Drupal\migrate\Row;
/**
* Gets all the vocabularies based on the node types that have Taxonomy enabled.
*
@@ -22,6 +24,26 @@ class VocabularyPerType extends Vocabulary {
return $query;
}
/**
* {@inheritdoc}
*/
public function prepareRow(Row $row) {
// Get the i18n taxonomy translation setting for this vocabulary.
// 0 - No multilingual options
// 1 - Localizable terms. Run through the localization system.
// 2 - Predefined language for a vocabulary and its terms.
// 3 - Per-language terms, translatable (referencing terms with different
// languages) but not localizable.
$i18ntaxonomy_vocab = $this->variableGet('i18ntaxonomy_vocabulary', NULL);
$vid = $row->getSourceProperty('vid');
$i18ntaxonomy_vocabulary = FALSE;
if (array_key_exists($vid, $i18ntaxonomy_vocab)) {
$i18ntaxonomy_vocabulary = $i18ntaxonomy_vocab[$vid];
}
$row->setSourceProperty('i18ntaxonomy_vocabulary', $i18ntaxonomy_vocabulary);
return parent::prepareRow($row);
}
/**
* {@inheritdoc}
*/
@@ -56,10 +56,26 @@ class Term extends FieldableEntity {
* {@inheritdoc}
*/
public function prepareRow(Row $row) {
$tid = $row->getSourceProperty('tid');
$vocabulary = $row->getSourceProperty('machine_name');
$default_language = (array) $this->variableGet('language_default', ['language' => 'en']);
// If this entity was translated using Entity Translation, we need to get
// its source language to get the field values in the right language.
// The translations will be migrated by the d7_node_entity_translation
// migration.
$translatable_vocabularies = array_keys(array_filter($this->variableGet('entity_translation_taxonomy', [])));
$entity_translatable = $this->isEntityTranslatable('taxonomy_term') && in_array($vocabulary, $translatable_vocabularies, TRUE);
$source_language = $this->getEntityTranslationSourceLanguage('taxonomy_term', $tid);
$language = $entity_translatable && $source_language ? $source_language : $default_language['language'];
$row->setSourceProperty('language', $language);
// Get Field API field values.
foreach (array_keys($this->getFields('taxonomy_term', $row->getSourceProperty('machine_name'))) as $field) {
$tid = $row->getSourceProperty('tid');
$row->setSourceProperty($field, $this->getFieldValues('taxonomy_term', $field, $tid));
foreach ($this->getFields('taxonomy_term', $vocabulary) as $field_name => $field) {
// Ensure we're using the right language if the entity and the field are
// translatable.
$field_language = $entity_translatable && $field['translatable'] ? $language : NULL;
$row->setSourceProperty($field_name, $this->getFieldValues('taxonomy_term', $field_name, $tid, NULL, $field_language));
}
// Find parents for this row.
@@ -87,6 +103,9 @@ class Term extends FieldableEntity {
if (isset($description_field[0]['value'])) {
$row->setSourceProperty('description', $description_field[0]['value']);
}
if (isset($description_field[0]['format'])) {
$row->setSourceProperty('format', $description_field[0]['format']);
}
}
return parent::prepareRow($row);
@@ -0,0 +1,122 @@
<?php
namespace Drupal\taxonomy\Plugin\migrate\source\d7;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\d7\FieldableEntity;
/**
* Provides Drupal 7 taxonomy term entity translation source plugin.
*
* @MigrateSource(
* id = "d7_taxonomy_term_entity_translation",
* source_module = "entity_translation"
* )
*/
class TermEntityTranslation extends FieldableEntity {
/**
* {@inheritdoc}
*/
public function query() {
$query = $this->select('entity_translation', 'et')
->fields('et')
->fields('td', [
'name',
'description',
'format',
])
->fields('tv', [
'machine_name',
])
->condition('et.entity_type', 'taxonomy_term')
->condition('et.source', '', '<>');
$query->innerJoin('taxonomy_term_data', 'td', 'td.tid = et.entity_id');
$query->innerJoin('taxonomy_vocabulary', 'tv', 'td.vid = tv.vid');
if (isset($this->configuration['bundle'])) {
$query->condition('tv.machine_name', (array) $this->configuration['bundle'], 'IN');
}
return $query;
}
/**
* {@inheritdoc}
*/
public function prepareRow(Row $row) {
$tid = $row->getSourceProperty('entity_id');
$vocabulary = $row->getSourceProperty('machine_name');
$language = $row->getSourceProperty('language');
// Get Field API field values.
foreach ($this->getFields('taxonomy_term', $vocabulary) as $field_name => $field) {
// Ensure we're using the right language if the entity is translatable.
$field_language = $field['translatable'] ? $language : NULL;
$row->setSourceProperty($field_name, $this->getFieldValues('taxonomy_term', $field_name, $tid, NULL, $field_language));
}
// If the term name or term description were replaced by real fields using
// the Drupal 7 Title module, use the fields value instead of the term name
// or term description.
if ($this->moduleExists('title')) {
$name_field = $row->getSourceProperty('name_field');
if (isset($name_field[0]['value'])) {
$row->setSourceProperty('name', $name_field[0]['value']);
}
$description_field = $row->getSourceProperty('description_field');
if (isset($description_field[0]['value'])) {
$row->setSourceProperty('description', $description_field[0]['value']);
}
if (isset($description_field[0]['format'])) {
$row->setSourceProperty('format', $description_field[0]['format']);
}
}
// Determine if this is a forum container.
$forum_container_tids = $this->variableGet('forum_containers', []);
$row->setSourceProperty('is_container', in_array($tid, $forum_container_tids));
return parent::prepareRow($row);
}
/**
* {@inheritdoc}
*/
public function fields() {
return [
'entity_type' => $this->t('The entity type this translation relates to'),
'entity_id' => $this->t('The entity ID this translation relates to'),
'revision_id' => $this->t('The entity revision ID this translation relates to'),
'language' => $this->t('The target language for this translation.'),
'source' => $this->t('The source language from which this translation was created.'),
'uid' => $this->t('The author of this translation.'),
'status' => $this->t('Boolean indicating whether the translation is published (visible to non-administrators).'),
'translate' => $this->t('A boolean indicating whether this translation needs to be updated.'),
'created' => $this->t('The Unix timestamp when the translation was created.'),
'changed' => $this->t('The Unix timestamp when the translation was most recently saved.'),
'name' => $this->t('The name of the term.'),
'description' => $this->t('The term description.'),
'format' => $this->t('Format of the term description.'),
'machine_name' => $this->t('Vocabulary machine name'),
];
}
/**
* {@inheritdoc}
*/
public function getIds() {
return [
'entity_id' => [
'type' => 'integer',
'alias' => 'et',
],
'language' => [
'type' => 'string',
'alias' => 'et',
],
];
}
}
@@ -15,7 +15,7 @@ class TermStorageSchema extends SqlContentEntityStorageSchema {
* {@inheritdoc}
*/
protected function getEntitySchema(ContentEntityTypeInterface $entity_type, $reset = FALSE) {
$schema = parent::getEntitySchema($entity_type, $reset = FALSE);
$schema = parent::getEntitySchema($entity_type, $reset);
if ($data_table = $this->storage->getDataTable()) {
$schema[$data_table]['indexes'] += [
@@ -4,8 +4,8 @@ namespace Drupal\taxonomy\Tests;
@trigger_error(__NAMESPACE__ . '\TaxonomyTestBase is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\taxonomy\Functional\TaxonomyTestBase', E_USER_DEPRECATED);
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\simpletest\WebTestBase;
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
use Drupal\Tests\taxonomy\Functional\TaxonomyTestTrait;
/**
@@ -5,9 +5,9 @@ namespace Drupal\taxonomy\Tests;
@trigger_error(__NAMESPACE__ . '\TaxonomyTranslationTestTrait is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\taxonomy\Functional\TaxonomyTranslationTestTrait', E_USER_DEPRECATED);
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
/**
* Provides common testing base for translated taxonomy terms.
+6 -1
View File
@@ -32,7 +32,12 @@ function taxonomy_update_8502(&$sandbox) {
$sandbox['tid'] = -1;
$sandbox['delta'] = 0;
$sandbox['limit'] = Settings::get('entity_update_batch_size', 50);
$sandbox['max'] = $database->select('taxonomy_term_hierarchy')
// Count records using a join, as there might be orphans in the hierarchy
// table. See https://www.drupal.org/project/drupal/issues/2997982.
$select = $database->select('taxonomy_term_hierarchy', 'h');
$select->join('taxonomy_term_data', 'd', 'h.tid = d.tid');
$sandbox['max'] = $select
->countQuery()
->execute()
->fetchField();
@@ -1,6 +1,6 @@
<?php
namespace Drupal\taxonomy\Tests;
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\views\Views;
@@ -106,7 +106,11 @@ class RssTest extends TaxonomyTestBase {
// Test that the feed page exists for the term.
$this->drupalGet("taxonomy/term/{$term1->id()}/feed");
$this->assertTrue(!empty($this->cssSelect('rss[version="2.0"]')), "Feed page is RSS.");
$assert = $this->assertSession();
$assert->responseHeaderContains('Content-Type', 'application/rss+xml');
// Ensure the RSS version is 2.0.
$rss_array = $this->getSession()->getDriver()->find('rss');
$this->assertEquals('2.0', reset($rss_array)->getAttribute('version'));
// Check that the "Exception value" is disabled by default.
$this->drupalGet('taxonomy/term/all/feed');
@@ -1,6 +1,6 @@
<?php
namespace Drupal\taxonomy\Tests;
namespace Drupal\Tests\taxonomy\Functional;
/**
* Ensure that the term indentation works properly.
@@ -33,6 +33,7 @@ class TaxonomyTermIndentationTest extends TaxonomyTestBase {
* Tests term indentation.
*/
public function testTermIndentation() {
$assert = $this->assertSession();
// Create three taxonomy terms.
$term1 = $this->createTerm($this->vocabulary);
$term2 = $this->createTerm($this->vocabulary);
@@ -42,15 +43,23 @@ class TaxonomyTermIndentationTest extends TaxonomyTestBase {
$taxonomy_storage = $this->container->get('entity.manager')->getStorage('taxonomy_term');
// Indent the second term under the first one.
$edit = [
$this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->get('vid') . '/overview');
$hidden_edit = [
'terms[tid:' . $term2->id() . ':0][term][tid]' => 2,
'terms[tid:' . $term2->id() . ':0][term][parent]' => 1,
'terms[tid:' . $term2->id() . ':0][term][depth]' => 1,
];
// Because we can't post hidden form elements, we have to change them in
// code here, and then submit.
foreach ($hidden_edit as $field => $value) {
$node = $assert->hiddenFieldExists($field);
$node->setValue($value);
}
$edit = [
'terms[tid:' . $term2->id() . ':0][weight]' => 1,
];
// Submit the edited form and check for HTML indentation element presence.
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->get('vid') . '/overview', $edit, t('Save'));
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertPattern('|<div class="js-indentation indentation">&nbsp;</div>|');
// Check explicitly that term 2's parent is term 1.
@@ -58,16 +67,24 @@ class TaxonomyTermIndentationTest extends TaxonomyTestBase {
$this->assertEqual(key($parents), 1, 'Term 1 is the term 2\'s parent');
// Move the second term back out to the root level.
$edit = [
$this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->get('vid') . '/overview');
$hidden_edit = [
'terms[tid:' . $term2->id() . ':0][term][tid]' => 2,
'terms[tid:' . $term2->id() . ':0][term][parent]' => 0,
'terms[tid:' . $term2->id() . ':0][term][depth]' => 0,
];
// Because we can't post hidden form elements, we have to change them in
// code here, and then submit.
foreach ($hidden_edit as $field => $value) {
$node = $assert->hiddenFieldExists($field);
$node->setValue($value);
}
$edit = [
'terms[tid:' . $term2->id() . ':0][weight]' => 1,
];
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->get('vid') . '/overview', $edit, t('Save'));
$this->drupalPostForm(NULL, $edit, t('Save'));
// All terms back at the root level, no indentation should be present.
$this->assertNoPattern('|<div class="js-indentation indentation">&nbsp;</div>|');
$this->assertSession()->responseNotMatches('|<div class="js-indentation indentation">&nbsp;</div>|');
// Check explicitly that term 2 has no parents.
\Drupal::entityManager()->getStorage('taxonomy_term')->resetCache();
@@ -2,8 +2,8 @@
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
/**
* Provides common helper methods for Taxonomy module tests.
@@ -3,9 +3,9 @@
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
/**
* Provides common testing base for translated taxonomy terms.
@@ -1,7 +1,8 @@
<?php
namespace Drupal\taxonomy\Tests;
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\Component\Serialization\Json;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
@@ -15,6 +16,13 @@ use Drupal\field\Entity\FieldStorageConfig;
*/
class TermAutocompleteTest extends TaxonomyTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['node'];
/**
* The vocabulary.
*
@@ -127,7 +135,25 @@ class TermAutocompleteTest extends TaxonomyTestBase {
// Retrieve the autocomplete url.
$this->drupalGet('node/add/article');
$result = $this->xpath('//input[@name="' . $this->fieldName . '[0][target_id]"]');
$this->autocompleteUrl = $this->getAbsoluteUrl($result[0]['data-autocomplete-path']);
$this->autocompleteUrl = $this->getAbsoluteUrl($result[0]->getAttribute('data-autocomplete-path'));
}
/**
* Helper function for JSON formatted requests.
*
* @param string|\Drupal\Core\Url $path
* Drupal path or URL to load into Mink controlled browser.
* @param array $options
* (optional) Options to be forwarded to the url generator.
* @param string[] $headers
* (optional) An array containing additional HTTP request headers.
*
* @return string[]
* Array representing decoded JSON response.
*/
protected function drupalGetJson($path, array $options = [], array $headers = []) {
$options = array_merge_recursive(['query' => ['_format' => 'json']], $options);
return Json::decode($this->drupalGet($path, $options, $headers));
}
/**
@@ -137,21 +163,21 @@ class TermAutocompleteTest extends TaxonomyTestBase {
*/
public function testAutocompleteCountResults() {
// Test that no matching term found.
$data = $this->drupalGetJSON(
$data = $this->drupalGetJson(
$this->autocompleteUrl,
['query' => ['q' => 'zzz']]
);
$this->assertTrue(empty($data), 'Autocomplete returned no results');
// Test that only one matching term found, when only one matches.
$data = $this->drupalGetJSON(
$data = $this->drupalGetJson(
$this->autocompleteUrl,
['query' => ['q' => 'aaa 10']]
);
$this->assertEqual(1, count($data), 'Autocomplete returned 1 result');
// Test the correct number of matches when multiple are partial matches.
$data = $this->drupalGetJSON(
$data = $this->drupalGetJson(
$this->autocompleteUrl,
['query' => ['q' => 'aaa 1']]
);
@@ -159,7 +185,7 @@ class TermAutocompleteTest extends TaxonomyTestBase {
// Tests that only 10 results are returned, even if there are more than 10
// matches.
$data = $this->drupalGetJSON(
$data = $this->drupalGetJson(
$this->autocompleteUrl,
['query' => ['q' => 'aaa']]
);
@@ -192,7 +218,7 @@ class TermAutocompleteTest extends TaxonomyTestBase {
];
}
$data = $this->drupalGetJSON(
$data = $this->drupalGetJson(
$this->autocompleteUrl,
['query' => ['q' => 'bbb']]
);
@@ -1,6 +1,6 @@
<?php
namespace Drupal\taxonomy\Tests;
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\Component\Utility\Tags;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
@@ -389,6 +389,7 @@ class TermTest extends TaxonomyTestBase {
* Save, edit and delete a term using the user interface.
*/
public function testTermReorder() {
$assert = $this->assertSession();
$this->createTerm($this->vocabulary);
$this->createTerm($this->vocabulary);
$this->createTerm($this->vocabulary);
@@ -406,21 +407,30 @@ class TermTest extends TaxonomyTestBase {
// "tid:1:0[depth]", and "tid:1:0[weight]". Change the order to term2,
// term3, term1 by setting weight property, make term3 a child of term2 by
// setting the parent and depth properties, and update all hidden fields.
$edit = [
$hidden_edit = [
'terms[tid:' . $term2->id() . ':0][term][tid]' => $term2->id(),
'terms[tid:' . $term2->id() . ':0][term][parent]' => 0,
'terms[tid:' . $term2->id() . ':0][term][depth]' => 0,
'terms[tid:' . $term2->id() . ':0][weight]' => 0,
'terms[tid:' . $term3->id() . ':0][term][tid]' => $term3->id(),
'terms[tid:' . $term3->id() . ':0][term][parent]' => $term2->id(),
'terms[tid:' . $term3->id() . ':0][term][depth]' => 1,
'terms[tid:' . $term3->id() . ':0][weight]' => 1,
'terms[tid:' . $term1->id() . ':0][term][tid]' => $term1->id(),
'terms[tid:' . $term1->id() . ':0][term][parent]' => 0,
'terms[tid:' . $term1->id() . ':0][term][depth]' => 0,
];
// Because we can't post hidden form elements, we have to change them in
// code here, and then submit.
foreach ($hidden_edit as $field => $value) {
$node = $assert->hiddenFieldExists($field);
$node->setValue($value);
}
// Edit non-hidden elements within drupalPostForm().
$edit = [
'terms[tid:' . $term2->id() . ':0][weight]' => 0,
'terms[tid:' . $term3->id() . ':0][weight]' => 1,
'terms[tid:' . $term1->id() . ':0][weight]' => 2,
];
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->drupalPostForm(NULL, $edit, 'Save');
$taxonomy_storage->resetCache();
$terms = $taxonomy_storage->loadTree($this->vocabulary->id());
@@ -570,7 +580,7 @@ class TermTest extends TaxonomyTestBase {
];
// Create the term.
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add', $edit, t('Save'));
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add', $edit, 'Save');
$terms = taxonomy_term_load_multiple_by_name($edit['name[0][value]']);
$term = reset($terms);
@@ -578,19 +588,19 @@ class TermTest extends TaxonomyTestBase {
// Check the breadcrumb on the term edit page.
$this->drupalGet('taxonomy/term/' . $term->id() . '/edit');
$breadcrumbs = $this->cssSelect('nav.breadcrumb ol li a');
$breadcrumbs = $this->getSession()->getPage()->findAll('css', 'nav.breadcrumb ol li a');
$this->assertIdentical(count($breadcrumbs), 2, 'The breadcrumbs are present on the page.');
$this->assertIdentical((string) $breadcrumbs[0], 'Home', 'First breadcrumb text is Home');
$this->assertIdentical((string) $breadcrumbs[1], $term->label(), 'Second breadcrumb text is term name on term edit page.');
$this->assertEscaped((string) $breadcrumbs[1], 'breadcrumbs displayed and escaped.');
$this->assertIdentical($breadcrumbs[0]->getText(), 'Home', 'First breadcrumb text is Home');
$this->assertIdentical($breadcrumbs[1]->getText(), $term->label(), 'Second breadcrumb text is term name on term edit page.');
$this->assertEscaped($breadcrumbs[1]->getText(), 'breadcrumbs displayed and escaped.');
// Check the breadcrumb on the term delete page.
$this->drupalGet('taxonomy/term/' . $term->id() . '/delete');
$breadcrumbs = $this->cssSelect('nav.breadcrumb ol li a');
$breadcrumbs = $this->getSession()->getPage()->findAll('css', 'nav.breadcrumb ol li a');
$this->assertIdentical(count($breadcrumbs), 2, 'The breadcrumbs are present on the page.');
$this->assertIdentical((string) $breadcrumbs[0], 'Home', 'First breadcrumb text is Home');
$this->assertIdentical((string) $breadcrumbs[1], $term->label(), 'Second breadcrumb text is term name on term delete page.');
$this->assertEscaped((string) $breadcrumbs[1], 'breadcrumbs displayed and escaped.');
$this->assertIdentical($breadcrumbs[0]->getText(), 'Home', 'First breadcrumb text is Home');
$this->assertIdentical($breadcrumbs[1]->getText(), $term->label(), 'Second breadcrumb text is term name on term delete page.');
$this->assertEscaped($breadcrumbs[1]->getText(), 'breadcrumbs displayed and escaped.');
}
}
@@ -1,9 +1,9 @@
<?php
namespace Drupal\taxonomy\Tests;
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\Core\Url;
use Drupal\system\Tests\Menu\AssertBreadcrumbTrait;
use Drupal\Tests\system\Functional\Menu\AssertBreadcrumbTrait;
/**
* Tests for proper breadcrumb translation.
@@ -2,7 +2,7 @@
namespace Drupal\Tests\taxonomy\Functional\Views;
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
use Drupal\taxonomy\Entity\Term;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\Tests\views_ui\Functional\UITestBase;
@@ -4,7 +4,7 @@ namespace Drupal\Tests\taxonomy\Functional\Views;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
use Drupal\Tests\views\Functional\ViewTestBase;
use Drupal\views\Tests\ViewTestData;
use Drupal\taxonomy\Entity\Vocabulary;
@@ -39,19 +39,21 @@ class MigrateVocabularyFieldInstanceTest extends MigrateDrupal6TestBase {
public function testVocabularyFieldInstance() {
$this->executeMigration('d6_vocabulary_field_instance');
// Test that the field exists.
// Test that the field exists. Tags has a multilingual option of 'None'.
$field_id = 'node.article.field_tags';
$field = FieldConfig::load($field_id);
$this->assertSame($field_id, $field->id(), 'Field instance exists on article bundle.');
$this->assertSame('Tags', $field->label());
$this->assertTrue($field->isRequired(), 'Field is required');
$this->assertFalse($field->isTranslatable());
// Test the page bundle as well.
// Test the page bundle as well. Tags has a multilingual option of 'None'.
$field_id = 'node.page.field_tags';
$field = FieldConfig::load($field_id);
$this->assertSame($field_id, $field->id(), 'Field instance exists on page bundle.');
$this->assertSame('Tags', $field->label());
$this->assertTrue($field->isRequired(), 'Field is required');
$this->assertFalse($field->isTranslatable());
$settings = $field->getSettings();
$this->assertSame('default:taxonomy_term', $settings['handler'], 'The handler plugin ID is correct.');
@@ -60,15 +62,32 @@ class MigrateVocabularyFieldInstanceTest extends MigrateDrupal6TestBase {
$this->assertSame(['node', 'article', 'field_tags'], $this->getMigration('d6_vocabulary_field_instance')->getIdMap()->lookupDestinationId([4, 'article']));
// Test the the field vocabulary_1_i_0_.
// Test the the field vocabulary_1_i_0_ with multilingual option,
// 'per language terms'.
$field_id = 'node.story.field_vocabulary_1_i_0_';
$field = FieldConfig::load($field_id);
$this->assertFalse($field->isRequired(), 'Field is not required');
$this->assertTrue($field->isTranslatable());
// Test the the field vocabulary_2_i_0_ with multilingual option,
// 'Set language to vocabulary'.
$field_id = 'node.story.field_vocabulary_2_i_1_';
$field = FieldConfig::load($field_id);
$this->assertFalse($field->isRequired(), 'Field is not required');
$this->assertFalse($field->isTranslatable());
// Test the the field vocabulary_3_i_0_ with multilingual option,
// 'Localize terms'.
$field_id = 'node.story.field_vocabulary_3_i_2_';
$field = FieldConfig::load($field_id);
$this->assertFalse($field->isRequired(), 'Field is not required');
$this->assertFalse($field->isTranslatable());
// Tests that a vocabulary named like a D8 base field will be migrated and
// prefixed with 'field_' to avoid conflicts.
$field_type = FieldConfig::load('node.sponsor.field_type');
$this->assertInstanceOf(FieldConfig::class, $field_type);
$this->assertFalse($field->isTranslatable());
}
/**
@@ -15,11 +15,15 @@ class MigrateTaxonomyTermTest extends MigrateDrupal7TestBase {
public static $modules = [
'comment',
'content_translation',
'datetime',
'forum',
'image',
'language',
'link',
'menu_ui',
// Required for translation migrations.
'migrate_drupal_multilingual',
'node',
'taxonomy',
'telephone',
@@ -38,16 +42,23 @@ class MigrateTaxonomyTermTest extends MigrateDrupal7TestBase {
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('comment');
$this->installEntitySchema('node');
$this->installEntitySchema('taxonomy_term');
$this->installConfig(static::$modules);
$this->executeMigrations([
'language',
'd7_user_role',
'd7_user',
'd7_node_type',
'd7_comment_type',
'd7_field',
'd7_taxonomy_vocabulary',
'd7_field_instance',
'd7_taxonomy_term',
'd7_entity_translation_settings',
'd7_taxonomy_term_entity_translation',
]);
}
@@ -110,7 +121,7 @@ class MigrateTaxonomyTermTest extends MigrateDrupal7TestBase {
$this->assertEntity(2, 'Term1 (This is a real field!)', 'test_vocabulary', 'The first term. (This is a real field!)', 'filtered_html', 0, [], NULL, 3);
$this->assertEntity(3, 'Term2', 'test_vocabulary', 'The second term.', 'filtered_html');
$this->assertEntity(4, 'Term3', 'test_vocabulary', 'The third term.', 'full_html', 0, [3], 6);
$this->assertEntity(4, 'Term3 in plain old English', 'test_vocabulary', 'The third term in plain old English.', 'full_html', 0, [3], 6);
$this->assertEntity(5, 'Custom Forum', 'forums', 'Where the cool kids are.', NULL, 3);
$this->assertEntity(6, 'Games', 'forums', '', NULL, 4, [], NULL, NULL, 1);
$this->assertEntity(7, 'Minecraft', 'forums', '', NULL, 1, [6]);
@@ -142,7 +153,7 @@ class MigrateTaxonomyTermTest extends MigrateDrupal7TestBase {
* Assert that a term is present in the tree storage, with the right parents.
*
* @param string $vid
* Vocabular ID.
* Vocabulary ID.
* @param int $tid
* ID of the term to check.
* @param array $parent_ids
@@ -162,4 +173,56 @@ class MigrateTaxonomyTermTest extends MigrateDrupal7TestBase {
$this->assertEquals($parent_ids, array_filter($term->parents), "Term $tid has correct parents in taxonomy tree");
}
/**
* Tests the migration of taxonomy term entity translations.
*/
public function testTaxonomyTermEntityTranslations() {
$manager = $this->container->get('content_translation.manager');
// Get the term and its translations.
$term = Term::load(4);
$term_fr = $term->getTranslation('fr');
$term_is = $term->getTranslation('is');
// Test that fields translated with Entity Translation are migrated.
$this->assertSame('Term3 in plain old English', $term->getName());
$this->assertSame('Term3 en français s\'il vous plaît', $term_fr->getName());
$this->assertSame('Term3 á íslensku', $term_is->getName());
$this->assertSame('The third term in plain old English.', $term->getDescription());
$this->assertSame('The third term en français s\'il vous plaît.', $term_fr->getDescription());
$this->assertSame('The third term á íslensku.', $term_is->getDescription());
$this->assertSame('full_html', $term->getFormat());
$this->assertSame('filtered_html', $term_fr->getFormat());
$this->assertSame('plain_text', $term_is->getFormat());
$this->assertSame('6', $term->field_integer->value);
$this->assertSame('5', $term_fr->field_integer->value);
$this->assertSame('4', $term_is->field_integer->value);
// Test that the French translation metadata is correctly migrated.
$metadata_fr = $manager->getTranslationMetadata($term_fr);
$this->assertTrue($metadata_fr->isPublished());
$this->assertSame('en', $metadata_fr->getSource());
$this->assertSame('2', $metadata_fr->getAuthor()->uid->value);
$this->assertSame('1531922267', $metadata_fr->getCreatedTime());
$this->assertSame('1531922268', $metadata_fr->getChangedTime());
$this->assertTrue($metadata_fr->isOutdated());
// Test that the Icelandic translation metadata is correctly migrated.
$metadata_is = $manager->getTranslationMetadata($term_is);
$this->assertFalse($metadata_is->isPublished());
$this->assertSame('en', $metadata_is->getSource());
$this->assertSame('1', $metadata_is->getAuthor()->uid->value);
$this->assertSame('1531922278', $metadata_is->getCreatedTime());
$this->assertSame('1531922279', $metadata_is->getChangedTime());
$this->assertFalse($metadata_is->isOutdated());
// Test that untranslatable properties are the same as the source language.
$this->assertSame($term->bundle(), $term_fr->bundle());
$this->assertSame($term->bundle(), $term_is->bundle());
$this->assertSame($term->getWeight(), $term_fr->getWeight());
$this->assertSame($term->getWeight(), $term_is->getWeight());
$this->assertSame($term->parent->terget_id, $term_fr->parent->terget_id);
$this->assertSame($term->parent->terget_id, $term_is->parent->terget_id);
}
}
@@ -0,0 +1,334 @@
<?php
namespace Drupal\Tests\taxonomy\Kernel\Plugin\migrate\source\d7;
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
/**
* Tests taxonomy term entity translation source plugin.
*
* @covers \Drupal\taxonomy\Plugin\migrate\source\d7\TermEntityTranslation
* @group taxonomy
*/
class TermEntityTranslationTest extends MigrateSqlSourceTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['taxonomy', 'migrate_drupal'];
/**
* {@inheritdoc}
*/
public function providerSource() {
$tests = [];
// The source data.
$tests[0]['source_data']['entity_translation'] = [
[
'entity_type' => 'taxonomy_term',
'entity_id' => 1,
'revision_id' => 1,
'language' => 'en',
'source' => '',
'uid' => 1,
'status' => 1,
'translate' => 0,
'created' => 1531343498,
'changed' => 1531343498,
],
[
'entity_type' => 'taxonomy_term',
'entity_id' => 1,
'revision_id' => 1,
'language' => 'fr',
'source' => 'en',
'uid' => 2,
'status' => 1,
'translate' => 1,
'created' => 1531343508,
'changed' => 1531343508,
],
[
'entity_type' => 'taxonomy_term',
'entity_id' => 1,
'revision_id' => 1,
'language' => 'es',
'source' => 'en',
'uid' => 1,
'status' => 0,
'translate' => 0,
'created' => 1531343528,
'changed' => 1531343528,
],
];
$tests[0]['source_data']['field_config'] = [
[
'id' => 1,
'field_name' => 'field_test',
'type' => 'text',
'module' => 'text',
'active' => 1,
'storage_type' => 'field_sql_storage',
'storage_module' => 'field_sql_storage',
'storage_active' => 1,
'locked' => 1,
'data' => 'a:0:{}',
'cardinality' => 1,
'translatable' => 1,
'deleted' => 0,
],
[
'id' => 2,
'field_name' => 'name_field',
'type' => 'text',
'module' => 'text',
'active' => 1,
'storage_type' => 'field_sql_storage',
'storage_module' => 'field_sql_storage',
'storage_active' => 1,
'locked' => 1,
'data' => 'a:0:{}',
'cardinality' => 1,
'translatable' => 1,
'deleted' => 0,
],
[
'id' => 3,
'field_name' => 'description_field',
'type' => 'text',
'module' => 'text',
'active' => 1,
'storage_type' => 'field_sql_storage',
'storage_module' => 'field_sql_storage',
'storage_active' => 1,
'locked' => 1,
'data' => 'a:0:{}',
'cardinality' => 1,
'translatable' => 1,
'deleted' => 0,
],
];
$tests[0]['source_data']['field_config_instance'] = [
[
'id' => '1',
'field_id' => 1,
'field_name' => 'field_test',
'entity_type' => 'taxonomy_term',
'bundle' => 'tags',
'data' => 'a:0:{}',
'deleted' => 0,
],
[
'id' => 2,
'field_id' => 2,
'field_name' => 'name_field',
'entity_type' => 'taxonomy_term',
'bundle' => 'tags',
'data' => 'a:0:{}',
'deleted' => 0,
],
[
'id' => 3,
'field_id' => 3,
'field_name' => 'description_field',
'entity_type' => 'taxonomy_term',
'bundle' => 'tags',
'data' => 'a:0:{}',
'deleted' => 0,
],
];
$tests[0]['source_data']['field_data_field_test'] = [
[
'entity_type' => 'taxonomy_term',
'bundle' => 'tags',
'deleted' => 0,
'entity_id' => 1,
'revision_id' => 1,
'language' => 'en',
'delta' => 0,
'field_test_value' => 'English field',
'field_test_format' => 'filtered_html',
],
[
'entity_type' => 'taxonomy_term',
'bundle' => 'tags',
'deleted' => 0,
'entity_id' => 1,
'revision_id' => 1,
'language' => 'fr',
'delta' => 0,
'field_test_value' => 'French field',
'field_test_format' => 'filtered_html',
],
[
'entity_type' => 'taxonomy_term',
'bundle' => 'tags',
'deleted' => 0,
'entity_id' => 1,
'revision_id' => 1,
'language' => 'es',
'delta' => 0,
'field_test_value' => 'Spanish field',
'field_test_format' => 'filtered_html',
],
];
$tests[0]['source_data']['field_data_name_field'] = [
[
'entity_type' => 'taxonomy_term',
'bundle' => 'tags',
'deleted' => '0',
'entity_id' => '1',
'revision_id' => '1',
'language' => 'en',
'delta' => '0',
'name_field_value' => 'Term Name EN',
'name_field_format' => NULL,
],
[
'entity_type' => 'taxonomy_term',
'bundle' => 'tags',
'deleted' => '0',
'entity_id' => '1',
'revision_id' => '1',
'language' => 'fr',
'delta' => '0',
'name_field_value' => 'Term Name FR',
'name_field_format' => NULL,
],
[
'entity_type' => 'taxonomy_term',
'bundle' => 'tags',
'deleted' => '0',
'entity_id' => '1',
'revision_id' => '1',
'language' => 'es',
'delta' => '0',
'name_field_value' => 'Term Name ES',
'name_field_format' => NULL,
],
];
$tests[0]['source_data']['field_data_description_field'] = [
[
'entity_type' => 'taxonomy_term',
'bundle' => 'tags',
'deleted' => '0',
'entity_id' => '1',
'revision_id' => '1',
'language' => 'en',
'delta' => '0',
'description_field_value' => 'Term Description EN',
'description_field_format' => 'full_html',
],
[
'entity_type' => 'taxonomy_term',
'bundle' => 'tags',
'deleted' => '0',
'entity_id' => '1',
'revision_id' => '1',
'language' => 'fr',
'delta' => '0',
'description_field_value' => 'Term Description FR',
'description_field_format' => 'full_html',
],
[
'entity_type' => 'taxonomy_term',
'bundle' => 'tags',
'deleted' => '0',
'entity_id' => '1',
'revision_id' => '1',
'language' => 'es',
'delta' => '0',
'description_field_value' => 'Term Description ES',
'description_field_format' => 'full_html',
],
];
$tests[0]['source_data']['system'] = [
[
'name' => 'title',
'type' => 'module',
'status' => 1,
],
];
$tests[0]['source_data']['taxonomy_term_data'] = [
[
'tid' => 1,
'vid' => 1,
'name' => 'Term Name',
'description' => 'Term Description',
'format' => 'filtered_html',
'weight' => 0,
],
];
$tests[0]['source_data']['taxonomy_term_hierarchy'] = [
[
'tid' => 1,
'parent' => 0,
],
];
$tests[0]['source_data']['taxonomy_vocabulary'] = [
[
'vid' => 1,
'name' => 'Tags',
'machine_name' => 'tags',
'description' => '',
'hierarchy' => 0,
'module' => 'taxonomy',
'weight' => 0,
],
];
// The expected results.
$tests[0]['expected_data'] = [
[
'entity_type' => 'taxonomy_term',
'entity_id' => 1,
'revision_id' => 1,
'language' => 'fr',
'source' => 'en',
'uid' => 2,
'status' => 1,
'translate' => 1,
'created' => 1531343508,
'changed' => 1531343508,
'name' => 'Term Name FR',
'description' => 'Term Description FR',
'format' => 'full_html',
'machine_name' => 'tags',
'is_container' => FALSE,
'field_test' => [
[
'value' => 'French field',
'format' => 'filtered_html',
],
],
],
[
'entity_type' => 'taxonomy_term',
'entity_id' => 1,
'revision_id' => 1,
'language' => 'es',
'source' => 'en',
'uid' => 1,
'status' => 0,
'translate' => 0,
'created' => 1531343528,
'changed' => 1531343528,
'name' => 'Term Name ES',
'description' => 'Term Description ES',
'format' => 'full_html',
'machine_name' => 'tags',
'is_container' => FALSE,
'field_test' => [
[
'value' => 'Spanish field',
'format' => 'filtered_html',
],
],
],
];
return $tests;
}
}
@@ -254,6 +254,10 @@ class TermTest extends MigrateSqlSourceTestBase {
'name' => 'forum_containers',
'value' => 'a:3:{i:0;s:1:"5";i:1;s:1:"6";i:2;s:1:"7";}',
],
[
'name' => 'language_default',
'value' => 'O:8:"stdClass":1:{s:8:"language";s:2:"en";}',
],
];
// The expected results.
@@ -265,6 +269,7 @@ class TermTest extends MigrateSqlSourceTestBase {
'description' => 'description value 1 (description_field)',
'weight' => 0,
'parent' => [0],
'language' => 'en',
],
[
'tid' => 2,
@@ -273,6 +278,7 @@ class TermTest extends MigrateSqlSourceTestBase {
'description' => 'description value 2',
'weight' => 0,
'parent' => [0],
'language' => 'en',
],
[
'tid' => 3,
@@ -281,6 +287,7 @@ class TermTest extends MigrateSqlSourceTestBase {
'description' => 'description value 3',
'weight' => 0,
'parent' => [0],
'language' => 'en',
],
[
'tid' => 4,
@@ -289,6 +296,7 @@ class TermTest extends MigrateSqlSourceTestBase {
'description' => 'description value 4 (description_field)',
'weight' => 1,
'parent' => [1],
'language' => 'en',
],
[
'tid' => 5,
@@ -297,6 +305,7 @@ class TermTest extends MigrateSqlSourceTestBase {
'description' => 'description value 5',
'weight' => 1,
'parent' => [2],
'language' => 'en',
],
[
'tid' => 6,
@@ -305,6 +314,7 @@ class TermTest extends MigrateSqlSourceTestBase {
'description' => 'description value 6',
'weight' => 0,
'parent' => [3, 2],
'language' => 'en',
],
[
'tid' => 7,
@@ -313,6 +323,7 @@ class TermTest extends MigrateSqlSourceTestBase {
'description' => 'description value 7',
'weight' => 0,
'parent' => [0],
'language' => 'en',
],
];
@@ -330,6 +341,7 @@ class TermTest extends MigrateSqlSourceTestBase {
'description' => 'description value 1 (description_field)',
'weight' => 0,
'parent' => [0],
'language' => 'en',
],
[
'tid' => 4,
@@ -338,6 +350,7 @@ class TermTest extends MigrateSqlSourceTestBase {
'description' => 'description value 4 (description_field)',
'weight' => 1,
'parent' => [1],
'language' => 'en',
],
];
$tests[1]['expected_count'] = NULL;
@@ -4,7 +4,7 @@ namespace Drupal\Tests\taxonomy\Kernel\Views;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
use Drupal\Tests\node\Traits\NodeCreationTrait;
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;