Update to Drupal 8.0.0 beta 14. For more information, see https://drupal.org/node/2544542

This commit is contained in:
Pantheon Automation 2015-08-27 12:03:05 -07:00 committed by Greg Anderson
parent 3b2511d96d
commit 81ccda77eb
2155 changed files with 54307 additions and 46870 deletions

View file

@ -0,0 +1,25 @@
# Schema for the migration source plugins.
migrate.source.d6_taxonomy_vocabulary:
type: migrate_source_sql
label: 'Drupal 6 field instance form display'
mapping:
constants:
type: migrate_entity_constant
label: 'Constants'
migrate.source.d6_taxonomy_vocabulary_per_type:
type: migrate_source_sql
label: 'Drupal 6 field instance form display'
mapping:
constants:
type: migrate_entity_constant
label: 'Constants'
migrate.source.d6_taxonomy_vocabulary_per_type:
type: migrate_source_sql
label: 'Drupal 6 field instance form display'
mapping:
constants:
type: migrate_entity_constant
label: 'Constants'

View file

@ -0,0 +1,15 @@
id: d6_taxonomy_settings
label: Drupal 6 taxonomy configuration
migration_tags:
- Drupal 6
source:
plugin: variable
variables:
- taxonomy_override_selector
- taxonomy_terms_per_page_admin
process:
override_selector: taxonomy_override_selector
terms_per_page_admin: taxonomy_terms_per_page_admin
destination:
plugin: config
config_name: taxonomy.settings

View file

@ -0,0 +1,29 @@
id: d6_taxonomy_term
label: Drupal 6 taxonomy terms
migration_tags:
- Drupal 6
source:
plugin: d6_taxonomy_term
process:
tid: tid
vid:
plugin: migration
migration: d6_taxonomy_vocabulary
source: vid
name: name
description: description
weight: weight
parent:
-
plugin: skip_on_empty
method: process
source: parent
-
plugin: migration
migration: d6_taxonomy_term
changed: timestamp
destination:
plugin: entity:taxonomy_term
migration_dependencies:
required:
- d6_taxonomy_vocabulary

View file

@ -0,0 +1,23 @@
id: d6_taxonomy_vocabulary
label: Drupal 6 taxonomy vocabularies
migration_tags:
- Drupal 6
source:
plugin: d6_taxonomy_vocabulary
process:
vid:
-
plugin: machine_name
source: name
-
plugin: dedupe_entity
entity_type: taxonomy_vocabulary
field: vid
length: 32
label: name
name: name
description: description
hierarchy: hierarchy
weight: weight
destination:
plugin: entity:taxonomy_vocabulary

View file

@ -0,0 +1,22 @@
id: d6_term_node
label: Drupal 6 term/node relationships
migration_tags:
- Drupal 6
load:
plugin: d6_term_node
source:
plugin: d6_term_node
process:
nid: nid
type: type
# The actual field name is dynamic and will be added by the load plugin.
destination:
plugin: entity:node
migration_dependencies:
required:
- d6_vocabulary_entity_display
- d6_vocabulary_entity_form_display
- d6_node

View file

@ -0,0 +1,22 @@
id: d6_term_node_revision
label: Drupal 6 term/node relationship revisions
migration_tags:
- Drupal 6
load:
plugin: d6_term_node
bundle_migration: d6_vocabulary_field
source:
plugin: d6_term_node_revision
process:
vid: vid
type: type
# The actual field name is dynamic and will be added by the load plugin.
destination:
plugin: entity_revision:node
migration_dependencies:
required:
- d6_term_node
- d6_node_revision

View file

@ -0,0 +1,28 @@
id: d6_vocabulary_entity_display
label: Drupal 6 vocabulary display configuration
migration_tags:
- Drupal 6
source:
plugin: d6_taxonomy_vocabulary_per_type
constants:
entity_type: node
view_mode: default
options:
label: hidden
type: entity_reference_label
weight: 20
process:
entity_type: 'constants/entity_type'
view_mode: 'constants/view_mode'
options: 'constants/options'
bundle: type
field_name:
plugin: migration
migration: d6_taxonomy_vocabulary
source: vid
destination:
plugin: component_entity_display
migration_dependencies:
required:
- d6_vocabulary_field_instance

View file

@ -0,0 +1,26 @@
id: d6_vocabulary_entity_form_display
label: Drupal 6 vocabulary form display configuration
migration_tags:
- Drupal 6
source:
plugin: d6_taxonomy_vocabulary_per_type
constants:
entity_type: node
form_mode: default
options:
type: options_select
weight: 20
process:
entity_type: 'constants/entity_type'
form_mode: 'constants/form_mode'
options: 'constants/options'
bundle: type
field_name:
plugin: migration
migration: d6_taxonomy_vocabulary
source: vid
destination:
plugin: component_entity_form_display
migration_dependencies:
required:
- d6_vocabulary_field_instance

View file

@ -0,0 +1,25 @@
id: d6_vocabulary_field
label: Drupal 6 vocabulary field configuration
migration_tags:
- Drupal 6
source:
plugin: d6_taxonomy_vocabulary
constants:
entity_type: node
type: entity_reference
target_entity_type: taxonomy_term
cardinality: -1
process:
entity_type: 'constants/entity_type'
type: 'constants/type'
field_name:
plugin: migration
migration: d6_taxonomy_vocabulary
source: vid
'settings/target_type': 'constants/target_entity_type'
cardinality: 'constants/cardinality'
destination:
plugin: md_entity:field_storage_config
migration_dependencies:
required:
- d6_taxonomy_vocabulary

View file

@ -0,0 +1,26 @@
id: d6_vocabulary_field_instance
label: Drupal 6 vocabulary field instance configuration
migration_tags:
- Drupal 6
source:
plugin: d6_taxonomy_vocabulary_per_type
constants:
entity_type: node
auto_create: true
selection_handler: 'default:taxonomy_term'
process:
entity_type: 'constants/entity_type'
bundle: type
field_name:
plugin: migration
migration: d6_taxonomy_vocabulary
source: vid
'settings/handler': 'constants/selection_handler'
'settings/handler_settings/target_bundles/0': @field_name
'settings/handler_settings/auto_create': 'constants/auto_create'
destination:
plugin: entity:field_config
migration_dependencies:
required:
- d6_node_type
- d6_vocabulary_field

View file

@ -7,6 +7,7 @@
namespace Drupal\taxonomy\Controller;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Controller\ControllerBase;
use Drupal\taxonomy\TermInterface;
@ -54,7 +55,7 @@ class TaxonomyController extends ControllerBase {
* The term label.
*/
public function vocabularyTitle(VocabularyInterface $taxonomy_vocabulary) {
return Xss::filter($taxonomy_vocabulary->label());
return SafeMarkup::xssFilter($taxonomy_vocabulary->label());
}
/**
@ -67,7 +68,7 @@ class TaxonomyController extends ControllerBase {
* The term label.
*/
public function termTitle(TermInterface $taxonomy_term) {
return Xss::filter($taxonomy_term->getName());
return SafeMarkup::xssFilter($taxonomy_term->getName());
}
}

View file

