Update to Drupal 8.2.2. For more information, see https://www.drupal.org/project/drupal/releases/8.2.2

This commit is contained in:
Pantheon Automation 2016-11-02 11:43:31 -07:00 committed by Greg Anderson
parent 23ffed3665
commit 507b45a0ed
378 changed files with 11434 additions and 5542 deletions

View file

@ -73,13 +73,13 @@ class Vocabulary extends ConfigEntityBundleBase implements VocabularyInterface {
* The type of hierarchy allowed within the vocabulary.
*
* Possible values:
* - TAXONOMY_HIERARCHY_DISABLED: No parents.
* - TAXONOMY_HIERARCHY_SINGLE: Single parent.
* - TAXONOMY_HIERARCHY_MULTIPLE: Multiple parents.
* - VocabularyInterface::HIERARCHY_DISABLED: No parents.
* - VocabularyInterface::HIERARCHY_SINGLE: Single parent.
* - VocabularyInterface::HIERARCHY_MULTIPL: Multiple parents.
*
* @var int
*/
protected $hierarchy = TAXONOMY_HIERARCHY_DISABLED;
protected $hierarchy = VocabularyInterface::HIERARCHY_DISABLED;
/**
* The weight of this vocabulary in relation to other vocabularies.

View file

@ -223,7 +223,7 @@ class OverviewTerms extends FormBase {
'#title' => $term->getName(),
'#url' => $term->urlInfo(),
);
if ($taxonomy_vocabulary->getHierarchy() != TAXONOMY_HIERARCHY_MULTIPLE && count($tree) > 1) {
if ($taxonomy_vocabulary->getHierarchy() != VocabularyInterface::HIERARCHY_MULTIPLE && count($tree) > 1) {
$parent_fields = TRUE;
$form['terms'][$key]['term']['tid'] = array(
'#type' => 'hidden',
@ -340,7 +340,7 @@ class OverviewTerms extends FormBase {
'group' => 'term-weight',
);
if ($taxonomy_vocabulary->getHierarchy() != TAXONOMY_HIERARCHY_MULTIPLE && count($tree) > 1) {
if ($taxonomy_vocabulary->getHierarchy() != VocabularyInterface::HIERARCHY_MULTIPLE && count($tree) > 1) {
$form['actions'] = array('#type' => 'actions', '#tree' => FALSE);
$form['actions']['submit'] = array(
'#type' => 'submit',
@ -382,7 +382,7 @@ class OverviewTerms extends FormBase {
$vocabulary = $form_state->get(['taxonomy', 'vocabulary']);
// Update the current hierarchy type as we go.
$hierarchy = TAXONOMY_HIERARCHY_DISABLED;
$hierarchy = VocabularyInterface::HIERARCHY_DISABLED;
$changed_terms = array();
$tree = $this->storageController->loadTree($vocabulary->id(), 0, NULL, TRUE);
@ -400,7 +400,7 @@ class OverviewTerms extends FormBase {
$changed_terms[$term->id()] = $term;
}
$weight++;
$hierarchy = $term->parents[0] != 0 ? TAXONOMY_HIERARCHY_SINGLE : $hierarchy;
$hierarchy = $term->parents[0] != 0 ? VocabularyInterface::HIERARCHY_SINGLE : $hierarchy;
$term = $tree[$weight];
}
@ -427,7 +427,7 @@ class OverviewTerms extends FormBase {
$term->parent->target_id = $values['term']['parent'];
$changed_terms[$term->id()] = $term;
}
$hierarchy = $term->parents[0] != 0 ? TAXONOMY_HIERARCHY_SINGLE : $hierarchy;
$hierarchy = $term->parents[0] != 0 ? VocabularyInterface::HIERARCHY_SINGLE : $hierarchy;
$weight++;
}
}
@ -440,7 +440,7 @@ class OverviewTerms extends FormBase {
$term->setWeight($weight);
$changed_terms[$term->id()] = $term;
}
$hierarchy = $term->parents[0] != 0 ? TAXONOMY_HIERARCHY_SINGLE : $hierarchy;
$hierarchy = $term->parents[0] != 0 ? VocabularyInterface::HIERARCHY_SINGLE : $hierarchy;
}
// Save all updated terms.

View file

@ -49,6 +49,7 @@ class TermSelection extends DefaultSelection {
*/
public function getReferenceableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0) {
if ($match || $limit) {
$this->configuration['handler_settings']['sort'] = ['field' => 'name', 'direction' => 'asc'];
return parent::getReferenceableEntities($match, $match_operator, $limit);
}

View file

@ -26,7 +26,7 @@ class TermForm extends ContentEntityForm {
$form['relations'] = array(
'#type' => 'details',
'#title' => $this->t('Relations'),
'#open' => $vocabulary->getHierarchy() == TAXONOMY_HIERARCHY_MULTIPLE,
'#open' => $vocabulary->getHierarchy() == VocabularyInterface::HIERARCHY_MULTIPLE,
'#weight' => 10,
);
@ -152,8 +152,8 @@ class TermForm extends ContentEntityForm {
}
// If we've increased the number of parents and this is a single or flat
// hierarchy, update the vocabulary immediately.
elseif ($current_parent_count > $previous_parent_count && $vocabulary->getHierarchy() != TAXONOMY_HIERARCHY_MULTIPLE) {
$vocabulary->setHierarchy($current_parent_count == 1 ? TAXONOMY_HIERARCHY_SINGLE : TAXONOMY_HIERARCHY_MULTIPLE);
elseif ($current_parent_count > $previous_parent_count && $vocabulary->getHierarchy() != VocabularyInterface::HIERARCHY_MULTIPLE) {
$vocabulary->setHierarchy($current_parent_count == 1 ? VocabularyInterface::HIERARCHY_SINGLE : VocabularyInterface::HIERARCHY_MULTIPLE);
$vocabulary->save();
}

View file

@ -0,0 +1,204 @@
<?php
namespace Drupal\taxonomy\Tests;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Tests the autocomplete implementation of the taxonomy class.
*
* @group taxonomy
*/
class TermAutocompleteTest extends TaxonomyTestBase {
/**
* The vocabulary.
*
* @var \Drupal\taxonomy\Entity\Vocabulary
*/
protected $vocabulary;
/**
* The field to add to the content type for the taxonomy terms.
*
* @var string
*/
protected $fieldName;
/**
* The admin user.
*
* @var \Drupal\user\Entity\User
*/
protected $adminUser;
/**
* The autocomplete URL to call.
*
* @var string
*/
protected $autocompleteUrl;
/**
* The term IDs indexed by term names.
*
* @var array
*/
protected $termIds;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Create a vocabulary.
$this->vocabulary = $this->createVocabulary();
// Create 11 terms, which have some sub-string in common, in a
// non-alphabetical order, so that we will have more than 10 matches later
// when we test the correct number of results is returned, and we can test
// the order of the results. The location of the sub-string to match varies
// also, since it should not be necessary to start with the sub-string to
// match it. Save term IDs to reuse later.
$termNames = [
'aaa 20 bbb',
'aaa 70 bbb',
'aaa 10 bbb',
'aaa 12 bbb',
'aaa 40 bbb',
'aaa 11 bbb',
'aaa 30 bbb',
'aaa 50 bbb',
'aaa 80',
'aaa 90',
'bbb 60 aaa',
];
foreach ($termNames as $termName) {
$term = $this->createTerm($this->vocabulary, ['name' => $termName]);
$this->termIds[$termName] = $term->id();
}
// Create a taxonomy_term_reference field on the article Content Type that
// uses a taxonomy_autocomplete widget.
$this->fieldName = Unicode::strtolower($this->randomMachineName());
FieldStorageConfig::create([
'field_name' => $this->fieldName,
'entity_type' => 'node',
'type' => 'entity_reference',
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
'settings' => [
'target_type' => 'taxonomy_term',
],
])->save();
FieldConfig::create([
'field_name' => $this->fieldName,
'bundle' => 'article',
'entity_type' => 'node',
'settings' => [
'handler' => 'default',
'handler_settings' => [
// Restrict selection of terms to a single vocabulary.
'target_bundles' => [
$this->vocabulary->id() => $this->vocabulary->id(),
],
],
],
])->save();
EntityFormDisplay::load('node.article.default')
->setComponent($this->fieldName, [
'type' => 'entity_reference_autocomplete',
])
->save();
EntityViewDisplay::load('node.article.default')
->setComponent($this->fieldName, [
'type' => 'entity_reference_label',
])
->save();
// Create a user and then login.
$this->adminUser = $this->drupalCreateUser(['create article content']);
$this->drupalLogin($this->adminUser);
// 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']);
}
/**
* Tests that the autocomplete method returns the good number of results.
*
* @see \Drupal\taxonomy\Controller\TermAutocompleteController::autocomplete()
*/
public function testAutocompleteCountResults() {
// Test that no matching term found.
$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(
$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(
$this->autocompleteUrl,
['query' => ['q' => 'aaa 1']]
);
$this->assertEqual(3, count($data), 'Autocomplete returned 3 results');
// Tests that only 10 results are returned, even if there are more than 10
// matches.
$data = $this->drupalGetJSON(
$this->autocompleteUrl,
['query' => ['q' => 'aaa']]
);
$this->assertEqual(10, count($data), 'Autocomplete returned only 10 results (for over 10 matches)');
}
/**
* Tests that the autocomplete method returns properly ordered results.
*
* @see \Drupal\taxonomy\Controller\TermAutocompleteController::autocomplete()
*/
public function testAutocompleteOrderedResults() {
$expectedResults = [
'aaa 10 bbb',
'aaa 11 bbb',
'aaa 12 bbb',
'aaa 20 bbb',
'aaa 30 bbb',
'aaa 40 bbb',
'aaa 50 bbb',
'aaa 70 bbb',
'bbb 60 aaa',
];
// Build $expected to match the autocomplete results.
$expected = [];
foreach ($expectedResults as $termName) {
$expected[] = [
'value' => $termName . ' (' . $this->termIds[$termName] . ')',
'label' => $termName
];
}
$data = $this->drupalGetJSON(
$this->autocompleteUrl,
['query' => ['q' => 'bbb']]
);
$this->assertIdentical($expected, $data);
}
}

View file

@ -9,6 +9,21 @@ use Drupal\Core\Config\Entity\ConfigEntityInterface;
*/
interface VocabularyInterface extends ConfigEntityInterface {
/**
* Denotes that no term in the vocabulary has a parent.
*/
const HIERARCHY_DISABLED = 0;
/**
* Denotes that one or more terms in the vocabulary has a single parent.
*/
const HIERARCHY_SINGLE = 1;
/**
* Denotes that one or more terms in the vocabulary have multiple parents.
*/
const HIERARCHY_MULTIPLE = 2;
/**
* Returns the vocabulary hierarchy.
*
@ -23,9 +38,9 @@ interface VocabularyInterface extends ConfigEntityInterface {
* @param int $hierarchy
* The hierarchy type of vocabulary.
* Possible values:
* - TAXONOMY_HIERARCHY_DISABLED: No parents.
* - TAXONOMY_HIERARCHY_SINGLE: Single parent.
* - TAXONOMY_HIERARCHY_MULTIPLE: Multiple parents.
* - VocabularyInterface::HIERARCHY_DISABLED: No parents.
* - VocabularyInterface::HIERARCHY_SINGLE: Single parent.
* - VocabularyInterface::HIERARCHY_MULTIPLE: Multiple parents.
*
* @return $this
*/

View file

@ -19,16 +19,25 @@ use Drupal\taxonomy\VocabularyInterface;
/**
* Denotes that no term in the vocabulary has a parent.
*
* @deprecated in Drupal 8.2.x and will be removed before 9.0.0. Use
* \Drupal\taxonomy\VocabularyInterface::HIERARCHY_DISABLED instead.
*/
const TAXONOMY_HIERARCHY_DISABLED = 0;
/**
* Denotes that one or more terms in the vocabulary has a single parent.
*
* @deprecated in Drupal 8.2.x and will be removed before 9.0.0. Use
* \Drupal\taxonomy\VocabularyInterface::HIERARCHY_SINGLE instead.
*/
const TAXONOMY_HIERARCHY_SINGLE = 1;
/**
* Denotes that one or more terms in the vocabulary have multiple parents.
*
* @deprecated in Drupal 8.2.x and will be removed before 9.0.0. Use
* \Drupal\taxonomy\VocabularyInterface::HIERARCHY_MULTIPLE instead.
*/
const TAXONOMY_HIERARCHY_MULTIPLE = 2;
@ -67,11 +76,11 @@ function taxonomy_help($route_name, RouteMatchInterface $route_match) {
case 'entity.taxonomy_vocabulary.overview_form':
$vocabulary = $route_match->getParameter('taxonomy_vocabulary');
switch ($vocabulary->getHierarchy()) {
case TAXONOMY_HIERARCHY_DISABLED:
case VocabularyInterface::HIERARCHY_DISABLED:
return '<p>' . t('You can reorganize the terms in %capital_name using their drag-and-drop handles, and group terms under a parent term by sliding them under and to the right of the parent.', array('%capital_name' => Unicode::ucfirst($vocabulary->label()), '%name' => $vocabulary->label())) . '</p>';
case TAXONOMY_HIERARCHY_SINGLE:
case VocabularyInterface::HIERARCHY_SINGLE:
return '<p>' . t('%capital_name contains terms grouped under parent terms. You can reorganize the terms in %capital_name using their drag-and-drop handles.', array('%capital_name' => Unicode::ucfirst($vocabulary->label()), '%name' => $vocabulary->label())) . '</p>';
case TAXONOMY_HIERARCHY_MULTIPLE:
case VocabularyInterface::HIERARCHY_MULTIPLE:
return '<p>' . t('%capital_name contains terms with multiple parents. Drag and drop of terms with multiple parents is not supported, but you can re-enable drag-and-drop support by editing each term to include only a single parent.', array('%capital_name' => Unicode::ucfirst($vocabulary->label()))) . '</p>';
}
}
@ -134,10 +143,11 @@ function taxonomy_theme() {
* Checks the current parents of all terms in a vocabulary and updates the
* vocabulary's hierarchy setting to the lowest possible level. If no term
* has parent terms then the vocabulary will be given a hierarchy of
* TAXONOMY_HIERARCHY_DISABLED. If any term has a single parent then the
* vocabulary will be given a hierarchy of TAXONOMY_HIERARCHY_SINGLE. If any
* term has multiple parents then the vocabulary will be given a hierarchy of
* TAXONOMY_HIERARCHY_MULTIPLE.
* VocabularyInterface::HIERARCHY_DISABLED. If any term has a single parent then
* the vocabulary will be given a hierarchy of
* VocabularyInterface::HIERARCHY_SINGLE. If any term has multiple parents then
* the vocabulary will be given a hierarchy of
* VocabularyInterface::HIERARCHY_MULTIPLE.
*
* @param \Drupal\taxonomy\VocabularyInterface $vocabulary
* A taxonomy vocabulary entity.
@ -149,7 +159,7 @@ function taxonomy_theme() {
*/
function taxonomy_check_vocabulary_hierarchy(VocabularyInterface $vocabulary, $changed_term) {
$tree = \Drupal::entityManager()->getStorage('taxonomy_term')->loadTree($vocabulary->id());
$hierarchy = TAXONOMY_HIERARCHY_DISABLED;
$hierarchy = VocabularyInterface::HIERARCHY_DISABLED;
foreach ($tree as $term) {
// Update the changed term with the new parent value before comparison.
if ($term->tid == $changed_term['tid']) {
@ -158,11 +168,11 @@ function taxonomy_check_vocabulary_hierarchy(VocabularyInterface $vocabulary, $c
}
// Check this term's parent count.
if (count($term->parents) > 1) {
$hierarchy = TAXONOMY_HIERARCHY_MULTIPLE;
$hierarchy = VocabularyInterface::HIERARCHY_MULTIPLE;
break;
}
elseif (count($term->parents) == 1 && !isset($term->parents[0])) {
$hierarchy = TAXONOMY_HIERARCHY_SINGLE;
$hierarchy = VocabularyInterface::HIERARCHY_SINGLE;
}
}
if ($hierarchy != $vocabulary->getHierarchy()) {

View file

@ -0,0 +1,19 @@
<?php
namespace Drupal\vocabulary_serialization_test;
use Drupal\Core\Cache\CacheableResponse;
use Drupal\taxonomy\VocabularyInterface;
class VocabularyResponse extends CacheableResponse {
/**
* @var \Drupal\taxonomy\VocabularyInterface
*/
protected $vocabulary;
public function setVocabulary(VocabularyInterface $vocabulary) {
$this->vocabulary = $vocabulary;
}
}

View file

@ -0,0 +1,15 @@
<?php
namespace Drupal\vocabulary_serialization_test;
use Drupal\taxonomy\VocabularyInterface;
class VocabularySerializationTestController {
public function vocabularyResponse(VocabularyInterface $taxonomy_vocabulary) {
$response = new VocabularyResponse('this is the output');
$response->setVocabulary($taxonomy_vocabulary);
return $response;
}
}

View file

@ -0,0 +1,7 @@
name: 'Vocabulary serialization test'
type: module
package: Testing
version: VERSION
core: 8.x
dependencies:
- taxonomy

View file

@ -0,0 +1,6 @@
vocabulary_serialization_test:
path: '/vocabulary_serialization_test/{taxonomy_vocabulary}'
defaults:
_controller: 'Drupal\vocabulary_serialization_test\VocabularySerializationTestController::vocabularyResponse'
requirements:
_access: 'TRUE'

View file

@ -0,0 +1,47 @@
<?php
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\Tests\BrowserTestBase;
/**
* Regression test for https://www.drupal.org/node/2807263.
*
* When a Vocabulary entity is unserialized before the modules have been loaded
* (which happens in the KernelPreHandle Stack middleware), then the constants
* that the Vocabulary entity uses are not yet available because they are set in
* taxonomy.module. This means that for example the PageCache middleware cannot
* load any cached Vocabulary entity, because unserialization will fail.
*
* @group taxonomy
*/
class VocabularySerializationTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['taxonomy', 'vocabulary_serialization_test'];
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
Vocabulary::create(['vid' => 'test'])->save();
}
public function testSerialization() {
$this->drupalGet('/vocabulary_serialization_test/test');
$this->assertSession()->statusCodeEquals(200);
$this->assertSame('this is the output', $this->getSession()->getPage()->getContent());
$this->assertSession()->responseHeaderEquals('X-Drupal-Cache', 'MISS');
$this->drupalGet('/vocabulary_serialization_test/test');
$this->assertSession()->statusCodeEquals(200);
$this->assertSame('this is the output', $this->getSession()->getPage()->getContent());
$this->assertSession()->responseHeaderEquals('X-Drupal-Cache', 'HIT');
}
}

View file

@ -54,9 +54,9 @@ class MigrateTaxonomyVocabularyTest extends MigrateDrupal7TestBase {
* Tests the Drupal 7 taxonomy vocabularies to Drupal 8 migration.
*/
public function testTaxonomyVocabulary() {
$this->assertEntity('tags', 'Tags', 'Use tags to group articles on similar topics into categories.', TAXONOMY_HIERARCHY_DISABLED, 0);
$this->assertEntity('forums', 'Forums', 'Forum navigation vocabulary', TAXONOMY_HIERARCHY_SINGLE, -10);
$this->assertEntity('test_vocabulary', 'Test Vocabulary', 'This is the vocabulary description', TAXONOMY_HIERARCHY_SINGLE, 0);
$this->assertEntity('tags', 'Tags', 'Use tags to group articles on similar topics into categories.', VocabularyInterface::HIERARCHY_DISABLED, 0);
$this->assertEntity('forums', 'Forums', 'Forum navigation vocabulary', VocabularyInterface::HIERARCHY_SINGLE, -10);
$this->assertEntity('test_vocabulary', 'Test Vocabulary', 'This is the vocabulary description', VocabularyInterface::HIERARCHY_SINGLE, 0);
}
}

View file

@ -0,0 +1,56 @@
<?php
namespace Drupal\Tests\taxonomy\Kernel\Plugin\migrate\source;
/**
* Tests the taxonomy term source with vocabulary filter.
*
* @covers \Drupal\taxonomy\Plugin\migrate\source\Term
* @group taxonomy
*/
class TermSourceWithVocabularyFilterTest extends TermTest {
/**
* {@inheritdoc}
*/
public static $modules = ['taxonomy', 'migrate_drupal'];
/**
* {@inheritdoc}
*/
public function providerSource() {
// Get the source data from parent.
$tests = parent::providerSource();
// The expected results.
$tests[0]['expected_data'] = [
[
'tid' => 1,
'vid' => 5,
'name' => 'name value 1',
'description' => 'description value 1',
'weight' => 0,
'parent' => [0],
],
[
'tid' => 4,
'vid' => 5,
'name' => 'name value 4',
'description' => 'description value 4',
'weight' => 1,
'parent' => [1],
],
];
// We know there are two rows with vid == 5.
$tests[0]['expected_count'] = 2;
// Set up source plugin configuration.
$tests[0]['configuration'] = [
'vocabulary' => [5],
];
return $tests;
}
}

View file

@ -0,0 +1,157 @@
<?php
namespace Drupal\Tests\taxonomy\Kernel\Plugin\migrate\source;
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
/**
* Tests taxonomy term source plugin.
*
* @covers \Drupal\taxonomy\Plugin\migrate\source\Term
* @group taxonomy
*/
class TermTest extends MigrateSqlSourceTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['taxonomy', 'migrate_drupal'];
/**
* {@inheritdoc}
*/
public function providerSource() {
$tests = [];
// The source data.
$tests[0]['source_data']['term_data'] = [
[
'tid' => 1,
'vid' => 5,
'name' => 'name value 1',
'description' => 'description value 1',
'weight' => 0,
],
[
'tid' => 2,
'vid' => 6,
'name' => 'name value 2',
'description' => 'description value 2',
'weight' => 0,
],
[
'tid' => 3,
'vid' => 6,
'name' => 'name value 3',
'description' => 'description value 3',
'weight' => 0,
],
[
'tid' => 4,
'vid' => 5,
'name' => 'name value 4',
'description' => 'description value 4',
'weight' => 1,
],
[
'tid' => 5,
'vid' => 6,
'name' => 'name value 5',
'description' => 'description value 5',
'weight' => 1,
],
[
'tid' => 6,
'vid' => 6,
'name' => 'name value 6',
'description' => 'description value 6',
'weight' => 0,
],
];
$tests[0]['source_data']['term_hierarchy'] = [
[
'tid' => 1,
'parent' => 0,
],
[
'tid' => 2,
'parent' => 0,
],
[
'tid' => 3,
'parent' => 0,
],
[
'tid' => 4,
'parent' => 1,
],
[
'tid' => 5,
'parent' => 2,
],
[
'tid' => 6,
'parent' => 3,
],
[
'tid' => 6,
'parent' => 2,
],
];
// The expected results.
$tests[0]['expected_data'] = [
[
'tid' => 1,
'vid' => 5,
'name' => 'name value 1',
'description' => 'description value 1',
'weight' => 0,
'parent' => [0],
],
[
'tid' => 2,
'vid' => 6,
'name' => 'name value 2',
'description' => 'description value 2',
'weight' => 0,
'parent' => [0],
],
[
'tid' => 3,
'vid' => 6,
'name' => 'name value 3',
'description' => 'description value 3',
'weight' => 0,
'parent' => [0],
],
[
'tid' => 4,
'vid' => 5,
'name' => 'name value 4',
'description' => 'description value 4',
'weight' => 1,
'parent' => [1],
],
[
'tid' => 5,
'vid' => 6,
'name' => 'name value 5',
'description' => 'description value 5',
'weight' => 1,
'parent' => [2],
],
[
'tid' => 6,
'vid' => 6,
'name' => 'name value 6',
'description' => 'description value 6',
'weight' => 0,
'parent' => [3, 2],
],
];
return $tests;
}
}

View file

@ -1,59 +1,48 @@
<?php
namespace Drupal\Tests\taxonomy\Unit\Migrate\d6;
namespace Drupal\Tests\taxonomy\Kernel\Plugin\migrate\source\d6;
use Drupal\taxonomy\Plugin\migrate\source\d6\TermNode;
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
/**
* Tests d6_term_node source plugin.
*
* @covers \Drupal\taxonomy\Plugin\migrate\source\d6\TermNode
* @group taxonomy
*/
class TermNodeTest extends MigrateSqlSourceTestCase {
const PLUGIN_CLASS = TermNode::class;
protected $migrationConfiguration = array(
'id' => 'test',
'source' => array(
'plugin' => 'd6_term_node',
'vid' => 3,
),
);
protected $expectedResults = array(
array(
'nid' => 1,
'vid' => 1,
'type' => 'story',
'tid' => array(1, 4, 5),
),
);
class TermNodeTest extends MigrateSqlSourceTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->databaseContents['term_node'] = array(
array(
public static $modules = ['taxonomy', 'migrate_drupal'];
/**
* {@inheritdoc}
*/
public function providerSource() {
$tests = [];
// The source data.
$tests[0]['source_data']['term_node'] = [
[
'nid' => '1',
'vid' => '1',
'tid' => '1',
),
array(
],
[
'nid' => '1',
'vid' => '1',
'tid' => '4',
),
array(
],
[
'nid' => '1',
'vid' => '1',
'tid' => '5',
),
);
$this->databaseContents['node'] = array(
array(
],
];
$tests[0]['source_data']['node'] = [
[
'nid' => '1',
'vid' => '1',
'type' => 'story',
@ -69,32 +58,51 @@ class TermNodeTest extends MigrateSqlSourceTestCase {
'sticky' => '0',
'tnid' => '0',
'translate' => '0',
),
);
$this->databaseContents['term_data'] = array(
array(
],
];
$tests[0]['source_data']['term_data'] = [
[
'tid' => '1',
'vid' => '3',
'name' => 'term 1 of vocabulary 3',
'description' => 'description of term 1 of vocabulary 3',
'weight' => '0',
),
array(
],
[
'tid' => '4',
'vid' => '3',
'name' => 'term 4 of vocabulary 3',
'description' => 'description of term 4 of vocabulary 3',
'weight' => '6',
),
array(
],
[
'tid' => '5',
'vid' => '3',
'name' => 'term 5 of vocabulary 3',
'description' => 'description of term 5 of vocabulary 3',
'weight' => '7',
),
);
parent::setUp();
],
];
// The expected results.
$tests[0]['expected_data'] = [
[
'nid' => 1,
'vid' => 1,
'type' => 'story',
'tid' => [1, 4, 5],
],
];
// Set default value for expected count.
$tests[0]['expected_count'] = NULL;
// Set plugin configuration.
$tests[0]['configuration'] = [
'vid' => 3,
];
return $tests;
}
}

View file

@ -0,0 +1,108 @@
<?php
namespace Drupal\Tests\taxonomy\Kernel\Plugin\migrate\source\d6;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
/**
* Tests D6 vocabulary source plugin.
*
* @covers \Drupal\taxonomy\Plugin\migrate\source\d6\Vocabulary
* @group taxonomy
*/
class VocabularyTest extends MigrateSqlSourceTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['taxonomy', 'migrate_drupal'];
/**
* {@inheritdoc}
*/
public function providerSource() {
$tests = [];
// The source data.
$tests[0]['source_data']['vocabulary'] = [
[
'vid' => 1,
'name' => 'Tags',
'description' => 'Tags description.',
'help' => 1,
'relations' => 0,
'hierarchy' => 0,
'multiple' => 0,
'required' => 0,
'tags' => 1,
'module' => 'taxonomy',
'weight' => 0,
],
[
'vid' => 2,
'name' => 'Categories',
'description' => 'Categories description.',
'help' => 1,
'relations' => 1,
'hierarchy' => 1,
'multiple' => 0,
'required' => 1,
'tags' => 0,
'module' => 'taxonomy',
'weight' => 0,
],
];
$tests[0]['source_data']['vocabulary_node_types'] = [
[
'vid' => 1,
'type' => 'page',
],
[
'vid' => 1,
'type' => 'article',
],
[
'vid' => 2,
'type' => 'article',
],
];
// The expected results.
$tests[0]['expected_data'] = [
[
'vid' => 1,
'name' => 'Tags',
'description' => 'Tags description.',
'help' => 1,
'relations' => 0,
'hierarchy' => 0,
'multiple' => 0,
'required' => 0,
'tags' => 1,
'module' => 'taxonomy',
'weight' => 0,
'node_types' => ['page', 'article'],
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
],
[
'vid' => 2,
'name' => 'Categories',
'description' => 'Categories description.',
'help' => 1,
'relations' => 1,
'hierarchy' => 1,
'multiple' => 0,
'required' => 1,
'tags' => 0,
'module' => 'taxonomy',
'weight' => 0,
'node_types' => ['article'],
'cardinality' => 1,
],
];
return $tests;
}
}

View file

@ -0,0 +1,54 @@
<?php
namespace Drupal\Tests\taxonomy\Kernel\Plugin\migrate\source\d7;
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
/**
* Tests D7 vocabulary source plugin.
*
* @covers \Drupal\taxonomy\Plugin\migrate\source\d7\Vocabulary
* @group taxonomy
*/
class VocabularyTest extends MigrateSqlSourceTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['taxonomy', 'migrate_drupal'];
/**
* {@inheritdoc}
*/
public function providerSource() {
$tests = [];
// The source data.
$tests[0]['source_data']['taxonomy_vocabulary'] = [
[
'vid' => 1,
'name' => 'Tags',
'description' => 'Tags description.',
'hierarchy' => 0,
'module' => 'taxonomy',
'weight' => 0,
'machine_name' => 'tags',
],
[
'vid' => 2,
'name' => 'Categories',
'description' => 'Categories description.',
'hierarchy' => 1,
'module' => 'taxonomy',
'weight' => 0,
'machine_name' => 'categories',
],
];
// The expected results.
$tests[0]['expected_data'] = $tests[0]['source_data']['taxonomy_vocabulary'];
return $tests;
}
}

View file

@ -1,25 +0,0 @@
<?php
namespace Drupal\Tests\taxonomy\Unit\Migrate;
/**
* Tests the taxonomy term source with vocabulary filter.
*
* @group taxonomy
*/
class TermSourceWithVocabularyFilterTest extends TermTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->migrationConfiguration['source']['vocabulary'] = array(5);
parent::setUp();
$this->expectedResults = array_values(array_filter($this->expectedResults, function($result) {
return $result['vid'] == 5;
}));
// We know there are two rows with vid == 5.
$this->expectedCount = 2;
}
}

View file

@ -1,12 +0,0 @@
<?php
namespace Drupal\Tests\taxonomy\Unit\Migrate;
/**
* Tests taxonomy term source plugin.
*
* @group taxonomy
*/
class TermTest extends TermTestBase {
}

View file

@ -1,89 +0,0 @@
<?php
namespace Drupal\Tests\taxonomy\Unit\Migrate;
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
/**
* Base class for taxonomy term source unit tests.
*/
abstract class TermTestBase extends MigrateSqlSourceTestCase {
const PLUGIN_CLASS = 'Drupal\taxonomy\Plugin\migrate\source\Term';
protected $migrationConfiguration = array(
'id' => 'test',
'source' => array(
'plugin' => 'd6_taxonomy_term',
),
);
protected $expectedResults = array(
array(
'tid' => 1,
'vid' => 5,
'name' => 'name value 1',
'description' => 'description value 1',
'weight' => 0,
'parent' => array(0),
),
array(
'tid' => 2,
'vid' => 6,
'name' => 'name value 2',
'description' => 'description value 2',
'weight' => 0,
'parent' => array(0),
),
array(
'tid' => 3,
'vid' => 6,
'name' => 'name value 3',
'description' => 'description value 3',
'weight' => 0,
'parent' => array(0),
),
array(
'tid' => 4,
'vid' => 5,
'name' => 'name value 4',
'description' => 'description value 4',
'weight' => 1,
'parent' => array(1),
),
array(
'tid' => 5,
'vid' => 6,
'name' => 'name value 5',
'description' => 'description value 5',
'weight' => 1,
'parent' => array(2),
),
array(
'tid' => 6,
'vid' => 6,
'name' => 'name value 6',
'description' => 'description value 6',
'weight' => 0,
'parent' => array(3, 2),
),
);
/**
* {@inheritdoc}
*/
protected function setUp() {
foreach ($this->expectedResults as $k => $row) {
foreach ($row['parent'] as $parent) {
$this->databaseContents['term_hierarchy'][] = array(
'tid' => $row['tid'],
'parent' => $parent,
);
}
unset($row['parent']);
$this->databaseContents['term_data'][$k] = $row;
}
parent::setUp();
}
}

View file

@ -1,74 +0,0 @@
<?php
namespace Drupal\Tests\taxonomy\Unit\Migrate\d6;
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
/**
* Tests D6 vocabulary source plugin.
*
* @group taxonomy
*/
class VocabularyTest extends MigrateSqlSourceTestCase {
const PLUGIN_CLASS = 'Drupal\taxonomy\Plugin\migrate\source\d6\Vocabulary';
protected $migrationConfiguration = [
'id' => 'test',
'source' => [
'plugin' => 'd6_vocabulary',
],
];
protected $expectedResults = [
[
'vid' => 1,
'name' => 'Tags',
'description' => 'Tags description.',
'help' => 1,
'relations' => 0,
'hierarchy' => 0,
'multiple' => 0,
'required' => 0,
'tags' => 1,
'module' => 'taxonomy',
'weight' => 0,
'node_types' => ['page', 'article'],
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
],
[
'vid' => 2,
'name' => 'Categories',
'description' => 'Categories description.',
'help' => 1,
'relations' => 1,
'hierarchy' => 1,
'multiple' => 0,
'required' => 1,
'tags' => 0,
'module' => 'taxonomy',
'weight' => 0,
'node_types' => ['article'],
'cardinality' => 1,
],
];
/**
* {@inheritdoc}
*/
protected function setUp() {
foreach ($this->expectedResults as &$row) {
foreach ($row['node_types'] as $type) {
$this->databaseContents['vocabulary_node_types'][] = [
'type' => $type,
'vid' => $row['vid'],
];
}
unset($row['node_types']);
}
$this->databaseContents['vocabulary'] = $this->expectedResults;
parent::setUp();
}
}

View file

@ -1,52 +0,0 @@
<?php
namespace Drupal\Tests\taxonomy\Unit\Migrate\d7;
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
/**
* Tests D7 vocabulary source plugin.
*
* @group taxonomy
*/
class VocabularyTest extends MigrateSqlSourceTestCase {
const PLUGIN_CLASS = 'Drupal\taxonomy\Plugin\migrate\source\d7\Vocabulary';
protected $migrationConfiguration = [
'id' => 'test',
'source' => [
'plugin' => 'd7_vocabulary',
],
];
protected $expectedResults = [
[
'vid' => 1,
'name' => 'Tags',
'description' => 'Tags description.',
'hierarchy' => 0,
'module' => 'taxonomy',
'weight' => 0,
'machine_name' => 'tags',
],
[
'vid' => 2,
'name' => 'Categories',
'description' => 'Categories description.',
'hierarchy' => 1,
'module' => 'taxonomy',
'weight' => 0,
'machine_name' => 'categories',
],
];
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->databaseContents['taxonomy_vocabulary'] = $this->expectedResults;
parent::setUp();
}
}