Newer
Older
Alex Pott
committed
<?php
Alex Pott
committed
namespace Drupal\Tests\node\Unit\Plugin\migrate\source\d6;
Alex Pott
committed
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
/**
* Tests D6 node source plugin with 'node_type' configuration.
*
Alex Pott
committed
* @group node
Alex Pott
committed
*/
class NodeByNodeTypeTest extends MigrateSqlSourceTestCase {
Alex Pott
committed
const PLUGIN_CLASS = 'Drupal\node\Plugin\migrate\source\d6\Node';
Alex Pott
committed
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// The fake Migration configuration entity.
protected $migrationConfiguration = array(
'id' => 'test',
// The fake configuration for the source.
'source' => array(
'plugin' => 'd6_node',
'node_type' => 'page',
),
);
protected $expectedResults = array(
array(
// Node fields.
'nid' => 1,
'vid' => 1,
'type' => 'page',
'language' => 'en',
'title' => 'node title 1',
'uid' => 1,
'status' => 1,
'timestamp' => 1279051598,
'created' => 1279051598,
'changed' => 1279051598,
'comment' => 2,
'promote' => 1,
'moderate' => 0,
'sticky' => 0,
'tnid' => 0,
'translate' => 0,
// Node revision fields.
'body' => 'body for node 1',
'teaser' => 'teaser for node 1',
'format' => 1,
'log' => 'log message 1',
),
array(
// Node fields.
'nid' => 2,
'vid' => 2,
'type' => 'page',
'language' => 'en',
'title' => 'node title 2',
'uid' => 1,
'status' => 1,
'timestamp' => 1279290908,
'created' => 1279290908,
'changed' => 1279308993,
'comment' => 0,
'promote' => 1,
'moderate' => 0,
'sticky' => 0,
'tnid' => 0,
'translate' => 0,
// Node revision fields.
'body' => 'body for node 2',
'teaser' => 'teaser for node 2',
'format' => 1,
'log' => 'log message 2',
),
);
/**
* {@inheritdoc}
*/
protected function setUp() {
$database_contents = $this->expectedResults;
Alex Pott
committed
array_walk($this->expectedResults, function (&$row) {
$row['node_uid'] = $row['uid'];
$row['revision_uid'] = $row['uid'] + 1;
unset($row['uid']);
});
Alex Pott
committed
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
$database_contents[] = array(
// Node fields.
'nid' => 5,
'vid' => 5,
'type' => 'article',
'language' => 'en',
'title' => 'node title 5',
'uid' => 1,
'status' => 1,
'timestamp' => 1279290908,
'created' => 1279290908,
'changed' => 1279308993,
'comment' => 0,
'promote' => 1,
'moderate' => 0,
'sticky' => 0,
'tnid' => 0,
'translate' => 0,
// Node revision fields.
'body' => 'body for node 5',
'teaser' => 'body for node 5',
'format' => 1,
'log' => 'log message 3',
);
// Add another row with an article node and make sure it is not migrated.
foreach ($database_contents as $k => $row) {
Alex Pott
committed
foreach (array('nid', 'vid', 'title', 'uid', 'body', 'teaser', 'format', 'timestamp', 'log') as $field) {
Alex Pott
committed
$this->databaseContents['node_revisions'][$k][$field] = $row[$field];
Alex Pott
committed
switch ($field) {
case 'nid': case 'vid':
break;
case 'uid':
$this->databaseContents['node_revisions'][$k]['uid']++;
break;
default:
unset($row[$field]);
break;