@ -0,0 +1,30 @@
<?php
/**
* @file
* Contains \Drupal\taxonomy\Plugin\migrate\destination\EntityTaxonomyTerm.
*/
namespace Drupal\taxonomy\Plugin\migrate\destination;
use Drupal\migrate\Row;
use Drupal\migrate\Plugin\migrate\destination\EntityContentBase;
/**
* @MigrateDestination(
* id = "entity:taxonomy_term"
* )
*/
class EntityTaxonomyTerm extends EntityContentBase {
/**
* {@inheritdoc}
*/
protected function getEntity(Row $row, array $old_destination_id_values) {
if ($row->isStub()) {
$row->setDestinationProperty('name', $this->t('Stub name for source tid:') . $row->getSourceProperty('tid'));
}
return parent::getEntity($row, $old_destination_id_values);
}
}

View file

@ -0,0 +1,64 @@
<?php
/**
* @file
* Contains \Drupal\taxonomy\Plugin\migrate\load\d6\LoadTermNode.
*/
namespace Drupal\taxonomy\Plugin\migrate\load\d6;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\migrate\Entity\MigrationInterface;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\MigrateMessage;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\load\LoadEntity;
/**
* @PluginID("d6_term_node")
*/
class LoadTermNode extends LoadEntity {
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, array $plugin_definition, MigrationInterface $migration) {
$configuration['bundle_migration'] = 'd6_taxonomy_vocabulary';
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration);
}
/**
* {@inheritdoc}
*/
public function loadMultiple(EntityStorageInterface $storage, array $sub_ids = NULL) {
/** @var \Drupal\migrate\Entity\MigrationInterface $bundle_migration */
$bundle_migration = $storage->load('d6_taxonomy_vocabulary');
$migrate_executable = new MigrateExecutable($bundle_migration, new MigrateMessage());
$process = array_intersect_key($bundle_migration->get('process'), $bundle_migration->getDestinationPlugin()->getIds());
$migrations = array();
$vid_map = array();
foreach ($bundle_migration->getIdMap() as $key => $value) {
$old_vid = unserialize($key)['sourceid1'];
$new_vid = $value['destid1'];
$vid_map[$old_vid] = $new_vid;
}
foreach ($bundle_migration->getSourcePlugin()->getIterator() as $source_row) {
$row = new Row($source_row, $source_row);
$migrate_executable->processRow($row, $process);
$old_vid = $source_row['vid'];
$new_vid = $row->getDestinationProperty('vid');
$vid_map[$old_vid] = $new_vid;
}
foreach ($vid_map as $old_vid => $new_vid) {
$values = $this->migration->toArray();
$migration_id = $this->migration->id() . ':' . $old_vid;
$values['id'] = $migration_id;
$values['source']['vid'] = $old_vid;
$values['process'][$new_vid] = 'tid';
$migrations[$migration_id] = $storage->create($values);;
}
return $migrations;
}
}

View file

@ -0,0 +1,79 @@
<?php
/**
* @file
* Contains \Drupal\taxonomy\Plugin\migrate\source\d6\Term.
*/
namespace Drupal\taxonomy\Plugin\migrate\source\d6;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/**
* Drupal 6 taxonomy terms source from database.
*
* @todo Support term_relation, term_synonym table if possible.
*
* @MigrateSource(
* id = "d6_taxonomy_term",
* source_provider = "taxonomy"
* )
*/
class Term extends DrupalSqlBase {
/**
* {@inheritdoc}
*/
public function query() {
// Note the explode - this supports the (admittedly unusual) case of
// consolidating multiple vocabularies into one.
$query = $this->select('term_data', 'td')
->fields('td', array('tid', 'vid', 'name', 'description', 'weight'))
// This works, but we cannot test that, because there is no support for
// distinct() in FakeSelect, yet.
->distinct()
->orderBy('tid');
if (isset($this->configuration['vocabulary'])) {
$query->condition('vid', $this->configuration['vocabulary'], 'IN');
}
return $query;
}
/**
* {@inheritdoc}
*/
public function fields() {
return array(
'tid' => $this->t('The term ID.'),
'vid' => $this->t('Existing term VID'),
'name' => $this->t('The name of the term.'),
'description' => $this->t('The term description.'),
'weight' => $this->t('Weight'),
'parent' => $this->t("The Drupal term IDs of the term's parents."),
);
}
/**
* {@inheritdoc}
*/
public function prepareRow(Row $row) {
// Find parents for this row.
$parents = $this->select('term_hierarchy', 'th')
->fields('th', array('parent', 'tid'))
->condition('tid', $row->getSourceProperty('tid'))
->execute()
->fetchCol();
$row->setSourceProperty('parent', $parents);
return parent::prepareRow($row);
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['tid']['type'] = 'integer';
return $ids;
}
}

View file

@ -0,0 +1,93 @@
<?php
/**
* @file
* Contains \Drupal\taxonomy\Plugin\migrate\source\d6\TermNode.
*/
namespace Drupal\taxonomy\Plugin\migrate\source\d6;
use Drupal\migrate\Plugin\SourceEntityInterface;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/**
* Source returning tids from the term_node table for the current revision.
*
* @MigrateSource(
* id = "d6_term_node",
* source_provider = "taxonomy"
* )
*/
class TermNode extends DrupalSqlBase implements SourceEntityInterface {
/**
* The join options between the node and the term node table.
*/
const JOIN = 'tn.vid = n.vid';
/**
* {@inheritdoc}
*/
public function query() {
$query = $this->select('term_node', 'tn')
// @todo: working, but not is there support for distinct() in FakeSelect?
->distinct()
->fields('tn', array('nid', 'vid'))
->fields('n', array('type'));
// Because this is an inner join it enforces the current revision.
$query->innerJoin('term_data', 'td', 'td.tid = tn.tid AND td.vid = :vid', array(':vid' => $this->configuration['vid']));
$query->innerJoin('node', 'n', static::JOIN);
return $query;
}
/**
* {@inheritdoc}
*/
public function fields() {
return array(
'nid' => $this->t('The node revision ID.'),
'vid' => $this->t('The node revision ID.'),
'tid' => $this->t('The term ID.'),
);
}
/**
* {@inheritdoc}
*/
public function prepareRow(Row $row) {
// Select the terms belonging to the revision selected.
$query = $this->select('term_node', 'tn')
->fields('tn', array('tid'))
->condition('n.nid', $row->getSourceProperty('nid'));
$query->join('node', 'n', static::JOIN);
$query->innerJoin('term_data', 'td', 'td.tid = tn.tid AND td.vid = :vid', array(':vid' => $this->configuration['vid']));
$row->setSourceProperty('tid', $query->execute()->fetchCol());
return parent::prepareRow($row);
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['vid']['type'] = 'integer';
$ids['vid']['alias'] = 'tn';
return $ids;
}
/**
* {@inheritdoc}
*/
public function bundleMigrationRequired() {
return TRUE;
}
/**
* {@inheritdoc}
*/
public function entityTypeId() {
return 'taxonomy_term';
}
}

View file

@ -0,0 +1,24 @@
<?php
/**
* @file
* Contains \Drupal\taxonomy\Plugin\migrate\source\d6\TermNodeRevision.
*/
namespace Drupal\taxonomy\Plugin\migrate\source\d6;
/**
* Source returning tids from the term_node table for the non-current revision.
*
* @MigrateSource(
* id = "d6_term_node_revision"
* )
*/
class TermNodeRevision extends TermNode {
/**
* {@inheritdoc}
*/
const JOIN = 'tn.nid = n.nid AND tn.vid != n.vid';
}

View file

@ -0,0 +1,44 @@
<?php
/**
* @file
* Contains \Drupal\taxonomy\Plugin\migrate\source\d6\Vocabulary.
*/
namespace Drupal\taxonomy\Plugin\migrate\source\d6;
use Drupal\migrate\Row;
/**
* Drupal 6 vocabularies source from database.
*
* @MigrateSource(
* id = "d6_taxonomy_vocabulary",
* source_provider = "taxonomy"
* )
*/
class Vocabulary extends VocabularyBase {
/**
* {@inheritdoc}
*/
public function prepareRow(Row $row) {
// Find node types for this row.
$node_types = $this->select('vocabulary_node_types', 'nt')
->fields('nt', array('type', 'vid'))
->condition('vid', $row->getSourceProperty('vid'))
->execute()
->fetchCol();
$row->setSourceProperty('node_types', $node_types);
return parent::prepareRow($row);
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['vid']['type'] = 'integer';
return $ids;
}
}

View file

@ -0,0 +1,58 @@
<?php
/**
* @file
* Contains \Drupal\taxonomy\Plugin\migrate\source\d6\VocabularyBase.
*/
namespace Drupal\taxonomy\Plugin\migrate\source\d6;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/**
* Drupal 6 vocabularies source base.
*/
abstract class VocabularyBase extends DrupalSqlBase {
/**
* {@inheritdoc}
*/
public function query() {
$query = $this->select('vocabulary', 'v')
->fields('v', array(
'vid',
'name',
'description',
'help',
'relations',
'hierarchy',
'multiple',
'required',
'tags',
'module',
'weight',
));
return $query;
}
/**
* {@inheritdoc}
*/
public function fields() {
return array(
'vid' => $this->t('The vocabulary ID.'),
'name' => $this->t('The name of the vocabulary.'),
'description' => $this->t('The description of the vocabulary.'),
'help' => $this->t('Help text to display for the vocabulary.'),
'relations' => $this->t('Whether or not related terms are enabled within the vocabulary. (0 = disabled, 1 = enabled)'),
'hierarchy' => $this->t('The type of hierarchy allowed within the vocabulary. (0 = disabled, 1 = single, 2 = multiple)'),
'multiple' => $this->t('Whether or not multiple terms from this vocabulary may be assigned to a node. (0 = disabled, 1 = enabled)'),
'required' => $this->t('Whether or not terms are required for nodes using this vocabulary. (0 = disabled, 1 = enabled)'),
'tags' => $this->t('Whether or not free tagging is enabled for the vocabulary. (0 = disabled, 1 = enabled)'),
'weight' => $this->t('The weight of the vocabulary in relation to other vocabularies.'),
'parents' => $this->t("The Drupal term IDs of the term's parents."),
'node_types' => $this->t('The names of the node types the vocabulary may be used with.'),
);
}
}

View file

@ -0,0 +1,42 @@
<?php
/**
* @file
* Contains \Drupal\taxonomy\Plugin\migrate\source\d6\VocabularyPerType.
*/
namespace Drupal\taxonomy\Plugin\migrate\source\d6;
/**
* Gets all the vocabularies based on the node types that have Taxonomy enabled.
*
* @MigrateSource(
* id = "d6_taxonomy_vocabulary_per_type",
* source_provider = "taxonomy"
* )
*/
class VocabularyPerType extends Vocabulary {
/**
* {@inheritdoc}
*/
public function query() {
$query = parent::query();
$query->fields('nt', array(
'type',
));
$query->join('vocabulary_node_types', 'nt', 'v.vid = nt.vid');
return $query;
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['vid']['type'] = 'integer';
$ids['vid']['alias'] = 'nt';
$ids['type']['type'] = 'string';
return $ids;
}
}

View file

@ -276,6 +276,12 @@ class TaxonomyIndexTid extends ManyToOne {
if (empty($this->options['exposed'])) {
return TRUE;
}
// We need to know the operator, which is normally set in
// \Drupal\views\Plugin\views\filter\FilterPluginBase::acceptExposedInput(),
// before we actually call the parent version of ourselves.
if (!empty($this->options['expose']['use_operator']) && !empty($this->options['expose']['operator_id']) && isset($input[$this->options['expose']['operator_id']])) {
$this->operator = $input[$this->options['expose']['operator_id']];
}
// If view is an attachment and is inheriting exposed filters, then assume
// exposed input has already been validated
@ -283,6 +289,12 @@ class TaxonomyIndexTid extends ManyToOne {
$this->validated_exposed_input = (array) $this->view->exposed_raw_input[$this->options['expose']['identifier']];
}
// If we're checking for EMPTY or NOT, we don't need any input, and we can
// say that our input conditions are met by just having the right operator.
if ($this->operator == 'empty' || $this->operator == 'not empty') {
return TRUE;
}
// If it's non-required and there's no value don't bother filtering.
if (!$this->options['expose']['required'] && empty($this->validated_exposed_input)) {
return FALSE;

View file

@ -96,8 +96,8 @@ class TermForm extends ContentEntityForm {
/**
* {@inheritdoc}
*/
public function validate(array $form, FormStateInterface $form_state) {
parent::validate($form, $form_state);
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
// Ensure numeric values.
if ($form_state->hasValue('weight') && !is_numeric($form_state->getValue('weight'))) {

View file

@ -318,23 +318,24 @@ class TermStorage extends SqlContentEntityStorage implements TermStorageInterfac
/**
* {@inheritdoc}
*/
public function getNodeTerms($nids, $vocabs = array(), $langcode = NULL) {
public function getNodeTerms(array $nids, array $vocabs = array(), $langcode = NULL) {
$query = db_select('taxonomy_term_field_data', 'td');
$query->innerJoin('taxonomy_index', 'tn', 'td.tid = tn.tid');
$query->fields('td', array('tid'));
$query->addField('tn', 'nid', 'node_nid');
$query->orderby('td.weight');
$query->orderby('td.name');
$query->condition('tn.nid', $nids);
$query->condition('tn.nid', $nids, 'IN');
$query->addTag('term_access');
if (!empty($vocabs)) {
$query->condition('td.vid', $vocabs);
$query->condition('td.vid', $vocabs, 'IN');
}
if (!empty($langcode)) {
$query->condition('td.langcode', $langcode);
}
$results = array();
$all_tids = array();
foreach ($query->execute() as $term_record) {
$results[$term_record->node_nid][] = $term_record->tid;
$all_tids[] = $term_record->tid;
@ -344,7 +345,7 @@ class TermStorage extends SqlContentEntityStorage implements TermStorageInterfac
$terms = array();
foreach ($results as $nid => $tids) {
foreach ($tids as $tid) {
$terms[$nid][$tid] = $all_terms[$term_record->tid];
$terms[$nid][$tid] = $all_terms[$tid];
}
}
return $terms;

View file

@ -121,6 +121,6 @@ interface TermStorageInterface extends EntityStorageInterface {
* @return array
* An array of nids and the term entities they were tagged with.
*/
public function getNodeTerms($nids, $vocabs = array(), $langcode = NULL);
public function getNodeTerms(array $nids, array $vocabs = array(), $langcode = NULL);
}

View file

@ -0,0 +1,48 @@
<?php
/**
* @file
* Contains \Drupal\taxonomy\Tests\Migrate\d6\MigrateTaxonomyConfigsTest.
*/
namespace Drupal\taxonomy\Tests\Migrate\d6;
use Drupal\config\Tests\SchemaCheckTestTrait;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
/**
* Upgrade variables to taxonomy.settings.yml.
*
* @group taxonomy
*/
class MigrateTaxonomyConfigsTest extends MigrateDrupal6TestBase {
use SchemaCheckTestTrait;
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('taxonomy');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->loadDumps(['Variable.php']);
$this->executeMigration('d6_taxonomy_settings');
}
/**
* Tests migration of taxonomy variables to taxonomy.settings.yml.
*/
public function testTaxonomySettings() {
$config = $this->config('taxonomy.settings');
$this->assertIdentical(100, $config->get('terms_per_page_admin'));
$this->assertIdentical(FALSE, $config->get('override_selector'));
$this->assertConfigSchema(\Drupal::service('config.typed'), 'taxonomy.settings', $config->get());
}
}

View file

@ -0,0 +1,108 @@
<?php
/**
* @file
* Contains \Drupal\taxonomy\Tests\Migrate\d6\MigrateTaxonomyTermTest.
*/
namespace Drupal\taxonomy\Tests\Migrate\d6;
use Drupal\taxonomy\Entity\Term;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
/**
* Upgrade taxonomy terms.
*
* @group taxonomy
*/
class MigrateTaxonomyTermTest extends MigrateDrupal6TestBase {
static $modules = array('taxonomy', 'text');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('taxonomy_term');
$this->prepareMigrations(array(
'd6_taxonomy_vocabulary' => array(
array(array(1), array('vocabulary_1_i_0_')),
array(array(2), array('vocabulary_2_i_1_')),
array(array(3), array('vocabulary_3_i_2_')),
)));
$this->loadDumps([
'TermData.php',
'TermHierarchy.php',
'Vocabulary.php',
'VocabularyNodeTypes.php',
]);
$this->executeMigration('d6_taxonomy_term');
}
/**
* Tests the Drupal 6 taxonomy term to Drupal 8 migration.
*/
public function testTaxonomyTerms() {
$expected_results = array(
'1' => array(
'source_vid' => 1,
'vid' => 'vocabulary_1_i_0_',
'weight' => 0,
'parent' => array(0),
),
'2' => array(
'source_vid' => 2,
'vid' => 'vocabulary_2_i_1_',
'weight' => 3,
'parent' => array(0),
),
'3' => array(
'source_vid' => 2,
'vid' => 'vocabulary_2_i_1_',
'weight' => 4,
'parent' => array(2),
),
'4' => array(
'source_vid' => 3,
'vid' => 'vocabulary_3_i_2_',
'weight' => 6,
'parent' => array(0),
),
'5' => array(
'source_vid' => 3,
'vid' => 'vocabulary_3_i_2_',
'weight' => 7,
'parent' => array(4),
),
'6' => array(
'source_vid' => 3,
'vid' => 'vocabulary_3_i_2_',
'weight' => 8,
'parent' => array(4, 5),
),
);
$terms = Term::loadMultiple(array_keys($expected_results));
foreach ($expected_results as $tid => $values) {
/** @var Term $term */
$term = $terms[$tid];
$this->assertIdentical("term {$tid} of vocabulary {$values['source_vid']}", $term->name->value);
$this->assertIdentical("description of term {$tid} of vocabulary {$values['source_vid']}", $term->description->value);
$this->assertIdentical($values['vid'], $term->vid->target_id);
$this->assertIdentical((string) $values['weight'], $term->weight->value);
if ($values['parent'] === array(0)) {
$this->assertNull($term->parent->target_id);
}
else {
$parents = array();
foreach (\Drupal::entityManager()->getStorage('taxonomy_term')->loadParents($tid) as $parent) {
$parents[] = (int) $parent->id();
}
$this->assertIdentical($parents, $values['parent']);
}
}
}
}

View file

@ -0,0 +1,56 @@
<?php
/**
* @file
* Contains \Drupal\taxonomy\Tests\Migrate\d6\MigrateTaxonomyVocabularyTest.
*/
namespace Drupal\taxonomy\Tests\Migrate\d6;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
/**
* Migrate taxonomy vocabularies to taxonomy.vocabulary.*.yml.
*
* @group taxonomy
*/
class MigrateTaxonomyVocabularyTest extends MigrateDrupal6TestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('taxonomy');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->loadDumps(['Vocabulary.php', 'VocabularyNodeTypes.php']);
$this->executeMigration('d6_taxonomy_vocabulary');
}
/**
* Tests the Drupal 6 taxonomy vocabularies to Drupal 8 migration.
*/
public function testTaxonomyVocabulary() {
for ($i = 0; $i < 3; $i++) {
$j = $i + 1;
$vocabulary = Vocabulary::load("vocabulary_{$j}_i_{$i}_");
$this->assertIdentical(entity_load('migration', 'd6_taxonomy_vocabulary')->getIdMap()->lookupDestinationID(array($j)), array($vocabulary->id()));
$this->assertIdentical("vocabulary $j (i=$i)", $vocabulary->label());
$this->assertIdentical("description of vocabulary $j (i=$i)", $vocabulary->getDescription());
$this->assertIdentical($i, $vocabulary->getHierarchy());
$this->assertIdentical(4 + $i, $vocabulary->get('weight'));
}
$vocabulary = Vocabulary::load('vocabulary_name_much_longer_than');
$this->assertIdentical('vocabulary name much longer than thirty two characters', $vocabulary->label());
$this->assertIdentical('description of vocabulary name much longer than thirty two characters', $vocabulary->getDescription());
$this->assertIdentical(3, $vocabulary->getHierarchy());
$this->assertIdentical(7, $vocabulary->get('weight'));
}
}

View file

@ -0,0 +1,51 @@
<?php
/**
* @file
* Contains \Drupal\taxonomy\Tests\Migrate\d6\MigrateTermNodeRevisionTest.
*/
namespace Drupal\taxonomy\Tests\Migrate\d6;
use Drupal\migrate\MigrateExecutable;
/**
* Upgrade taxonomy term node associations.
*
* @group taxonomy
*/
class MigrateTermNodeRevisionTest extends MigrateTermNodeTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$id_mappings = array(
'd6_term_node' => array(
array(array(2), array(1)),
),
'd6_node_revision' => array(
array(array(2), array(2)),
),
);
$this->prepareMigrations($id_mappings);
/** @var \Drupal\migrate\entity\Migration $migration */
$migrations = entity_load_multiple('migration', array('d6_term_node_revision:*'));
foreach ($migrations as $migration) {
$executable = new MigrateExecutable($migration, $this);
$executable->import();
}
}
/**
* Tests the Drupal 6 term-node revision association to Drupal 8 migration.
*/
public function testTermRevisionNode() {
$node = \Drupal::entityManager()->getStorage('node')->loadRevision(2);
$this->assertIdentical(2, count($node->vocabulary_3_i_2_));
$this->assertIdentical('4', $node->vocabulary_3_i_2_[0]->target_id);
$this->assertIdentical('5', $node->vocabulary_3_i_2_[1]->target_id);
}
}

View file

@ -0,0 +1,49 @@
<?php
/**
* @file
* Contains \Drupal\taxonomy\Tests\Migrate\d6\MigrateTermNodeTest.
*/
namespace Drupal\taxonomy\Tests\Migrate\d6;
use Drupal\migrate\MigrateExecutable;
use Drupal\node\Entity\Node;
/**
* Upgrade taxonomy term node associations.
*
* @group taxonomy
*/
class MigrateTermNodeTest extends MigrateTermNodeTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
/** @var \Drupal\migrate\entity\Migration $migration */
$migrations = entity_load_multiple('migration', array('d6_term_node:*'));
foreach ($migrations as $migration) {
$executable = new MigrateExecutable($migration, $this);
$executable->import();
}
}
/**
* Tests the Drupal 6 term-node association to Drupal 8 migration.
*/
public function testTermNode() {
$node_storage = $this->container->get('entity.manager')->getStorage('node');
$node_storage->resetCache(array(1, 2));
$nodes = Node::loadMultiple(array(1, 2));
$node = $nodes[1];
$this->assertIdentical(1, count($node->vocabulary_1_i_0_));
$this->assertIdentical('1', $node->vocabulary_1_i_0_[0]->target_id);
$node = $nodes[2];
$this->assertIdentical(2, count($node->vocabulary_2_i_1_));
$this->assertIdentical('2', $node->vocabulary_2_i_1_[0]->target_id);
$this->assertIdentical('3', $node->vocabulary_2_i_1_[1]->target_id);
}
}

View file

@ -0,0 +1,98 @@
<?php
/**
* @file
* Contains \Drupal\taxonomy\Tests\Migrate\d6\MigrateTermNodeTestBase.
*/
namespace Drupal\taxonomy\Tests\Migrate\d6;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\entity_reference\Tests\EntityReferenceTestTrait;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
/**
* Base class for Taxonomy/Node migration tests.
*/
abstract class MigrateTermNodeTestBase extends MigrateDrupal6TestBase {
use EntityReferenceTestTrait;
/**
* {@inheritdoc}
*/
static $modules = array('node', 'taxonomy', 'text', 'filter', 'entity_reference');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('node');
$this->installEntitySchema('taxonomy_term');
$this->installSchema('node', array('node_access'));
$vocabulary = entity_create('taxonomy_vocabulary', array(
'vid' => 'test',
));
$vocabulary->save();
$node_type = entity_create('node_type', array('type' => 'story'));
$node_type->save();
foreach (array('vocabulary_1_i_0_', 'vocabulary_2_i_1_', 'vocabulary_3_i_2_') as $name) {
$handler_settings = array(
'target_bundles' => array(
$vocabulary->id() => $vocabulary->id(),
),
'auto_create' => TRUE,
);
$this->createEntityReferenceField('node', 'story', $name, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
}
$id_mappings = array(
'd6_vocabulary_field_instance' => array(
array(array(1, 'page'), array('node', 'page', 'test')),
),
'd6_vocabulary_entity_display' => array(
array(array(1, 'page'), array('node', 'page', 'default', 'test')),
),
'd6_vocabulary_entity_form_display' => array(
array(array(1, 'page'), array('node', 'page', 'default', 'test')),
),
'd6_node' => array(
array(array(1), array(1)),
array(array(2), array(2)),
),
);
$this->prepareMigrations($id_mappings);
$vids = array(1, 2, 3);
for ($i = 1; $i <= 2; $i++) {
$node = entity_create('node', array(
'type' => 'story',
'nid' => $i,
'vid' => array_shift($vids),
));
$node->enforceIsNew();
$node->save();
if ($i == 1) {
$node->vid->value = array_shift($vids);
$node->enforceIsNew(FALSE);
$node->setNewRevision();
$node->isDefaultRevision(FALSE);
$node->save();
}
}
$this->loadDumps([
'Node.php',
'NodeRevisions.php',
'ContentTypeStory.php',
'ContentTypeTestPlanet.php',
'TermNode.php',
'TermHierarchy.php',
'TermData.php',
'Vocabulary.php',
'VocabularyNodeTypes.php',
]);
}
}

View file

@ -0,0 +1,89 @@
<?php
/**
* @file
* Contains \Drupal\taxonomy\Tests\Migrate\d6\MigrateVocabularyEntityDisplayTest.
*/
namespace Drupal\taxonomy\Tests\Migrate\d6;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
/**
* Vocabulary entity display migration.
*
* @group taxonomy
*/
class MigrateVocabularyEntityDisplayTest extends MigrateDrupal6TestBase {
/**
* The modules to be enabled during the test.
*
* @var array
*/
static $modules = array('field', 'node', 'taxonomy', 'text', 'entity_reference');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
entity_create('field_storage_config', array(
'entity_type' => 'node',
'field_name' => 'tags',
'type' => 'entity_reference',
'settings' => array(
'target_type' => 'taxonomy_term',
),
))->save();
foreach (array('page', 'article', 'story') as $type) {
entity_create('node_type', array('type' => $type))->save();
entity_create('field_config', array(
'label' => 'Tags',
'description' => '',
'field_name' => 'tags',
'entity_type' => 'node',
'bundle' => $type,
'required' => 1,
'settings' => array(
'handler' => 'default',
'handler_settings' => array(
'target_bundles' => array(
'tags' => 'tags',
),
'auto_create' => TRUE,
),
),
))->save();
}
// Add some id mappings for the dependant migrations.
$id_mappings = array(
'd6_taxonomy_vocabulary' => array(
array(array(4), array('tags')),
),
'd6_vocabulary_field_instance' => array(
array(array(4, 'page'), array('node', 'page', 'tags')),
)
);
$this->prepareMigrations($id_mappings);
$this->loadDumps(['Vocabulary.php', 'VocabularyNodeTypes.php']);
$this->executeMigration('d6_vocabulary_entity_display');
}
/**
* Tests the Drupal 6 vocabulary-node type association to Drupal 8 migration.
*/
public function testVocabularyEntityDisplay() {
// Test that the field exists.
$component = entity_get_display('node', 'page', 'default')->getComponent('tags');
$this->assertIdentical('entity_reference_label', $component['type']);
$this->assertIdentical(20, $component['weight']);
// Test the Id map.
$this->assertIdentical(array('node', 'article', 'default', 'tags'), entity_load('migration', 'd6_vocabulary_entity_display')->getIdMap()->lookupDestinationID(array(4, 'article')));
}
}

View file

@ -0,0 +1,89 @@
<?php
/**
* @file
* Contains \Drupal\taxonomy\Tests\Migrate\d6\MigrateVocabularyEntityFormDisplayTest.
*/
namespace Drupal\taxonomy\Tests\Migrate\d6;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
/**
* Vocabulary entity form display migration.
*
* @group taxonomy
*/
class MigrateVocabularyEntityFormDisplayTest extends MigrateDrupal6TestBase {
/**
* The modules to be enabled during the test.
*
* @var array
*/
static $modules = array('node', 'taxonomy', 'field', 'text', 'entity_reference');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
entity_create('field_storage_config', array(
'entity_type' => 'node',
'field_name' => 'tags',
'type' => 'entity_reference',
'settings' => array(
'target_type' => 'taxonomy_term',
),
))->save();
foreach (array('page', 'article', 'story') as $type) {
entity_create('node_type', array('type' => $type))->save();
entity_create('field_config', array(
'label' => 'Tags',
'description' => '',
'field_name' => 'tags',
'entity_type' => 'node',
'bundle' => $type,
'required' => 1,
'settings' => array(
'handler' => 'default',
'handler_settings' => array(
'target_bundles' => array(
'tags' => 'tags',
),
'auto_create' => TRUE,
),
),
))->save();
}
// Add some id mappings for the dependant migrations.
$id_mappings = array(
'd6_taxonomy_vocabulary' => array(
array(array(4), array('tags')),
),
'd6_vocabulary_field_instance' => array(
array(array(4, 'page'), array('node', 'page', 'tags')),
)
);
$this->prepareMigrations($id_mappings);
$this->loadDumps(['Vocabulary.php', 'VocabularyNodeTypes.php']);
$this->executeMigration('d6_vocabulary_entity_form_display');
}
/**
* Tests the Drupal 6 vocabulary-node type association to Drupal 8 migration.
*/
public function testVocabularyEntityFormDisplay() {
// Test that the field exists.
$component = entity_get_form_display('node', 'page', 'default')->getComponent('tags');
$this->assertIdentical('options_select', $component['type']);
$this->assertIdentical(20, $component['weight']);
// Test the Id map.
$this->assertIdentical(array('node', 'article', 'default', 'tags'), entity_load('migration', 'd6_vocabulary_entity_form_display')->getIdMap()->lookupDestinationID(array(4, 'article')));
}
}

