Commit 2c7b21d2 authored by catch's avatar catch

Issue #2903007 by rakesh.gectcr, dipakmdhrm, maxocub, dillix, masipila,...

Issue #2903007 by rakesh.gectcr, dipakmdhrm, maxocub, dillix, masipila, quietone, phenaproxima: [D7] Forum containers are migrated as forums
parent 4210adf6
...@@ -30,6 +30,7 @@ process: ...@@ -30,6 +30,7 @@ process:
plugin: default_value plugin: default_value
default_value: 0 default_value: 0
source: '@parent_id' source: '@parent_id'
forum_container: is_container
changed: timestamp changed: timestamp
destination: destination:
plugin: entity:taxonomy_term plugin: entity:taxonomy_term
......
...@@ -70,6 +70,11 @@ public function prepareRow(Row $row) { ...@@ -70,6 +70,11 @@ public function prepareRow(Row $row) {
->fetchCol(); ->fetchCol();
$row->setSourceProperty('parent', $parents); $row->setSourceProperty('parent', $parents);
// Determine if this is a forum container.
$forum_container_tids = $this->variableGet('forum_containers', []);
$current_tid = $row->getSourceProperty('tid');
$row->setSourceProperty('is_container', in_array($current_tid, $forum_container_tids));
return parent::prepareRow($row); return parent::prepareRow($row);
} }
......
...@@ -16,6 +16,7 @@ class MigrateTaxonomyTermTest extends MigrateDrupal7TestBase { ...@@ -16,6 +16,7 @@ class MigrateTaxonomyTermTest extends MigrateDrupal7TestBase {
public static $modules = [ public static $modules = [
'comment', 'comment',
'datetime', 'datetime',
'forum',
'image', 'image',
'link', 'link',
'menu_ui', 'menu_ui',
...@@ -71,17 +72,19 @@ protected function setUp() { ...@@ -71,17 +72,19 @@ protected function setUp() {
* The value the migrated entity field should have. * The value the migrated entity field should have.
* @param int $expected_term_reference_tid * @param int $expected_term_reference_tid
* The term reference id the migrated entity field should have. * The term reference id the migrated entity field should have.
* @param bool $expected_container_flag
* The term should be a container entity.
*/ */
protected function assertEntity($id, $expected_label, $expected_vid, $expected_description = '', $expected_format = NULL, $expected_weight = 0, $expected_parents = [], $expected_field_integer_value = NULL, $expected_term_reference_tid = NULL) { protected function assertEntity($id, $expected_label, $expected_vid, $expected_description = '', $expected_format = NULL, $expected_weight = 0, $expected_parents = [], $expected_field_integer_value = NULL, $expected_term_reference_tid = NULL, $expected_container_flag = 0) {
/** @var \Drupal\taxonomy\TermInterface $entity */ /** @var \Drupal\taxonomy\TermInterface $entity */
$entity = Term::load($id); $entity = Term::load($id);
$this->assertTrue($entity instanceof TermInterface); $this->assertInstanceOf(TermInterface::class, $entity);
$this->assertIdentical($expected_label, $entity->label()); $this->assertEquals($expected_label, $entity->label());
$this->assertIdentical($expected_vid, $entity->bundle()); $this->assertEquals($expected_vid, $entity->bundle());
$this->assertEqual($expected_description, $entity->getDescription()); $this->assertEquals($expected_description, $entity->getDescription());
$this->assertEquals($expected_format, $entity->getFormat()); $this->assertEquals($expected_format, $entity->getFormat());
$this->assertEqual($expected_weight, $entity->getWeight()); $this->assertEquals($expected_weight, $entity->getWeight());
$this->assertIdentical($expected_parents, $this->getParentIDs($id)); $this->assertEquals($expected_parents, $this->getParentIDs($id));
$this->assertHierarchy($expected_vid, $id, $expected_parents); $this->assertHierarchy($expected_vid, $id, $expected_parents);
if (!is_null($expected_field_integer_value)) { if (!is_null($expected_field_integer_value)) {
$this->assertTrue($entity->hasField('field_integer')); $this->assertTrue($entity->hasField('field_integer'));
...@@ -91,6 +94,9 @@ protected function assertEntity($id, $expected_label, $expected_vid, $expected_d ...@@ -91,6 +94,9 @@ protected function assertEntity($id, $expected_label, $expected_vid, $expected_d
$this->assertTrue($entity->hasField('field_integer')); $this->assertTrue($entity->hasField('field_integer'));
$this->assertEquals($expected_term_reference_tid, $entity->field_term_reference->target_id); $this->assertEquals($expected_term_reference_tid, $entity->field_term_reference->target_id);
} }
if ($entity->hasField('forum_container')) {
$this->assertEquals($expected_container_flag, $entity->forum_container->value);
}
} }
/** /**
...@@ -102,9 +108,17 @@ public function testTaxonomyTerms() { ...@@ -102,9 +108,17 @@ public function testTaxonomyTerms() {
$this->assertEntity(3, 'Term2', 'test_vocabulary', 'The second term.', 'filtered_html'); $this->assertEntity(3, 'Term2', 'test_vocabulary', 'The second term.', 'filtered_html');
$this->assertEntity(4, 'Term3', 'test_vocabulary', 'The third term.', 'full_html', 0, [3], 6); $this->assertEntity(4, 'Term3', 'test_vocabulary', 'The third term.', 'full_html', 0, [3], 6);
$this->assertEntity(5, 'Custom Forum', 'forums', 'Where the cool kids are.', NULL, 3); $this->assertEntity(5, 'Custom Forum', 'forums', 'Where the cool kids are.', NULL, 3);
$this->assertEntity(6, 'Games', 'forums', '', NULL, 4); $this->assertEntity(6, 'Games', 'forums', '', NULL, 4, [], NULL, NULL, 1);
$this->assertEntity(7, 'Minecraft', 'forums', '', NULL, 1, [6]); $this->assertEntity(7, 'Minecraft', 'forums', '', NULL, 1, [6]);
$this->assertEntity(8, 'Half Life 3', 'forums', '', NULL, 0, [6]); $this->assertEntity(8, 'Half Life 3', 'forums', '', NULL, 0, [6]);
// Verify that we still can create forum containers after the migration.
$term = Term::create(['vid' => 'forums', 'name' => 'Forum Container', 'forum_container' => 1]);
$term->save();
// Reset the forums tree data so this new term is included in the tree.
unset($this->treeData['forums']);
$this->assertEntity(19, 'Forum Container', 'forums', '', NULL, 0, [], NULL, NULL, 1);
} }
/** /**
......
...@@ -31,6 +31,7 @@ public function providerSource() { ...@@ -31,6 +31,7 @@ public function providerSource() {
'name' => 'name value 1', 'name' => 'name value 1',
'description' => 'description value 1', 'description' => 'description value 1',
'weight' => 0, 'weight' => 0,
'is_container' => FALSE,
], ],
[ [
'tid' => 2, 'tid' => 2,
...@@ -38,6 +39,7 @@ public function providerSource() { ...@@ -38,6 +39,7 @@ public function providerSource() {
'name' => 'name value 2', 'name' => 'name value 2',
'description' => 'description value 2', 'description' => 'description value 2',
'weight' => 0, 'weight' => 0,
'is_container' => TRUE,
], ],
[ [
'tid' => 3, 'tid' => 3,
...@@ -45,6 +47,7 @@ public function providerSource() { ...@@ -45,6 +47,7 @@ public function providerSource() {
'name' => 'name value 3', 'name' => 'name value 3',
'description' => 'description value 3', 'description' => 'description value 3',
'weight' => 0, 'weight' => 0,
'is_container' => FALSE,
], ],
[ [
'tid' => 4, 'tid' => 4,
...@@ -52,6 +55,7 @@ public function providerSource() { ...@@ -52,6 +55,7 @@ public function providerSource() {
'name' => 'name value 4', 'name' => 'name value 4',
'description' => 'description value 4', 'description' => 'description value 4',
'weight' => 1, 'weight' => 1,
'is_container' => FALSE,
], ],
[ [
'tid' => 5, 'tid' => 5,
...@@ -59,6 +63,7 @@ public function providerSource() { ...@@ -59,6 +63,7 @@ public function providerSource() {
'name' => 'name value 5', 'name' => 'name value 5',
'description' => 'description value 5', 'description' => 'description value 5',
'weight' => 1, 'weight' => 1,
'is_container' => FALSE,
], ],
[ [
'tid' => 6, 'tid' => 6,
...@@ -66,6 +71,7 @@ public function providerSource() { ...@@ -66,6 +71,7 @@ public function providerSource() {
'name' => 'name value 6', 'name' => 'name value 6',
'description' => 'description value 6', 'description' => 'description value 6',
'weight' => 0, 'weight' => 0,
'is_container' => TRUE,
], ],
[ [
'tid' => 7, 'tid' => 7,
...@@ -73,6 +79,7 @@ public function providerSource() { ...@@ -73,6 +79,7 @@ public function providerSource() {
'name' => 'name value 7', 'name' => 'name value 7',
'description' => 'description value 7', 'description' => 'description value 7',
'weight' => 0, 'weight' => 0,
'is_container' => TRUE,
], ],
]; ];
$tests[0]['source_data']['taxonomy_term_hierarchy'] = [ $tests[0]['source_data']['taxonomy_term_hierarchy'] = [
...@@ -149,6 +156,12 @@ public function providerSource() { ...@@ -149,6 +156,12 @@ public function providerSource() {
'delta' => 0, 'delta' => 0,
], ],
]; ];
$tests[0]['source_data']['variable'] = [
[
'name' => 'forum_containers',
'value' => 'a:3:{i:0;s:1:"5";i:1;s:1:"6";i:2;s:1:"7";}',
],
];
// The expected results. // The expected results.
$tests[0]['expected_data'] = [ $tests[0]['expected_data'] = [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment