MigrateTermNodeTest.php 1.94 KB
Newer Older
1 2
<?php

3
namespace Drupal\Tests\taxonomy\Kernel\Migrate\d6;
4

5
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
6
use Drupal\node\Entity\Node;
7 8

/**
9 10
 * Upgrade taxonomy term node associations.
 *
11
 * @group migrate_drupal_6
12
 */
13 14 15 16 17 18
class MigrateTermNodeTest extends MigrateDrupal6TestBase {

  /**
   * {@inheritdoc}
   */
  public static $modules = ['taxonomy'];
19 20 21 22 23 24

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
25 26 27
    $this->installSchema('node', ['node_access']);
    $this->migrateContent();
    $this->migrateTaxonomy();
28 29 30 31 32 33
  }

  /**
   * Tests the Drupal 6 term-node association to Drupal 8 migration.
   */
  public function testTermNode() {
34 35
    // This is a base plugin id and we want to run all derivatives.
    $this->executeMigrations(['d6_term_node']);
36

37 38 39 40 41
    $this->container->get('entity.manager')
      ->getStorage('node')
      ->resetCache([1, 2]);

    $nodes = Node::loadMultiple([1, 2]);
42
    $node = $nodes[1];
43 44
    $this->assertIdentical(1, count($node->vocabulary_1_i_0_));
    $this->assertIdentical('1', $node->vocabulary_1_i_0_[0]->target_id);
45
    $node = $nodes[2];
46 47 48
    $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);
49 50
  }

51 52 53 54 55 56 57
  /**
   * Tests that term associations are ignored when they belong to nodes which
   * were not migrated.
   */
  public function testSkipNonExistentNode() {
    // Node 2 is migrated by d6_node__story, but we need to pretend that it
    // failed, so record that in the map table.
58
    $this->mockFailure('d6_node:story', ['nid' => 2]);
59 60 61

    // d6_term_node__2 should skip over node 2 (a.k.a. revision 3) because,
    // according to the map table, it failed.
62
    $migration = $this->getMigration('d6_term_node:2');
63 64 65 66
    $this->executeMigration($migration);
    $this->assertNull($migration->getIdMap()->lookupDestinationId(['vid' => 3])[0]);
  }

67
}