View file

@ -0,0 +1,97 @@
<?php
/**
* @file
* Contains \Drupal\taxonomy\Tests\Migrate\d6\MigrateVocabularyFieldInstanceTest.
*/
namespace Drupal\taxonomy\Tests\Migrate\d6;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
/**
* Vocabulary field instance migration.
*
* @group taxonomy
*/
class MigrateVocabularyFieldInstanceTest extends MigrateDrupal6TestBase {
/**
* The modules to be enabled during the test.
*
* @var array
*/
static $modules = array('node', 'field', 'taxonomy', 'text', 'entity_reference');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
entity_create('node_type', array('type' => 'page'))->save();
entity_create('node_type', array('type' => 'article'))->save();
entity_create('node_type', array('type' => 'story'))->save();
// Add some id mappings for the dependant migrations.
$id_mappings = array(
'd6_node_type' => array(
array(array('article'), array('article')),
array(array('page'), array('page')),
array(array('story'), array('story')),
),
'd6_taxonomy_vocabulary' => array(
array(array(4), array('tags')),
),
'd6_vocabulary_field' => array(
array(array(4), array('node', 'tags')),
)
);
$this->prepareMigrations($id_mappings);
// Create the vocab.
entity_create('taxonomy_vocabulary', array(
'field_name' => 'Test Vocabulary',
'description' => 'Test Vocabulary',
'vid' => 'tags',
))->save();
// Create the field storage.
entity_create('field_storage_config', array(
'entity_type' => 'node',
'field_name' => 'tags',
'type' => 'entity_reference',
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
'settings' => array(
'target_type' => 'taxonomy_term',
),
))->save();
$this->loadDumps(['Vocabulary.php', 'VocabularyNodeTypes.php']);
$this->executeMigration('d6_vocabulary_field_instance');
}
/**
* Tests the Drupal 6 vocabulary-node type association to Drupal 8 migration.
*/
public function testVocabularyFieldInstance() {
// Test that the field exists.
$field_id = 'node.article.tags';
$field = FieldConfig::load($field_id);
$this->assertIdentical($field_id, $field->id(), 'Field instance exists on article bundle.');
// Test the page bundle as well.
$field_id = 'node.page.tags';
$field = FieldConfig::load($field_id);
$this->assertIdentical($field_id, $field->id(), 'Field instance exists on page bundle.');
$settings = $field->getSettings();
$this->assertIdentical('default:taxonomy_term', $settings['handler'], 'The handler plugin ID is correct.');
$this->assertIdentical(['tags'], $settings['handler_settings']['target_bundles'], 'The target_bundle handler setting is correct.');
$this->assertIdentical(TRUE, $settings['handler_settings']['auto_create'], 'The "auto_create" setting is correct.');
$this->assertIdentical(array('node', 'article', 'tags'), entity_load('migration', 'd6_vocabulary_field_instance')->getIdMap()->lookupDestinationID(array(4, 'article')));
}
}

View file

@ -0,0 +1,66 @@
<?php
/**
* @file
* Contains \Drupal\taxonomy\Tests\Migrate\d6\MigrateVocabularyFieldTest.
*/
namespace Drupal\taxonomy\Tests\Migrate\d6;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
/**
* Vocabulary field migration.
*
* @group taxonomy
*/
class MigrateVocabularyFieldTest extends MigrateDrupal6TestBase {
/**
* The modules to be enabled during the test.
*
* @var array
*/
static $modules = array('node', 'taxonomy', 'field', 'text', 'entity_reference');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Add some id mappings for the dependant migrations.
$id_mappings = array(
'd6_taxonomy_vocabulary' => array(
array(array(4), array('tags')),
),
);
$this->prepareMigrations($id_mappings);
entity_create('taxonomy_vocabulary', array(
'name' => 'Test Vocabulary',
'description' => 'Test Vocabulary',
'vid' => 'test_vocab',
))->save();
$this->loadDumps(['Vocabulary.php', 'VocabularyNodeTypes.php']);
$this->executeMigration('d6_vocabulary_field');
}
/**
* Tests the Drupal 6 vocabulary-node type association to Drupal 8 migration.
*/
public function testVocabularyField() {
// Test that the field exists.
$field_storage_id = 'node.tags';
$field_storage = FieldStorageConfig::load($field_storage_id);
$this->assertIdentical($field_storage_id, $field_storage->id());
$settings = $field_storage->getSettings();
$this->assertIdentical('taxonomy_term', $settings['target_type'], "Target type is correct.");
$this->assertIdentical(array('node', 'tags'), entity_load('migration', 'd6_vocabulary_field')->getIdMap()->lookupDestinationID(array(4)), "Test IdMap");
}
}

View file

