Commit b313cdcd authored by catch's avatar catch

Issue #2705977 by heddn, edysmp: D6/7->D8 migration: User role based block...

Issue #2705977 by heddn, edysmp: D6/7->D8 migration: User role based block visibility settings doesn't filter missing roles
parent ce31c4e2
......@@ -43,6 +43,13 @@ class Block extends DrupalSqlBase {
*/
protected $blockRoleTable;
/**
* Table listing user roles.
*
* @var string
*/
protected $userRoleTable;
/**
* {@inheritdoc}
*/
......@@ -55,6 +62,9 @@ public function query() {
$this->blockTable = 'blocks';
$this->blockRoleTable = 'blocks_roles';
}
// Drupal 6 & 7 both use the same name for the user roles table.
$this->userRoleTable = 'role';
return $this->select($this->blockTable, 'b')->fields('b');
}
......@@ -106,11 +116,12 @@ public function prepareRow(Row $row) {
$module = $row->getSourceProperty('module');
$delta = $row->getSourceProperty('delta');
$roles = $this->select($this->blockRoleTable, 'br')
$query = $this->select($this->blockRoleTable, 'br')
->fields('br', array('rid'))
->condition('module', $module)
->condition('delta', $delta)
->execute()
->condition('delta', $delta);
$query->join($this->userRoleTable, 'ur', 'br.rid = ur.rid');
$roles = $query->execute()
->fetchCol();
$row->setSourceProperty('roles', $roles);
......
......@@ -25,6 +25,39 @@ class BlockTest extends MigrateSqlSourceTestCase {
* Sample block instance query results from the source.
*/
protected $expectedResults = array(
array(
'bid' => 1,
'module' => 'block',
'delta' => '1',
'theme' => 'garland',
'status' => 1,
'weight' => 0,
'region' => 'left',
'visibility' => 0,
'pages' => '',
'title' => 'Test Title 01',
'cache' => -1,
'roles' => [2]
),
array(
'bid' => 2,
'module' => 'block',
'delta' => '2',
'theme' => 'garland',
'status' => 1,
'weight' => 5,
'region' => 'right',
'visibility' => 0,
'pages' => '<front>',
'title' => 'Test Title 02',
'cache' => -1,
'roles' => [2]
),
);
/**
* Sample block table.
*/
protected $expectedBlocks = array(
array(
'bid' => 1,
'module' => 'block',
......@@ -62,14 +95,35 @@ class BlockTest extends MigrateSqlSourceTestCase {
'delta' => 1,
'rid' => 2,
),
array(
'module' => 'block',
'delta' => 2,
'rid' => 2,
),
array(
'module' => 'block',
'delta' => 2,
'rid' => 100,
),
);
/**
* Sample role table.
*/
protected $expectedRole = array(
array(
'rid' => 2,
'name' => 'authenticated user',
),
);
/**
* Prepopulate database contents.
*/
protected function setUp() {
$this->databaseContents['blocks'] = $this->expectedResults;
$this->databaseContents['blocks'] = $this->expectedBlocks;
$this->databaseContents['blocks_roles'] = $this->expectedBlocksRoles;
$this->databaseContents['role'] = $this->expectedRole;
$this->databaseContents['system'] = array(
array(
'filename' => 'modules/system/system.module',
......
......@@ -27,7 +27,13 @@ class FieldInstanceTest extends MigrateSqlSourceTestCase {
'bundle' => 'page',
'label' => 'Body',
'widget_settings' => array(
'module' => 'text',
'settings' => array(
'rows' => 20,
'summary_rows' => 5,
),
'type' => 'text_textarea_with_summary',
'weight' => -4,
),
'display_settings' => array(
),
......
......@@ -26,8 +26,28 @@ class FieldTest extends MigrateSqlSourceTestCase {
'type' => 'file',
'global_settings' => '',
'storage' => array(
'type' => 'field_sql_storage',
'active' => 1,
'details' => array(
'sql' => array(
'FIELD_LOAD_CURRENT' => array(
'field_data_field_file' => array(
'description' => 'field_file_description',
'display' => 'field_file_display',
'fid' => 'field_file_fid',
),
),
'FIELD_LOAD_REVISION' => array(
'field_revision_field_file' => array(
'description' => 'field_file_description',
'display' => 'field_file_display',
'fid' => 'field_file_fid',
),
),
),
),
'module' => 'field_sql_storage',
'settings' => array(),
'type' => 'field_sql_storage',
),
'module' => 'file',
'db_columns' => '',
......@@ -39,8 +59,28 @@ class FieldTest extends MigrateSqlSourceTestCase {
'type' => 'file',
'global_settings' => '',
'storage' => array(
'type' => 'field_sql_storage',
'active' => 1,
'details' => array(
'sql' => array(
'FIELD_LOAD_CURRENT' => array(
'field_data_field_file' => array(
'description' => 'field_file_description',
'display' => 'field_file_display',
'fid' => 'field_file_fid',
),
),
'FIELD_LOAD_REVISION' => array(
'field_revision_field_file' => array(
'description' => 'field_file_description',
'display' => 'field_file_display',
'fid' => 'field_file_fid',
),
),
),
),
'module' => 'field_sql_storage',
'settings' => array(),
'type' => 'field_sql_storage',
),
'module' => 'file',
'db_columns' => '',
......
......@@ -32,16 +32,19 @@ class FilterFormatTest extends MigrateSqlSourceTestCase {
'module' => 'filter',
'delta' => 2,
'weight' => 0,
'settings' => array(),
),
array(
'module' => 'filter',
'delta' => 0,
'weight' => 1,
'settings' => array(),
),
array(
'module' => 'filter',
'delta' => 1,
'weight' => 2,
'settings' => array(),
),
),
),
......@@ -55,16 +58,19 @@ class FilterFormatTest extends MigrateSqlSourceTestCase {
'module' => 'filter',
'delta' => 2,
'weight' => 0,
'settings' => array(),
),
array(
'module' => 'filter',
'delta' => 1,
'weight' => 1,
'settings' => array(),
),
array(
'module' => 'filter',
'delta' => 3,
'weight' => 10,
'settings' => array(),
),
),
),
......@@ -79,6 +85,7 @@ class FilterFormatTest extends MigrateSqlSourceTestCase {
'module' => 'markdown',
'delta' => 1,
'weight' => 10,
'settings' => array(),
),
),
),
......@@ -89,9 +96,11 @@ class FilterFormatTest extends MigrateSqlSourceTestCase {
*/
protected function setUp() {
$fid = 1;
$empty_array = serialize(array());
foreach ($this->expectedResults as $k => $row) {
$row['roles'] = ',' . implode(',', $row['roles']) . ',';
foreach ($row['filters'] as $filter) {
$filter['settings'] = $empty_array;
$this->databaseContents['filters'][$fid] = $filter;
$this->databaseContents['filters'][$fid]['format'] = $row['format'];
$this->databaseContents['filters'][$fid]['fid'] = $fid;
......
......@@ -29,6 +29,7 @@ class FilterFormatTest extends MigrateSqlSourceTestCase {
'weight' => 0,
'filters' => array(
'filter_autop' => array(
'format' => 'custom_text_format',
'module' => 'filter',
'name' => 'filter_autop',
'weight' => 0,
......@@ -36,6 +37,7 @@ class FilterFormatTest extends MigrateSqlSourceTestCase {
'settings' => array(),
),
'filter_html' => array(
'format' => 'custom_text_format',
'module' => 'filter',
'name' => 'filter_html',
'weight' => 1,
......@@ -52,6 +54,7 @@ class FilterFormatTest extends MigrateSqlSourceTestCase {
'weight' => 1,
'filters' => array(
'filter_url' => array(
'format' => 'full_html',
'module' => 'filter',
'name' => 'filter_url',
'weight' => 0,
......
......@@ -199,9 +199,11 @@ protected function getValue($row, $key) {
*/
protected function retrievalAssertHelper($expected_value, $actual_value, $message) {
if (is_array($expected_value)) {
foreach ($expected_value as $k => $v) {
$this->retrievalAssertHelper($v, $actual_value[$k], $message . '[' . $k . ']');
// If the expected and actual values are empty, no need to array compare.
if (empty($expected_value && $actual_value)) {
return;
}
$this->assertArrayEquals($expected_value, $actual_value, $message);
}
else {
$this->assertSame((string) $expected_value, (string) $actual_value, $message);
......
......@@ -92,7 +92,10 @@ class NodeTest extends MigrateSqlSourceTestCase {
'timestamp' => 1279308993,
'format' => 1,
'field_test_four' => array(
array('value' => '3.14159'),
array(
'value' => '3.14159',
'delta' => 0,
),
),
),
);
......
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