MigrateBookTest.php 2.69 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
<?php

/**
 * @file
 * Contains \Drupal\migrate_drupal\Tests\d6\MigrateBookTest.
 */

namespace Drupal\migrate_drupal\Tests\d6;

use Drupal\migrate\MigrateExecutable;
11
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
12
use Drupal\node\Entity\Node;
13 14

/**
15 16 17
 * Upgrade book structure.
 *
 * @group migrate_drupal
18
 */
19
class MigrateBookTest extends MigrateDrupal6TestBase {
20 21 22 23 24 25 26 27 28 29 30 31

  public static $modules = array('book');

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    $id_mappings = array();
    for ($i = 4; $i <= 8; $i++) {
      $entity = entity_create('node', array(
        'type' => 'story',
32
        'title' => "Node $i",
33
        'nid' => $i,
34
        'status' => TRUE,
35 36 37 38 39
      ));
      $entity->enforceIsNew();
      $entity->save();
      $id_mappings['d6_node'][] = array(array($i), array($i));
    }
40
    $this->prepareMigrations($id_mappings);
41 42
    // Load database dumps to provide source data.
    $dumps = array(
43 44
      $this->getDumpDirectory() . '/Book.php',
      $this->getDumpDirectory() . '/MenuLinks.php',
45 46 47 48 49 50 51 52 53 54 55 56
    );
    $this->loadDumps($dumps);
    // Migrate books..
    $migration = entity_load('migration', 'd6_book');
    $executable = new MigrateExecutable($migration, $this);
    $executable->import();
  }

  /**
   * Tests the Drupal 6 book structure to Drupal 8 migration.
   */
  public function testBook() {
57
    $nodes = Node::loadMultiple(array(4, 5, 6, 7, 8));
58 59
    $this->assertIdentical('4', $nodes[4]->book['bid']);
    $this->assertIdentical('0', $nodes[4]->book['pid']);
60

61 62
    $this->assertIdentical('4', $nodes[5]->book['bid']);
    $this->assertIdentical('4', $nodes[5]->book['pid']);
63

64 65
    $this->assertIdentical('4', $nodes[6]->book['bid']);
    $this->assertIdentical('5', $nodes[6]->book['pid']);
66

67 68
    $this->assertIdentical('4', $nodes[7]->book['bid']);
    $this->assertIdentical('5', $nodes[7]->book['pid']);
69

70 71
    $this->assertIdentical('8', $nodes[8]->book['bid']);
    $this->assertIdentical('0', $nodes[8]->book['pid']);
72 73

    $tree = \Drupal::service('book.manager')->bookTreeAllData(4);
74 75 76 77 78 79
    $this->assertIdentical('4', $tree['49990 Node 4 4']['link']['nid']);
    $this->assertIdentical('5', $tree['49990 Node 4 4']['below']['50000 Node 5 5']['link']['nid']);
    $this->assertIdentical('6', $tree['49990 Node 4 4']['below']['50000 Node 5 5']['below']['50000 Node 6 6']['link']['nid']);
    $this->assertIdentical('7', $tree['49990 Node 4 4']['below']['50000 Node 5 5']['below']['50000 Node 7 7']['link']['nid']);
    $this->assertIdentical(array(), $tree['49990 Node 4 4']['below']['50000 Node 5 5']['below']['50000 Node 6 6']['below']);
    $this->assertIdentical(array(), $tree['49990 Node 4 4']['below']['50000 Node 5 5']['below']['50000 Node 7 7']['below']);
80 81 82
  }

}