@ -8,6 +8,7 @@
namespace Drupal\taxonomy\Tests;
use Drupal\user\RoleInterface;
use Drupal\file\Entity\File;
/**
* Tests access checks of private image fields.
@ -86,7 +87,7 @@ class TaxonomyImageTest extends TaxonomyTestBase {
// Create a user that should have access to the file and one that doesn't.
$access_user = $this->drupalCreateUser(array('access content'));
$no_access_user = $this->drupalCreateUser();
$image = file_load($term->field_test->target_id);
$image = File::load($term->field_test->target_id);
$this->drupalLogin($access_user);
$this->drupalGet(file_create_url($image->getFileUri()));
$this->assertResponse(200, 'Private image on term is accessible with right permission');

View file

@ -78,8 +78,12 @@ trait TaxonomyTranslationTestTrait {
/**
* Adds term reference field for the article content type.
*
* @param bool $translatable
* (optional) If TRUE, create a translatable term reference field. Defaults
* to FALSE.
*/
protected function setUpTermReferenceField() {
protected function setUpTermReferenceField($translatable = FALSE) {
$handler_settings = array(
'target_bundles' => array(
$this->vocabulary->id() => $this->vocabulary->id(),
@ -88,7 +92,7 @@ trait TaxonomyTranslationTestTrait {
);
$this->createEntityReferenceField('node', 'article', $this->termFieldName, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
$field_storage = FieldStorageConfig::loadByName('node', $this->termFieldName);
$field_storage->setTranslatable(FALSE);
$field_storage->setTranslatable($translatable);
$field_storage->save();
entity_get_form_display('node', 'article', 'default')

View file

@ -50,7 +50,7 @@ class TermTranslationFieldViewTest extends TaxonomyTestBase {
$this->vocabulary = $this->createVocabulary();
$this->enableTranslation();
$this->setUpTerm();
$this->setUpTermReferenceField();
$this->setUpTermReferenceField(TRUE);
$this->setUpNode();
}
@ -85,7 +85,7 @@ class TermTranslationFieldViewTest extends TaxonomyTestBase {
'langcode' => $this->baseLangcode,
));
$node->save();
$node->addTranslation($this->translateToLangcode, array());
$node->addTranslation($this->translateToLangcode, $node->toArray());
$node->save();
$this->node = $node;
}

View file

@ -10,6 +10,7 @@ namespace Drupal\taxonomy\Tests;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Render\BubbleableMetadata;
/**
* Generates text using placeholders for dummy content to check taxonomy token
@ -91,10 +92,26 @@ class TokenReplaceTest extends TaxonomyTestBase {
$tests['[term:node-count]'] = 0;
$tests['[term:parent:name]'] = '[term:parent:name]';
$tests['[term:vocabulary:name]'] = SafeMarkup::checkPlain($this->vocabulary->label());
$tests['[term:vocabulary]'] = SafeMarkup::checkPlain($this->vocabulary->label());
$base_bubbleable_metadata = BubbleableMetadata::createFromObject($term1);
$metadata_tests = array();
$metadata_tests['[term:tid]'] = $base_bubbleable_metadata;
$metadata_tests['[term:name]'] = $base_bubbleable_metadata;
$metadata_tests['[term:description]'] = $base_bubbleable_metadata;
$metadata_tests['[term:url]'] = $base_bubbleable_metadata;
$metadata_tests['[term:node-count]'] = $base_bubbleable_metadata;
$metadata_tests['[term:parent:name]'] = $base_bubbleable_metadata;
$bubbleable_metadata = clone $base_bubbleable_metadata;
$metadata_tests['[term:vocabulary:name]'] = $bubbleable_metadata->addCacheTags($this->vocabulary->getCacheTags());
$metadata_tests['[term:vocabulary]'] = $bubbleable_metadata->addCacheTags($this->vocabulary->getCacheTags());
foreach ($tests as $input => $expected) {
$output = $token_service->replace($input, array('term' => $term1), array('langcode' => $language_interface->getId()));
$bubbleable_metadata = new BubbleableMetadata();
$output = $token_service->replace($input, array('term' => $term1), array('langcode' => $language_interface->getId()), $bubbleable_metadata);
$this->assertEqual($output, $expected, format_string('Sanitized taxonomy term token %token replaced.', array('%token' => $input)));
$this->assertEqual($bubbleable_metadata, $metadata_tests[$input]);
}
// Generate and test sanitized tokens for term2.

View file

@ -0,0 +1,42 @@
<?php
/**
* @file
* Contains \Drupal\taxonomy\Tests\Views\TaxonomyFieldAllTerms.
*/
namespace Drupal\taxonomy\Tests\Views;
use Drupal\views\Views;
/**
* Tests the "All terms" taxonomy term field handler.
*
* @group taxonomy
*/
class TaxonomyFieldAllTermsTest extends TaxonomyTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('taxonomy_all_terms_test');
function testViewsHandlerAllTermsField() {
$view = Views::getView('taxonomy_all_terms_test');
$this->executeView($view);
$this->drupalGet('taxonomy_all_terms_test');
$actual = $this->xpath('//a[@href="' . $this->term1->url() . '"]');
$this->assertEqual(count($actual), 2, 'Correct number of taxonomy term1 links');
$this->assertEqual($actual[0]->__toString(), $this->term1->label());
$this->assertEqual($actual[1]->__toString(), $this->term1->label());
$actual = $this->xpath('//a[@href="' . $this->term2->url() . '"]');
$this->assertEqual(count($actual), 2, 'Correct number of taxonomy term2 links');
$this->assertEqual($actual[0]->__toString(), $this->term2->label());
$this->assertEqual($actual[1]->__toString(), $this->term2->label());
}
}

View file

@ -7,6 +7,7 @@
namespace Drupal\taxonomy\Tests\Views;
use Drupal\Core\Render\RenderContext;
use Drupal\views\Views;
/**
@ -24,10 +25,15 @@ class TaxonomyFieldTidTest extends TaxonomyTestBase {
public static $testViews = array('test_taxonomy_tid_field');
function testViewsHandlerTidField() {
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = \Drupal::service('renderer');
$view = Views::getView('test_taxonomy_tid_field');
$this->executeView($view);
$actual = $view->field['name']->advancedRender($view->result[0]);
$actual = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
return $view->field['name']->advancedRender($view->result[0]);
});
$expected = \Drupal::l($this->term1->label(), $this->term1->urlInfo());
$this->assertEqual($expected, $actual);

View file

@ -7,6 +7,8 @@
namespace Drupal\taxonomy\Tests\Views;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\entity_reference\Tests\EntityReferenceTestTrait;
use Drupal\taxonomy\Entity\Term;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\views\Tests\ViewTestData;
@ -20,6 +22,8 @@ use Drupal\views_ui\Tests\UITestBase;
*/
class TaxonomyIndexTidUiTest extends UITestBase {
use EntityReferenceTestTrait;
/**
* Views used by this test.
*
@ -32,7 +36,7 @@ class TaxonomyIndexTidUiTest extends UITestBase {
*
* @var array
*/
public static $modules = array('node', 'taxonomy', 'taxonomy_test_views');
public static $modules = array('node', 'taxonomy', 'taxonomy_test_views', 'entity_reference');
/**
* A nested array of \Drupal\taxonomy\TermInterface objects.
@ -120,4 +124,72 @@ class TaxonomyIndexTidUiTest extends UITestBase {
$this->assertIdentical($expected, $view->calculateDependencies());
}
/**
* Tests exposed taxonomy filters.
*/
public function testExposedFilter() {
$node_type = $this->drupalCreateContentType(['type' => 'page']);
// Create the tag field itself.
$field_name = 'taxonomy_tags';
$this->createEntityReferenceField('node', $node_type->id(), $field_name, NULL, 'taxonomy_term');
// Create 4 nodes: 1 without a term, 2 with the same term, and 1 with a
// different term.
$node1 = $this->drupalCreateNode();
$node2 = $this->drupalCreateNode([
$field_name => [['target_id' => $this->terms[1][0]->id()]],
]);
$node3 = $this->drupalCreateNode([
$field_name => [['target_id' => $this->terms[1][0]->id()]],
]);
$node4 = $this->drupalCreateNode([
$field_name => [['target_id' => $this->terms[2][0]->id()]],
]);
// Only the nodes with the selected term should be shown.
$this->drupalGet('test-filter-taxonomy-index-tid');
$xpath = $this->xpath('//div[@class="view-content"]//a');
$this->assertIdentical(2, count($xpath));
$xpath = $this->xpath('//div[@class="view-content"]//a[@href=:href]', [':href' => $node2->url()]);
$this->assertIdentical(1, count($xpath));
$xpath = $this->xpath('//div[@class="view-content"]//a[@href=:href]', [':href' => $node3->url()]);
$this->assertIdentical(1, count($xpath));
// Expose the filter.
$this->drupalPostForm('admin/structure/views/nojs/handler/test_filter_taxonomy_index_tid/default/filter/tid', [], 'Expose filter');
// Set the operator to 'empty' and remove the default term ID.
$this->drupalPostForm(NULL, [
'options[operator]' => 'empty',
'options[value][]' => [],
], 'Apply');
// Save the view.
$this->drupalPostForm(NULL, [], 'Save');
// After switching to 'empty' operator, the node without a term should be
// shown.
$this->drupalGet('test-filter-taxonomy-index-tid');
$xpath = $this->xpath('//div[@class="view-content"]//a');
$this->assertIdentical(1, count($xpath));
$xpath = $this->xpath('//div[@class="view-content"]//a[@href=:href]', [':href' => $node1->url()]);
$this->assertIdentical(1, count($xpath));
// Set the operator to 'not empty'.
$this->drupalPostForm('admin/structure/views/nojs/handler/test_filter_taxonomy_index_tid/default/filter/tid', ['options[operator]' => 'not empty'], 'Apply');
// Save the view.
$this->drupalPostForm(NULL, [], 'Save');
// After switching to 'not empty' operator, all nodes with terms should be
// shown.
$this->drupalGet('test-filter-taxonomy-index-tid');
$xpath = $this->xpath('//div[@class="view-content"]//a');
$this->assertIdentical(3, count($xpath));
$xpath = $this->xpath('//div[@class="view-content"]//a[@href=:href]', [':href' => $node2->url()]);
$this->assertIdentical(1, count($xpath));
$xpath = $this->xpath('//div[@class="view-content"]//a[@href=:href]', [':href' => $node3->url()]);
$this->assertIdentical(1, count($xpath));
$xpath = $this->xpath('//div[@class="view-content"]//a[@href=:href]', [':href' => $node4->url()]);
$this->assertIdentical(1, count($xpath));
}
}

View file

@ -7,6 +7,7 @@
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Render\BubbleableMetadata;
use Drupal\taxonomy\Entity\Vocabulary;
/**
@ -92,7 +93,7 @@ function taxonomy_token_info() {
/**
* Implements hook_tokens().
*/
function taxonomy_tokens($type, $tokens, array $data = array(), array $options = array()) {
function taxonomy_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) {
$token_service = \Drupal::token();
$replacements = array();
@ -129,12 +130,14 @@ function taxonomy_tokens($type, $tokens, array $data = array(), array $options =
case 'vocabulary':
$vocabulary = Vocabulary::load($term->bundle());
$bubbleable_metadata->addCacheableDependency($vocabulary);
$replacements[$original] = SafeMarkup::checkPlain($vocabulary->label());
break;
case 'parent':
if ($parents = $taxonomy_storage->loadParents($term->id())) {
$parent = array_pop($parents);
$bubbleable_metadata->addCacheableDependency($parent);
$replacements[$original] = SafeMarkup::checkPlain($parent->getName());
}
break;
@ -143,12 +146,12 @@ function taxonomy_tokens($type, $tokens, array $data = array(), array $options =
if ($vocabulary_tokens = $token_service->findWithPrefix($tokens, 'vocabulary')) {
$vocabulary = Vocabulary::load($term->bundle());
$replacements += $token_service->generate('vocabulary', $vocabulary_tokens, array('vocabulary' => $vocabulary), $options);
$replacements += $token_service->generate('vocabulary', $vocabulary_tokens, array('vocabulary' => $vocabulary), $options, $bubbleable_metadata);
}
if (($vocabulary_tokens = $token_service->findWithPrefix($tokens, 'parent')) && $parents = $taxonomy_storage->loadParents($term->id())) {
$parent = array_pop($parents);
$replacements += $token_service->generate('term', $vocabulary_tokens, array('term' => $parent), $options);
$replacements += $token_service->generate('term', $vocabulary_tokens, array('term' => $parent), $options, $bubbleable_metadata);
}
}

View file

@ -0,0 +1,183 @@
langcode: en
status: true
dependencies:
module:
- node
- taxonomy
- user
id: taxonomy_all_terms_test
label: taxonomy_all_terms_test
module: views
description: ''
tag: ''
base_table: node_field_data
base_field: nid
core: 8.x
display:
default:
display_plugin: default
id: default
display_title: Master
position: 0
display_options:
access:
type: perm
options:
perm: 'access content'
cache:
type: tag
options: { }
query:
type: views_query
options:
disable_sql_rewrite: false
distinct: false
replica: false
query_comment: ''
query_tags: { }
exposed_form:
type: basic
options:
submit_button: Apply
reset_button: false
reset_button_label: Reset
exposed_sorts_label: 'Sort by'
expose_sort_order: true
sort_asc_label: Asc
sort_desc_label: Desc
pager:
type: full
options:
items_per_page: 10
offset: 0
id: 0
total_pages: null
expose:
items_per_page: false
items_per_page_label: 'Items per page'
items_per_page_options: '5, 10, 25, 50'
items_per_page_options_all: false
items_per_page_options_all_label: '- All -'
offset: false
offset_label: Offset
tags:
previous: ' previous'
next: 'next '
first: '« first'
last: 'last »'
quantity: 9
style:
type: default
options:
grouping: { }
row_class: ''
default_row_class: true
uses_fields: false
row:
type: fields
options:
inline: { }
separator: ''
hide_empty: false
default_field_elements: true
fields:
term_node_tid:
id: term_node_tid
table: node_field_data
field: term_node_tid
relationship: none
group_type: group
admin_label: ''
label: ''
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: false
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
type: separator
separator: ', '
link_to_taxonomy: true
limit: false
vids:
tags: '0'
entity_type: node
plugin_id: taxonomy_index_tid
filters: { }
sorts:
nid:
id: nid
table: node
field: nid
relationship: none
group_type: group
admin_label: ''
order: ASC
exposed: false
expose:
label: ''
entity_type: node
entity_field: nid
plugin_id: standard
header: { }
footer: { }
empty: { }
relationships: { }
arguments: { }
display_extenders: { }
cache_metadata:
contexts:
- 'languages:language_interface'
- 'url.query_args.pagers:0'
- 'user.node_grants:view'
- user.permissions
cacheable: false
page_1:
display_plugin: page
id: page_1
display_title: Page
position: 1
display_options:
display_extenders: { }
path: taxonomy_all_terms_test
cache_metadata:
contexts:
- 'languages:language_interface'
- 'url.query_args.pagers:0'
- 'user.node_grants:view'
- user.permissions
cacheable: false

View file

@ -176,3 +176,11 @@ display:
empty: { }
relationships: { }
arguments: { }
page_1:
display_plugin: page
id: page_1
display_title: Page
position: 2
display_options:
display_extenders: { }
path: test-filter-taxonomy-index-tid

View file

@ -0,0 +1,30 @@
<?php
/**
* @file
* Contains \Drupal\Tests\taxonomy\Unit\Migrate\d6\TermSourceWithVocabularyFilterTest.
*/
namespace Drupal\Tests\taxonomy\Unit\Migrate\d6;
/**
* Tests the Drupal 6 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

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

View file

@ -0,0 +1,96 @@
<?php
/**
* @file
* Contains \Drupal\Tests\taxonomy\Unit\Migrate\d6\TermTestBase.
*/
namespace Drupal\Tests\taxonomy\Unit\Migrate\d6;
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\d6\Term';
protected $migrationConfiguration = array(
'id' => 'test',
'highWaterProperty' => array('field' => 'test'),
'idlist' => array(),
'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

@ -0,0 +1,80 @@
<?php
/**
* @file
* Contains \Drupal\Tests\taxonomy\Unit\Migrate\d6\VocabularyTest.
*/
namespace Drupal\Tests\taxonomy\Unit\Migrate\d6;
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
/**
* Tests D6 vocabulary source plugin.
*
* @group taxonomy
*/
class VocabularyTest extends MigrateSqlSourceTestCase {
const PLUGIN_CLASS = 'Drupal\taxonomy\Plugin\migrate\source\d6\Vocabulary';
// The fake Migration configuration entity.
protected $migrationConfiguration = [
// The ID of the entity, can be any string.
'id' => 'test',
// Leave it empty for now.
'idlist' => [],
'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'],
],
[
'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'],
],
];
/**
* {@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();
}
}