Update to drupal 8.0.0-rc1. For more information, see https://www.drupal.org/node/2582663

This commit is contained in:
Greg Anderson 2015-10-08 11:40:12 -07:00
parent eb34d130a8
commit f32e58e4b1
8476 changed files with 211648 additions and 170042 deletions

View file

@ -38,7 +38,7 @@ class LoadMultipleTest extends TaxonomyTestBase {
// Load the terms from the vocabulary.
$terms = entity_load_multiple_by_properties('taxonomy_term', array('vid' => $vocabulary->id()));
$count = count($terms);
$this->assertEqual($count, 5, format_string('Correct number of terms were loaded. !count terms.', array('!count' => $count)));
$this->assertEqual($count, 5, format_string('Correct number of terms were loaded. @count terms.', array('@count' => $count)));
// Load the same terms again by tid.
$terms2 = Term::loadMultiple(array_keys($terms));

View file

@ -2,10 +2,10 @@
/**
* @file
* Contains \Drupal\taxonomy\Tests\Migrate\d6\MigrateTaxonomyConfigsTest.
* Contains \Drupal\taxonomy\Tests\Migrate\MigrateTaxonomyConfigsTest.
*/
namespace Drupal\taxonomy\Tests\Migrate\d6;
namespace Drupal\taxonomy\Tests\Migrate;
use Drupal\config\Tests\SchemaCheckTestTrait;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
@ -20,9 +20,7 @@ class MigrateTaxonomyConfigsTest extends MigrateDrupal6TestBase {
use SchemaCheckTestTrait;
/**
* Modules to enable.
*
* @var array
* {@inheritdoc}
*/
public static $modules = array('taxonomy');
@ -31,7 +29,7 @@ class MigrateTaxonomyConfigsTest extends MigrateDrupal6TestBase {
*/
protected function setUp() {
parent::setUp();
$this->executeMigration('d6_taxonomy_settings');
$this->executeMigration('taxonomy_settings');
}
/**

View file

@ -17,23 +17,18 @@ use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
*/
class MigrateTaxonomyTermTest extends MigrateDrupal6TestBase {
static $modules = array('taxonomy', 'text');
/**
* {@inheritdoc}
*/
public static $modules = array('taxonomy');
/**
* {@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->executeMigration('d6_taxonomy_term');
$this->executeMigrations(['d6_taxonomy_vocabulary', 'd6_taxonomy_term']);
}
/**

View file

@ -7,6 +7,7 @@
namespace Drupal\taxonomy\Tests\Migrate\d6;
use Drupal\migrate\Entity\Migration;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
@ -18,9 +19,7 @@ use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
class MigrateTaxonomyVocabularyTest extends MigrateDrupal6TestBase {
/**
* Modules to enable.
*
* @var array
* {@inheritdoc}
*/
public static $modules = array('taxonomy');
@ -39,7 +38,7 @@ class MigrateTaxonomyVocabularyTest extends MigrateDrupal6TestBase {
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(Migration::load('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());

View file

@ -7,32 +7,29 @@
namespace Drupal\taxonomy\Tests\Migrate\d6;
use Drupal\migrate\Entity\Migration;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
/**
* Upgrade taxonomy term node associations.
*
* @group migrate_drupal_6
*/
class MigrateTermNodeRevisionTest extends MigrateTermNodeTestBase {
class MigrateTermNodeRevisionTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['taxonomy'];
/**
* {@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);
$migrations = Migration::loadMultiple(['d6_term_node_revision:*']);
array_walk($migrations, [$this, 'executeMigration']);
$this->installSchema('node', ['node_access']);
$this->migrateContent(TRUE);
$this->migrateTaxonomy();
$this->executeMigrations(['d6_term_node:*', 'd6_term_node_revision:*']);
}
/**

View file

@ -7,8 +7,7 @@
namespace Drupal\taxonomy\Tests\Migrate\d6;
use Drupal\migrate\Entity\Migration;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
use Drupal\node\Entity\Node;
/**
@ -16,33 +15,33 @@ use Drupal\node\Entity\Node;
*
* @group migrate_drupal_6
*/
class MigrateTermNodeTest extends MigrateTermNodeTestBase {
class MigrateTermNodeTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['taxonomy'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$id_mappings = array(
'd6_node:*' => array(
array(
array(0),
array(0),
),
),
);
$this->prepareMigrations($id_mappings);
$migrations = Migration::loadMultiple(['d6_term_node:*']);
array_walk($migrations, [$this, 'executeMigration']);
$this->installSchema('node', ['node_access']);
$this->migrateContent();
$this->migrateTaxonomy();
$this->executeMigrations(['d6_term_node:*']);
}
/**
* 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));
$this->container->get('entity.manager')
->getStorage('node')
->resetCache([1, 2]);
$nodes = Node::loadMultiple([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);

View file

@ -1,88 +0,0 @@
<?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),
'title' => $this->randomString(),
));
$node->enforceIsNew();
$node->save();
if ($i == 1) {
$node->vid->value = array_shift($vids);
$node->enforceIsNew(FALSE);
$node->setNewRevision();
$node->isDefaultRevision(FALSE);
$node->save();
}
}
}
}

View file

@ -7,6 +7,8 @@
namespace Drupal\taxonomy\Tests\Migrate\d6;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\migrate\Entity\Migration;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
/**
@ -17,59 +19,16 @@ use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
class MigrateVocabularyEntityDisplayTest extends MigrateDrupal6TestBase {
/**
* The modules to be enabled during the test.
*
* @var array
* {@inheritdoc}
*/
static $modules = array('field', 'node', 'taxonomy', 'text', 'entity_reference');
public static $modules = ['field', 'taxonomy'];
/**
* {@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->executeMigration('d6_vocabulary_entity_display');
$this->migrateTaxonomy();
}
/**
@ -77,11 +36,11 @@ class MigrateVocabularyEntityDisplayTest extends MigrateDrupal6TestBase {
*/
public function testVocabularyEntityDisplay() {
// Test that the field exists.
$component = entity_get_display('node', 'page', 'default')->getComponent('tags');
$component = EntityViewDisplay::load('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')));
$this->assertIdentical(array('node', 'article', 'default', 'tags'), Migration::load('d6_vocabulary_entity_display')->getIdMap()->lookupDestinationID(array(4, 'article')));
}
}

View file

@ -7,6 +7,8 @@
namespace Drupal\taxonomy\Tests\Migrate\d6;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\migrate\Entity\Migration;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
/**
@ -17,59 +19,16 @@ use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
class MigrateVocabularyEntityFormDisplayTest extends MigrateDrupal6TestBase {
/**
* The modules to be enabled during the test.
*
* @var array
* {@inheritdoc}
*/
static $modules = array('node', 'taxonomy', 'field', 'text', 'entity_reference');
public static $modules = ['taxonomy'];
/**
* {@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->executeMigration('d6_vocabulary_entity_form_display');
$this->migrateTaxonomy();
}
/**
@ -77,11 +36,11 @@ class MigrateVocabularyEntityFormDisplayTest extends MigrateDrupal6TestBase {
*/
public function testVocabularyEntityFormDisplay() {
// Test that the field exists.
$component = entity_get_form_display('node', 'page', 'default')->getComponent('tags');
$component = EntityFormDisplay::load('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')));
$this->assertIdentical(array('node', 'article', 'default', 'tags'), Migration::load('d6_vocabulary_entity_form_display')->getIdMap()->lookupDestinationID(array(4, 'article')));
}
}

View file

@ -9,6 +9,7 @@ namespace Drupal\taxonomy\Tests\Migrate\d6;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\migrate\Entity\Migration;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
/**
@ -19,56 +20,16 @@ use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
class MigrateVocabularyFieldInstanceTest extends MigrateDrupal6TestBase {
/**
* The modules to be enabled during the test.
*
* @var array
* {@inheritdoc}
*/
static $modules = array('node', 'field', 'taxonomy', 'text', 'entity_reference');
public static $modules = ['taxonomy'];
/**
* {@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->executeMigration('d6_vocabulary_field_instance');
$this->migrateTaxonomy();
}
/**
@ -87,10 +48,10 @@ class MigrateVocabularyFieldInstanceTest extends MigrateDrupal6TestBase {
$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(['tags'], $settings['handler_settings']['target_bundles'], 'The target_bundles 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')));
$this->assertIdentical(array('node', 'article', 'tags'), Migration::load('d6_vocabulary_field_instance')->getIdMap()->lookupDestinationID(array(4, 'article')));
}
}

View file

@ -8,6 +8,7 @@
namespace Drupal\taxonomy\Tests\Migrate\d6;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\migrate\Entity\Migration;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
/**
@ -18,33 +19,16 @@ use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
class MigrateVocabularyFieldTest extends MigrateDrupal6TestBase {
/**
* The modules to be enabled during the test.
*
* @var array
* {@inheritdoc}
*/
static $modules = array('node', 'taxonomy', 'field', 'text', 'entity_reference');
public static $modules = ['taxonomy'];
/**
* {@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->executeMigration('d6_vocabulary_field');
$this->migrateTaxonomy();
}
/**
@ -59,7 +43,7 @@ class MigrateVocabularyFieldTest extends MigrateDrupal6TestBase {
$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");
$this->assertIdentical(array('node', 'tags'), Migration::load('d6_vocabulary_field')->getIdMap()->lookupDestinationID(array(4)), "Test IdMap");
}
}

View file

@ -0,0 +1,84 @@
<?php
/**
* @file
* Contains \Drupal\taxonomy\Tests\Migrate\d7\MigrateNodeTaxonomyTest.
*/
namespace Drupal\taxonomy\Tests\Migrate\d7;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\FieldStorageConfigInterface;
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
use Drupal\node\Entity\Node;
use Drupal\node\NodeInterface;
/**
* @group taxonomy
*/
class MigrateNodeTaxonomyTest extends MigrateDrupal7TestBase {
public static $modules = array(
'datetime',
'field',
'filter',
'image',
'link',
'node',
'taxonomy',
'telephone',
'text',
);
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('node');
$this->installEntitySchema('taxonomy_term');
$this->installConfig(static::$modules);
$this->installSchema('node', ['node_access']);
$this->installSchema('system', ['sequences']);
$this->executeMigration('d7_node_type');
FieldStorageConfig::create(array(
'type' => 'entity_reference',
'field_name' => 'field_tags',
'entity_type' => 'node',
'settings' => array(
'target_type' => 'taxonomy_term',
),
'cardinality' => FieldStorageConfigInterface::CARDINALITY_UNLIMITED,
))->save();
FieldConfig::create(array(
'entity_type' => 'node',
'field_name' => 'field_tags',
'bundle' => 'article',
))->save();
$this->executeMigrations([
'd7_taxonomy_vocabulary',
'd7_taxonomy_term',
'd7_user_role',
'd7_user',
'd7_node__article',
]);
}
/**
* Test node migration from Drupal 7 to 8.
*/
public function testMigration() {
$node = Node::load(2);
$this->assertTrue($node instanceof NodeInterface);
$this->assertEqual(9, $node->field_tags[0]->target_id);
$this->assertEqual(14, $node->field_tags[1]->target_id);
$this->assertEqual(17, $node->field_tags[2]->target_id);
}
}

View file

@ -0,0 +1,86 @@
<?php
/**
* @file
* Contains \Drupal\taxonomy\Tests\Migrate\d7\MigrateTaxonomyTermTest.
*/
namespace Drupal\taxonomy\Tests\Migrate\d7;
use Drupal\taxonomy\Entity\Term;
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
use Drupal\taxonomy\TermInterface;
/**
* Upgrade taxonomy terms.
*
* @group taxonomy
*/
class MigrateTaxonomyTermTest extends MigrateDrupal7TestBase {
public static $modules = array('taxonomy', 'text');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('taxonomy_term');
$this->executeMigrations(['d7_taxonomy_vocabulary', 'd7_taxonomy_term']);
}
/**
* Validate a migrated term contains the expected values.
*
* @param $id
* Entity ID to load and check.
* @param $expected_label
* The label the migrated entity should have.
* @param $expected_vid
* The parent vocabulary the migrated entity should have.
* @param string $expected_description
* The description the migrated entity should have.
* @param int $expected_weight
* The weight the migrated entity should have.
* @param array $expected_parents
* The parent terms the migrated entity should have.
*/
protected function assertEntity($id, $expected_label, $expected_vid, $expected_description = '', $expected_weight = 0, $expected_parents = []) {
/** @var \Drupal\taxonomy\TermInterface $entity */
$entity = Term::load($id);
$this->assertTrue($entity instanceof TermInterface);
$this->assertIdentical($expected_label, $entity->label());
$this->assertIdentical($expected_vid, $entity->getVocabularyId());
$this->assertEqual($expected_description, $entity->getDescription());
$this->assertEqual($expected_weight, $entity->getWeight());
$this->assertIdentical($expected_parents, $this->getParentIDs($id));
}
/**
* Tests the Drupal 7 taxonomy term to Drupal 8 migration.
*/
public function testTaxonomyTerms() {
$this->assertEntity(1, 'General discussion', 'forums', '', 2);
$this->assertEntity(2, 'Term1', 'test_vocabulary', 'The first term.');
$this->assertEntity(3, 'Term2', 'test_vocabulary', 'The second term.');
$this->assertEntity(4, 'Term3', 'test_vocabulary', 'The third term.', 0, [3]);
$this->assertEntity(5, 'Custom Forum', 'forums', 'Where the cool kids are.', 3);
$this->assertEntity(6, 'Games', 'forums', '', 4);
$this->assertEntity(7, 'Minecraft', 'forums', '', 1, [6]);
$this->assertEntity(8, 'Half Life 3', 'forums', '', 0, [6]);
}
/**
* Retrieves the parent term IDs for a given term.
*
* @param $tid
* ID of the term to check.
*
* @return array
* List of parent term IDs.
*/
protected function getParentIDs($tid) {
return array_keys(\Drupal::entityManager()->getStorage('taxonomy_term')->loadParents($tid));
}
}

View file

@ -0,0 +1,67 @@
<?php
/**
* @file
* Contains \Drupal\taxonomy\Tests\Migrate\d7\MigrateTaxonomyVocabularyTest.
*/
namespace Drupal\taxonomy\Tests\Migrate\d7;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
use Drupal\taxonomy\VocabularyInterface;
/**
* Migrate taxonomy vocabularies to taxonomy.vocabulary.*.yml.
*
* @group taxonomy
*/
class MigrateTaxonomyVocabularyTest extends MigrateDrupal7TestBase {
/**
* {@inheritdoc}
*/
public static $modules = array('taxonomy');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->executeMigration('d7_taxonomy_vocabulary');
}
/**
* Validate a migrated vocabulary contains the expected values.
*
* @param $id
* Entity ID to load and check.
* @param $expected_label
* The label the migrated entity should have.
* @param $expected_description
* The description the migrated entity should have.
* @param $expected_hierarchy
* The hierarchy setting the migrated entity should have.
* @param $expected_weight
* The weight the migrated entity should have.
*/
protected function assertEntity($id, $expected_label, $expected_description, $expected_hierarchy, $expected_weight) {
/** @var \Drupal\taxonomy\VocabularyInterface $entity */
$entity = Vocabulary::load($id);
$this->assertTrue($entity instanceof VocabularyInterface);
$this->assertIdentical($expected_label, $entity->label());
$this->assertIdentical($expected_description, $entity->getDescription());
$this->assertIdentical($expected_hierarchy, $entity->getHierarchy());
$this->assertIdentical($expected_weight, $entity->get('weight'));
}
/**
* 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);
}
}

View file

@ -7,7 +7,7 @@
namespace Drupal\taxonomy\Tests;
use Drupal\entity_reference\Tests\EntityReferenceTestTrait;
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\simpletest\WebTestBase;
/**

View file

@ -8,7 +8,7 @@
namespace Drupal\taxonomy\Tests;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\entity_reference\Tests\EntityReferenceTestTrait;
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\language\Entity\ConfigurableLanguage;
@ -83,7 +83,7 @@ trait TaxonomyTranslationTestTrait {
* (optional) If TRUE, create a translatable term reference field. Defaults
* to FALSE.
*/
protected function setUpTermReferenceField($translatable = FALSE) {
protected function setUpTermReferenceField() {
$handler_settings = array(
'target_bundles' => array(
$this->vocabulary->id() => $this->vocabulary->id(),
@ -92,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($translatable);
$field_storage->setTranslatable(FALSE);
$field_storage->save();
entity_get_form_display('node', 'article', 'default')

View file

@ -22,7 +22,7 @@ class TermEntityReferenceTest extends TaxonomyTestBase {
*
* @var array
*/
public static $modules = array('entity_reference', 'entity_reference_test', 'entity_test');
public static $modules = ['entity_reference_test', 'entity_test'];
/**
* Tests an entity reference field restricted to a single vocabulary.

View file

@ -50,6 +50,7 @@ class TermTest extends TaxonomyTestBase {
$this->drupalPlaceBlock('local_actions_block');
$this->drupalPlaceBlock('local_tasks_block');
$this->drupalPlaceBlock('page_title_block');
$this->drupalLogin($this->drupalCreateUser(['administer taxonomy', 'bypass node access']));
$this->vocabulary = $this->createVocabulary();

View file

@ -50,7 +50,7 @@ class TermTranslationFieldViewTest extends TaxonomyTestBase {
$this->vocabulary = $this->createVocabulary();
$this->enableTranslation();
$this->setUpTerm();
$this->setUpTermReferenceField(TRUE);
$this->setUpTermReferenceField();
$this->setUpNode();
}

View file

@ -7,8 +7,6 @@
namespace Drupal\taxonomy\Tests;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Render\BubbleableMetadata;
@ -86,13 +84,13 @@ class TokenReplaceTest extends TaxonomyTestBase {
// Generate and test sanitized tokens for term1.
$tests = array();
$tests['[term:tid]'] = $term1->id();
$tests['[term:name]'] = Html::escape($term1->getName());
$tests['[term:name]'] = $term1->getName();
$tests['[term:description]'] = $term1->description->processed;
$tests['[term:url]'] = $term1->url('canonical', array('absolute' => TRUE));
$tests['[term:node-count]'] = 0;
$tests['[term:parent:name]'] = '[term:parent:name]';
$tests['[term:vocabulary:name]'] = Html::escape($this->vocabulary->label());
$tests['[term:vocabulary]'] = Html::escape($this->vocabulary->label());
$tests['[term:vocabulary:name]'] = $this->vocabulary->label();
$tests['[term:vocabulary]'] = $this->vocabulary->label();
$base_bubbleable_metadata = BubbleableMetadata::createFromObject($term1);
@ -117,14 +115,14 @@ class TokenReplaceTest extends TaxonomyTestBase {
// Generate and test sanitized tokens for term2.
$tests = array();
$tests['[term:tid]'] = $term2->id();
$tests['[term:name]'] = Html::escape($term2->getName());
$tests['[term:name]'] = $term2->getName();
$tests['[term:description]'] = $term2->description->processed;
$tests['[term:url]'] = $term2->url('canonical', array('absolute' => TRUE));
$tests['[term:node-count]'] = 1;
$tests['[term:parent:name]'] = Html::escape($term1->getName());
$tests['[term:parent:name]'] = $term1->getName();
$tests['[term:parent:url]'] = $term1->url('canonical', array('absolute' => TRUE));
$tests['[term:parent:parent:name]'] = '[term:parent:parent:name]';
$tests['[term:vocabulary:name]'] = Html::escape($this->vocabulary->label());
$tests['[term:vocabulary:name]'] = $this->vocabulary->label();
// Test to make sure that we generated something for each token.
$this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
@ -134,22 +132,11 @@ class TokenReplaceTest extends TaxonomyTestBase {
$this->assertEqual($output, $expected, format_string('Sanitized taxonomy term token %token replaced.', array('%token' => $input)));
}
// Generate and test unsanitized tokens.
$tests['[term:name]'] = $term2->getName();
$tests['[term:description]'] = $term2->getDescription();
$tests['[term:parent:name]'] = $term1->getName();
$tests['[term:vocabulary:name]'] = $this->vocabulary->label();
foreach ($tests as $input => $expected) {
$output = $token_service->replace($input, array('term' => $term2), array('langcode' => $language_interface->getId(), 'sanitize' => FALSE));
$this->assertEqual($output, $expected, format_string('Unsanitized taxonomy term token %token replaced.', array('%token' => $input)));
}
// Generate and test sanitized tokens.
$tests = array();
$tests['[vocabulary:vid]'] = $this->vocabulary->id();
$tests['[vocabulary:name]'] = Html::escape($this->vocabulary->label());
$tests['[vocabulary:description]'] = Xss::filter($this->vocabulary->getDescription());
$tests['[vocabulary:name]'] = $this->vocabulary->label();
$tests['[vocabulary:description]'] = $this->vocabulary->getDescription();
$tests['[vocabulary:node-count]'] = 1;
$tests['[vocabulary:term-count]'] = 2;
@ -160,15 +147,6 @@ class TokenReplaceTest extends TaxonomyTestBase {
$output = $token_service->replace($input, array('vocabulary' => $this->vocabulary), array('langcode' => $language_interface->getId()));
$this->assertEqual($output, $expected, format_string('Sanitized taxonomy vocabulary token %token replaced.', array('%token' => $input)));
}
// Generate and test unsanitized tokens.
$tests['[vocabulary:name]'] = $this->vocabulary->label();
$tests['[vocabulary:description]'] = $this->vocabulary->getDescription();
foreach ($tests as $input => $expected) {
$output = $token_service->replace($input, array('vocabulary' => $this->vocabulary), array('langcode' => $language_interface->getId(), 'sanitize' => FALSE));
$this->assertEqual($output, $expected, format_string('Unsanitized taxonomy vocabulary token %token replaced.', array('%token' => $input)));
}
}
}

View file

@ -0,0 +1,127 @@
<?php
/**
* @file
* Contains \Drupal\taxonomy\Tests\Views\ArgumentValidatorTermTest.
*/
namespace Drupal\taxonomy\Tests\Views;
use Drupal\views\Views;
/**
* Tests the plugin of the taxonomy: term argument validator.
*
* @group taxonomy
* @see Views\taxonomy\Plugin\views\argument_validator\Term
*/
class ArgumentValidatorTermTest extends TaxonomyTestBase {
/**
* Stores the taxonomy term used by this test.
*
* @var array
*/
protected $terms = [];
/**
* Stores the taxonomy names used by this test.
*
* @var array
*/
protected $names = [];
/**
* Stores the taxonomy IDs used by this test.
*
* @var array
*/
protected $ids = [];
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['taxonomy', 'taxonomy_test_views', 'views_test_config'];
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = ['test_argument_validator_term'];
protected function setUp() {
parent::setUp();
// Add three terms to the 'tags' vocabulary.
for ($i = 0; $i < 3; $i++) {
$this->terms[] = $term = $this->createTerm();
$this->names[] = $term->label();
$this->ids[] = $term->id();
}
}
/**
* Tests the term argument validator plugin.
*/
public function testArgumentValidatorTerm() {
$view = Views::getView('test_argument_validator_term');
$view->initHandlers();
// Test the single validator for term IDs.
$view->argument['tid']->validator->options['type'] = 'tid';
// Pass in a single valid term.
foreach ($this->terms as $term) {
$this->assertTrue($view->argument['tid']->setArgument($term->id()));
$this->assertEqual($view->argument['tid']->getTitle(), $term->label());
$view->argument['tid']->validated_title = NULL;
$view->argument['tid']->argument_validated = NULL;
}
// Pass in a invalid term.
$this->assertFalse($view->argument['tid']->setArgument(rand(1000, 10000)));
$this->assertEqual('', $view->argument['tid']->getTitle());
$view->argument['tid']->validated_title = NULL;
$view->argument['tid']->argument_validated = NULL;
// Test the multiple validator for term IDs.
$view->argument['tid']->validator->options['type'] = 'tids';
$view->argument['tid']->options['break_phrase'] = TRUE;
// Pass in a single term.
$this->assertTrue($view->argument['tid']->setArgument($this->terms[0]->id()));
$this->assertEqual($view->argument['tid']->getTitle(), $this->terms[0]->label());
$view->argument['tid']->validated_title = NULL;
$view->argument['tid']->argument_validated = NULL;
// Check for multiple valid terms separated by commas.
$this->assertTrue($view->argument['tid']->setArgument(implode(',', $this->ids)));
$this->assertEqual($view->argument['tid']->getTitle(), implode(', ', $this->names));
$view->argument['tid']->validated_title = NULL;
$view->argument['tid']->argument_validated = NULL;
// Check for multiple valid terms separated by plus signs.
$this->assertTrue($view->argument['tid']->setArgument(implode('+', $this->ids)));
$this->assertEqual($view->argument['tid']->getTitle(), implode(' + ', $this->names));
$view->argument['tid']->validated_title = NULL;
$view->argument['tid']->argument_validated = NULL;
// Check for a single invalid term.
$this->assertFalse($view->argument['tid']->setArgument(rand(1000, 10000)));
$this->assertEqual('', $view->argument['tid']->getTitle());
$view->argument['tid']->validated_title = NULL;
$view->argument['tid']->argument_validated = NULL;
// Check for multiple invalid terms.
$this->assertFalse($view->argument['tid']->setArgument(implode(',', [rand(1000, 10000), rand(1000, 10000)])));
$this->assertEqual('', $view->argument['tid']->getTitle());
$view->argument['tid']->validated_title = NULL;
$view->argument['tid']->argument_validated = NULL;
}
}

View file

@ -34,7 +34,7 @@ class RelationshipNodeTermDataTest extends TaxonomyTestBase {
'user',
],
];
$this->assertIdentical($expected, $view->calculateDependencies());
$this->assertIdentical($expected, $view->getDependencies());
$this->executeView($view, array($this->term1->id(), $this->term2->id()));
$expected_result = array(
array(
@ -55,7 +55,7 @@ class RelationshipNodeTermDataTest extends TaxonomyTestBase {
$view = Views::getView('test_taxonomy_node_term_data');
// Tests \Drupal\taxonomy\Plugin\views\relationship\NodeTermData::calculateDependencies().
$expected['config'][] = 'taxonomy.vocabulary.views_testing_tags';
$this->assertIdentical($expected, $view->calculateDependencies());
$this->assertIdentical($expected, $view->getDependencies());
$this->executeView($view, array($this->term1->id(), $this->term2->id()));
$this->assertIdenticalResultset($view, $expected_result, $column_map);
}

View file

@ -59,4 +59,14 @@ class TaxonomyDefaultArgumentTest extends TaxonomyTestBase {
$expected = $this->term1->id();
$this->assertEqual($expected, $view->argument['tid']->getDefaultArgument());
}
/**
* Tests escaping of page title when the taxonomy plugin provides it.
*/
public function testTermTitleEscaping() {
$this->term1->setName('<em>Markup</em>')->save();
$this->drupalGet('taxonomy_default_argument_test/'. $this->term1->id());
$this->assertEscaped($this->term1->label());
}
}

View file

@ -28,6 +28,7 @@ class TaxonomyFieldAllTermsTest extends TaxonomyTestBase {
* Tests the "all terms" field handler.
*/
public function testViewsHandlerAllTermsField() {
$this->term1->setName('<em>Markup</em>')->save();
$view = Views::getView('taxonomy_all_terms_test');
$this->executeView($view);
$this->drupalGet('taxonomy_all_terms_test');
@ -36,6 +37,7 @@ class TaxonomyFieldAllTermsTest extends TaxonomyTestBase {
$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());
$this->assertEscaped($this->term1->label());
$actual = $this->xpath('//a[@href="' . $this->term2->url() . '"]');
$this->assertEqual(count($actual), 2, 'Correct number of taxonomy term2 links');

View file

@ -8,7 +8,7 @@
namespace Drupal\taxonomy\Tests\Views;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\entity_reference\Tests\EntityReferenceTestTrait;
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\taxonomy\Entity\Term;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\views\Tests\ViewTestData;
@ -36,7 +36,7 @@ class TaxonomyIndexTidUiTest extends UITestBase {
*
* @var array
*/
public static $modules = array('node', 'taxonomy', 'taxonomy_test_views', 'entity_reference');
public static $modules = ['node', 'taxonomy', 'taxonomy_test_views'];
/**
* A nested array of \Drupal\taxonomy\TermInterface objects.
@ -121,7 +121,7 @@ class TaxonomyIndexTidUiTest extends UITestBase {
'user',
],
];
$this->assertIdentical($expected, $view->calculateDependencies());
$this->assertIdentical($expected, $view->calculateDependencies()->getDependencies());
}
/**

View file

@ -0,0 +1,64 @@
<?php
/**
* @file
* Contains \Drupal\taxonomy\Tests\Views\TaxonomyTermArgumentDepthTest.
*/
namespace Drupal\taxonomy\Tests\Views;
/**
* Tests the taxonomy term with depth argument.
*
* @group taxonomy
*/
class TaxonomyTermArgumentDepthTest extends TaxonomyTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['taxonomy', 'taxonomy_test_views', 'views', 'node'];
/**
* {@inheritdoc}
*/
public static $testViews = ['test_argument_taxonomy_index_tid_depth'];
/**
* @var \Drupal\taxonomy\TermInterface[]
*/
protected $terms = [];
/**
* @var \Drupal\views\ViewExecutable
*/
protected $view;
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
// Create a term with markup in the label.
$first = $this->createTerm(['name' => '<em>First</em>']);
// Create a node w/o any terms.
$settings = ['type' => 'article'];
// Create a node with linked to the term.
$settings['field_views_testing_tags'][0]['target_id'] = $first->id();
$this->nodes[] = $this->drupalCreateNode($settings);
$this->terms[0] = $first;
}
/**
* Tests title escaping.
*/
public function testTermWithDepthArgumentTitleEscaping() {
$this->drupalGet('test_argument_taxonomy_index_tid_depth/' . $this->terms[0]->id());
$this->assertEscaped($this->terms[0]->label());
}
}

View file

@ -9,7 +9,7 @@ namespace Drupal\taxonomy\Tests\Views;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\entity_reference\Tests\EntityReferenceTestTrait;
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\views\Tests\ViewTestBase;
use Drupal\views\Tests\ViewTestData;

View file

@ -142,37 +142,6 @@ class VocabularyCrudTest extends TaxonomyTestBase {
$this->assertEqual($vocabulary->id(), $vocabulary2->id(), 'Vocabulary loaded successfully by name and ID.');
}
/**
* Tests that machine name changes are properly reflected.
*/
function testTaxonomyVocabularyChangeMachineName() {
// Add a field to the vocabulary.
entity_create('field_storage_config', array(
'field_name' => 'field_test',
'entity_type' => 'taxonomy_term',
'type' => 'test_field',
))->save();
entity_create('field_config', array(
'field_name' => 'field_test',
'entity_type' => 'taxonomy_term',
'bundle' => $this->vocabulary->id(),
))->save();
// Change the machine name.
$old_name = $this->vocabulary->id();
$new_name = Unicode::strtolower($this->randomMachineName());
$this->vocabulary->set('vid', $new_name);
$this->vocabulary->save();
// Check that entity bundles are properly updated.
$info = entity_get_bundles('taxonomy_term');
$this->assertFalse(isset($info[$old_name]), 'The old bundle name does not appear in entity_get_bundles().');
$this->assertTrue(isset($info[$new_name]), 'The new bundle name appears in entity_get_bundles().');
// Check that the field is still attached to the vocabulary.
$this->assertTrue(FieldConfig::loadByName('taxonomy_term', $new_name, 'field_test'), 'The bundle name was updated correctly.');
}
/**
* Test uninstall and reinstall of the taxonomy module.
*/

View file

@ -14,6 +14,12 @@ namespace Drupal\taxonomy\Tests;
*/
class VocabularyPermissionsTest extends TaxonomyTestBase {
protected function setUp() {
parent::setUp();
$this->drupalPlaceBlock('page_title_block');
}
/**
* Create, edit and delete a taxonomy term via the user interface.
*/

View file

@ -30,6 +30,7 @@ class VocabularyUiTest extends TaxonomyTestBase {
$this->drupalLogin($this->drupalCreateUser(['administer taxonomy']));
$this->vocabulary = $this->createVocabulary();
$this->drupalPlaceBlock('local_actions_block');
$this->drupalPlaceBlock('page_title_block');
}
/**