Skip to content
Snippets Groups Projects
Commit a8bfe0b3 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2807941 by svendecabooter: Convert Taxonomy's Migrate source tests to new base class

parent c0fda56d
No related branches found
No related tags found
No related merge requests found
Showing
with 427 additions and 296 deletions
<?php
namespace Drupal\Tests\taxonomy\Kernel\Plugin\migrate\source;
/**
* Tests the taxonomy term source with vocabulary filter.
*
* @covers \Drupal\taxonomy\Plugin\migrate\source\Term
* @group taxonomy
*/
class TermSourceWithVocabularyFilterTest extends TermTest {
/**
* {@inheritdoc}
*/
public static $modules = ['taxonomy', 'migrate_drupal'];
/**
* {@inheritdoc}
*/
public function providerSource() {
// Get the source data from parent.
$tests = parent::providerSource();
// The expected results.
$tests[0]['expected_data'] = [
[
'tid' => 1,
'vid' => 5,
'name' => 'name value 1',
'description' => 'description value 1',
'weight' => 0,
'parent' => [0],
],
[
'tid' => 4,
'vid' => 5,
'name' => 'name value 4',
'description' => 'description value 4',
'weight' => 1,
'parent' => [1],
],
];
// We know there are two rows with vid == 5.
$tests[0]['expected_count'] = 2;
// Set up source plugin configuration.
$tests[0]['configuration'] = [
'vocabulary' => [5],
];
return $tests;
}
}
<?php
namespace Drupal\Tests\taxonomy\Kernel\Plugin\migrate\source;
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
/**
* Tests taxonomy term source plugin.
*
* @covers \Drupal\taxonomy\Plugin\migrate\source\Term
* @group taxonomy
*/
class TermTest extends MigrateSqlSourceTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['taxonomy', 'migrate_drupal'];
/**
* {@inheritdoc}
*/
public function providerSource() {
$tests = [];
// The source data.
$tests[0]['source_data']['term_data'] = [
[
'tid' => 1,
'vid' => 5,
'name' => 'name value 1',
'description' => 'description value 1',
'weight' => 0,
],
[
'tid' => 2,
'vid' => 6,
'name' => 'name value 2',
'description' => 'description value 2',
'weight' => 0,
],
[
'tid' => 3,
'vid' => 6,
'name' => 'name value 3',
'description' => 'description value 3',
'weight' => 0,
],
[
'tid' => 4,
'vid' => 5,
'name' => 'name value 4',
'description' => 'description value 4',
'weight' => 1,
],
[
'tid' => 5,
'vid' => 6,
'name' => 'name value 5',
'description' => 'description value 5',
'weight' => 1,
],
[
'tid' => 6,
'vid' => 6,
'name' => 'name value 6',
'description' => 'description value 6',
'weight' => 0,
],
];
$tests[0]['source_data']['term_hierarchy'] = [
[
'tid' => 1,
'parent' => 0,
],
[
'tid' => 2,
'parent' => 0,
],
[
'tid' => 3,
'parent' => 0,
],
[
'tid' => 4,
'parent' => 1,
],
[
'tid' => 5,
'parent' => 2,
],
[
'tid' => 6,
'parent' => 3,
],
[
'tid' => 6,
'parent' => 2,
],
];
// The expected results.
$tests[0]['expected_data'] = [
[
'tid' => 1,
'vid' => 5,
'name' => 'name value 1',
'description' => 'description value 1',
'weight' => 0,
'parent' => [0],
],
[
'tid' => 2,
'vid' => 6,
'name' => 'name value 2',
'description' => 'description value 2',
'weight' => 0,
'parent' => [0],
],
[
'tid' => 3,
'vid' => 6,
'name' => 'name value 3',
'description' => 'description value 3',
'weight' => 0,
'parent' => [0],
],
[
'tid' => 4,
'vid' => 5,
'name' => 'name value 4',
'description' => 'description value 4',
'weight' => 1,
'parent' => [1],
],
[
'tid' => 5,
'vid' => 6,
'name' => 'name value 5',
'description' => 'description value 5',
'weight' => 1,
'parent' => [2],
],
[
'tid' => 6,
'vid' => 6,
'name' => 'name value 6',
'description' => 'description value 6',
'weight' => 0,
'parent' => [3, 2],
],
];
return $tests;
}
}
<?php
namespace Drupal\Tests\taxonomy\Unit\Migrate\d6;
namespace Drupal\Tests\taxonomy\Kernel\Plugin\migrate\source\d6;
use Drupal\taxonomy\Plugin\migrate\source\d6\TermNode;
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
/**
* Tests d6_term_node source plugin.
*
* @covers \Drupal\taxonomy\Plugin\migrate\source\d6\TermNode
* @group taxonomy
*/
class TermNodeTest extends MigrateSqlSourceTestCase {
class TermNodeTest extends MigrateSqlSourceTestBase {
const PLUGIN_CLASS = TermNode::class;
protected $migrationConfiguration = array(
'id' => 'test',
'source' => array(
'plugin' => 'd6_term_node',
'vid' => 3,
),
);
protected $expectedResults = array(
array(
'nid' => 1,
'vid' => 1,
'type' => 'story',
'tid' => array(1, 4, 5),
),
);
/**
* {@inheritdoc}
*/
public static $modules = ['taxonomy', 'migrate_drupal'];
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->databaseContents['term_node'] = array(
array(
public function providerSource() {
$tests = [];
// The source data.
$tests[0]['source_data']['term_node'] = [
[
'nid' => '1',
'vid' => '1',
'tid' => '1',
),
array(
],
[
'nid' => '1',
'vid' => '1',
'tid' => '4',
),
array(
],
[
'nid' => '1',
'vid' => '1',
'tid' => '5',
),
);
$this->databaseContents['node'] = array(
array(
],
];
$tests[0]['source_data']['node'] = [
[
'nid' => '1',
'vid' => '1',
'type' => 'story',
......@@ -69,32 +58,51 @@ protected function setUp() {
'sticky' => '0',
'tnid' => '0',
'translate' => '0',
),
);
$this->databaseContents['term_data'] = array(
array(
],
];
$tests[0]['source_data']['term_data'] = [
[
'tid' => '1',
'vid' => '3',
'name' => 'term 1 of vocabulary 3',
'description' => 'description of term 1 of vocabulary 3',
'weight' => '0',
),
array(
],
[
'tid' => '4',
'vid' => '3',
'name' => 'term 4 of vocabulary 3',
'description' => 'description of term 4 of vocabulary 3',
'weight' => '6',
),
array(
],
[
'tid' => '5',
'vid' => '3',
'name' => 'term 5 of vocabulary 3',
'description' => 'description of term 5 of vocabulary 3',
'weight' => '7',
),
);
parent::setUp();
],
];
// The expected results.
$tests[0]['expected_data'] = [
[
'nid' => 1,
'vid' => 1,
'type' => 'story',
'tid' => [1, 4, 5],
],
];
// Set default value for expected count.
$tests[0]['expected_count'] = NULL;
// Set plugin configuration.
$tests[0]['configuration'] = [
'vid' => 3,
];
return $tests;
}
}
<?php
namespace Drupal\Tests\taxonomy\Kernel\Plugin\migrate\source\d6;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
/**
* Tests D6 vocabulary source plugin.
*
* @covers \Drupal\taxonomy\Plugin\migrate\source\d6\Vocabulary
* @group taxonomy
*/
class VocabularyTest extends MigrateSqlSourceTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['taxonomy', 'migrate_drupal'];
/**
* {@inheritdoc}
*/
public function providerSource() {
$tests = [];
// The source data.
$tests[0]['source_data']['vocabulary'] = [
[
'vid' => 1,
'name' => 'Tags',
'description' => 'Tags description.',
'help' => 1,
'relations' => 0,
'hierarchy' => 0,
'multiple' => 0,
'required' => 0,
'tags' => 1,
'module' => 'taxonomy',
'weight' => 0,
],
[
'vid' => 2,
'name' => 'Categories',
'description' => 'Categories description.',
'help' => 1,
'relations' => 1,
'hierarchy' => 1,
'multiple' => 0,
'required' => 1,
'tags' => 0,
'module' => 'taxonomy',
'weight' => 0,
],
];
$tests[0]['source_data']['vocabulary_node_types'] = [
[
'vid' => 1,
'type' => 'page',
],
[
'vid' => 1,
'type' => 'article',
],
[
'vid' => 2,
'type' => 'article',
],
];
// The expected results.
$tests[0]['expected_data'] = [
[
'vid' => 1,
'name' => 'Tags',
'description' => 'Tags description.',
'help' => 1,
'relations' => 0,
'hierarchy' => 0,
'multiple' => 0,
'required' => 0,
'tags' => 1,
'module' => 'taxonomy',
'weight' => 0,
'node_types' => ['page', 'article'],
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
],
[
'vid' => 2,
'name' => 'Categories',
'description' => 'Categories description.',
'help' => 1,
'relations' => 1,
'hierarchy' => 1,
'multiple' => 0,
'required' => 1,
'tags' => 0,
'module' => 'taxonomy',
'weight' => 0,
'node_types' => ['article'],
'cardinality' => 1,
],
];
return $tests;
}
}
<?php
namespace Drupal\Tests\taxonomy\Kernel\Plugin\migrate\source\d7;
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
/**
* Tests D7 vocabulary source plugin.
*
* @covers \Drupal\taxonomy\Plugin\migrate\source\d7\Vocabulary
* @group taxonomy
*/
class VocabularyTest extends MigrateSqlSourceTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['taxonomy', 'migrate_drupal'];
/**
* {@inheritdoc}
*/
public function providerSource() {
$tests = [];
// The source data.
$tests[0]['source_data']['taxonomy_vocabulary'] = [
[
'vid' => 1,
'name' => 'Tags',
'description' => 'Tags description.',
'hierarchy' => 0,
'module' => 'taxonomy',
'weight' => 0,
'machine_name' => 'tags',
],
[
'vid' => 2,
'name' => 'Categories',
'description' => 'Categories description.',
'hierarchy' => 1,
'module' => 'taxonomy',
'weight' => 0,
'machine_name' => 'categories',
],
];
// The expected results.
$tests[0]['expected_data'] = $tests[0]['source_data']['taxonomy_vocabulary'];
return $tests;
}
}
<?php
namespace Drupal\Tests\taxonomy\Unit\Migrate;
/**
* Tests the taxonomy term source with vocabulary filter.
*
* @group taxonomy
*/
class TermSourceWithVocabularyFilterTest extends TermTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->migrationConfiguration['source']['vocabulary'] = array(5);
parent::setUp();
$this->expectedResults = array_values(array_filter($this->expectedResults, function($result) {
return $result['vid'] == 5;
}));
// We know there are two rows with vid == 5.
$this->expectedCount = 2;
}
}
<?php
namespace Drupal\Tests\taxonomy\Unit\Migrate;
/**
* Tests taxonomy term source plugin.
*
* @group taxonomy
*/
class TermTest extends TermTestBase {
}
<?php
namespace Drupal\Tests\taxonomy\Unit\Migrate;
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
/**
* Base class for taxonomy term source unit tests.
*/
abstract class TermTestBase extends MigrateSqlSourceTestCase {
const PLUGIN_CLASS = 'Drupal\taxonomy\Plugin\migrate\source\Term';
protected $migrationConfiguration = array(
'id' => 'test',
'source' => array(
'plugin' => 'd6_taxonomy_term',
),
);
protected $expectedResults = array(
array(
'tid' => 1,
'vid' => 5,
'name' => 'name value 1',
'description' => 'description value 1',
'weight' => 0,
'parent' => array(0),
),
array(
'tid' => 2,
'vid' => 6,
'name' => 'name value 2',
'description' => 'description value 2',
'weight' => 0,
'parent' => array(0),
),
array(
'tid' => 3,
'vid' => 6,
'name' => 'name value 3',
'description' => 'description value 3',
'weight' => 0,
'parent' => array(0),
),
array(
'tid' => 4,
'vid' => 5,
'name' => 'name value 4',
'description' => 'description value 4',
'weight' => 1,
'parent' => array(1),
),
array(
'tid' => 5,
'vid' => 6,
'name' => 'name value 5',
'description' => 'description value 5',
'weight' => 1,
'parent' => array(2),
),
array(
'tid' => 6,
'vid' => 6,
'name' => 'name value 6',
'description' => 'description value 6',
'weight' => 0,
'parent' => array(3, 2),
),
);
/**
* {@inheritdoc}
*/
protected function setUp() {
foreach ($this->expectedResults as $k => $row) {
foreach ($row['parent'] as $parent) {
$this->databaseContents['term_hierarchy'][] = array(
'tid' => $row['tid'],
'parent' => $parent,
);
}
unset($row['parent']);
$this->databaseContents['term_data'][$k] = $row;
}
parent::setUp();
}
}
<?php
namespace Drupal\Tests\taxonomy\Unit\Migrate\d6;
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
/**
* Tests D6 vocabulary source plugin.
*
* @group taxonomy
*/
class VocabularyTest extends MigrateSqlSourceTestCase {
const PLUGIN_CLASS = 'Drupal\taxonomy\Plugin\migrate\source\d6\Vocabulary';
protected $migrationConfiguration = [
'id' => 'test',
'source' => [
'plugin' => 'd6_vocabulary',
],
];
protected $expectedResults = [
[
'vid' => 1,
'name' => 'Tags',
'description' => 'Tags description.',
'help' => 1,
'relations' => 0,
'hierarchy' => 0,
'multiple' => 0,
'required' => 0,
'tags' => 1,
'module' => 'taxonomy',
'weight' => 0,
'node_types' => ['page', 'article'],
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
],
[
'vid' => 2,
'name' => 'Categories',
'description' => 'Categories description.',
'help' => 1,
'relations' => 1,
'hierarchy' => 1,
'multiple' => 0,
'required' => 1,
'tags' => 0,
'module' => 'taxonomy',
'weight' => 0,
'node_types' => ['article'],
'cardinality' => 1,
],
];
/**
* {@inheritdoc}
*/
protected function setUp() {
foreach ($this->expectedResults as &$row) {
foreach ($row['node_types'] as $type) {
$this->databaseContents['vocabulary_node_types'][] = [
'type' => $type,
'vid' => $row['vid'],
];
}
unset($row['node_types']);
}
$this->databaseContents['vocabulary'] = $this->expectedResults;
parent::setUp();
}
}
<?php
namespace Drupal\Tests\taxonomy\Unit\Migrate\d7;
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
/**
* Tests D7 vocabulary source plugin.
*
* @group taxonomy
*/
class VocabularyTest extends MigrateSqlSourceTestCase {
const PLUGIN_CLASS = 'Drupal\taxonomy\Plugin\migrate\source\d7\Vocabulary';
protected $migrationConfiguration = [
'id' => 'test',
'source' => [
'plugin' => 'd7_vocabulary',
],
];
protected $expectedResults = [
[
'vid' => 1,
'name' => 'Tags',
'description' => 'Tags description.',
'hierarchy' => 0,
'module' => 'taxonomy',
'weight' => 0,
'machine_name' => 'tags',
],
[
'vid' => 2,
'name' => 'Categories',
'description' => 'Categories description.',
'hierarchy' => 1,
'module' => 'taxonomy',
'weight' => 0,
'machine_name' => 'categories',
],
];
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->databaseContents['taxonomy_vocabulary'] = $this->expectedResults;
parent::setUp();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment