Unverified Commit 42630422 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3261486 by catch, longwave, dww: Remove core updates added prior to...

Issue #3261486 by catch, longwave, dww: Remove core updates added prior to 9.3.0 and adjust test coverage
parent 22bfdaa3
Loading
Loading
Loading
Loading
+5 −20
Original line number Diff line number Diff line
@@ -5,27 +5,12 @@
 * Post update functions for Action module.
 */

use Drupal\Core\Config\Entity\ConfigEntityUpdater;
use Drupal\system\ActionConfigEntityInterface;

/**
 * Moves action plugins to core.
 * Implements hook_removed_post_updates().
 */
function action_post_update_move_plugins(&$sandbox = NULL) {
  $resave_ids = [
    'action_goto_action',
    'action_message_action',
    'action_send_email_action',
function action_removed_post_updates() {
  return [
    'action_post_update_move_plugins' => '10.0.0',
    'action_post_update_remove_settings' => '10.0.0',
  ];
  \Drupal::classResolver(ConfigEntityUpdater::class)->update($sandbox, 'action', function (ActionConfigEntityInterface $action) use ($resave_ids) {
    // Save entity to recalculate dependencies.
    return $action->isConfigurable() && in_array($action->getPlugin()->getPluginId(), $resave_ids, TRUE);
  });
}

/**
 * Removes action settings.
 */
function action_post_update_remove_settings() {
  \Drupal::configFactory()->getEditable('action.settings')->delete();
}
+0 −53
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Contains database additions to for testing upgrade path for action settings.
 *
 * @see https://www.drupal.org/node/3022401
 */

use Drupal\Core\Database\Database;
use Drupal\Core\Serialization\Yaml;

$connection = Database::getConnection();

$action_settings = Yaml::decode(file_get_contents(__DIR__ . '/action.settings_3022401.yml'));
$connection->insert('config')
  ->fields([
    'collection',
    'name',
    'data',
  ])
  ->values([
    'collection' => '',
    'name' => 'action.settings',
    'data' => serialize($action_settings),
  ])
  ->execute();

// Enable action module.
$extensions = $connection->select('config')
  ->fields('config', ['data'])
  ->condition('name', 'core.extension')
  ->execute()
  ->fetchField();
$extensions = unserialize($extensions);
$connection->update('config')
  ->fields([
    'data' => serialize(array_merge_recursive($extensions, ['module' => ['action' => 0]])),
  ])
  ->condition('name', 'core.extension')
  ->execute();
$connection->insert('key_value')
  ->fields([
    'collection',
    'name',
    'value',
  ])
  ->values([
    'collection' => 'system.schema',
    'name' => 'action',
    'value' => serialize(8000),
  ])
  ->execute();
+0 −45
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\action\Functional\Update;

use Drupal\FunctionalTests\Update\UpdatePathTestBase;

/**
 * Tests removing action module's configuration.
 *
 * @group Update
 */
class ActionConfigTest extends UpdatePathTestBase {

  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';

  /**
   * {@inheritdoc}
   */
  protected function setDatabaseDumpFiles() {
    $this->databaseDumpFiles = [
      __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.8.0.bare.standard.php.gz',
      __DIR__ . '/../../../../tests/fixtures/update/drupal-8.action-3022401.php',
    ];
  }

  /**
   * Tests upgrading action settings.
   *
   * @see \action_post_update_remove_settings()
   */
  public function testUpdateActionPlugins() {
    $config = $this->config('action.settings');
    $this->assertSame(35, $config->get('recursion_limit'));

    // Run updates.
    $this->runUpdates();

    $config = $this->config('action.settings');
    $this->assertTrue($config->isNew());
  }

}
+1 −18
Original line number Diff line number Diff line
@@ -13,23 +13,6 @@ function block_removed_post_updates() {
    'block_post_update_disable_blocks_with_missing_contexts' => '9.0.0',
    'block_post_update_disabled_region_update' => '9.0.0',
    'block_post_update_fix_negate_in_conditions' => '9.0.0',
    'block_post_update_replace_node_type_condition' => '10.0.0',
  ];
}

/**
 * Updates the node type visibility condition.
 */
function block_post_update_replace_node_type_condition() {
  $config_factory = \Drupal::configFactory();
  foreach ($config_factory->listAll('block.block.') as $block_config_name) {
    $block = $config_factory->getEditable($block_config_name);

    if ($block->get('visibility.node_type')) {
      $configuration = $block->get('visibility.node_type');
      $configuration['id'] = 'entity_bundle:node';
      $block->set('visibility.entity_bundle:node', $configuration);
      $block->clear('visibility.node_type');
      $block->save(TRUE);
    }
  }
}
+0 −46
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\block\Functional\Update;

use Drupal\FunctionalTests\Update\UpdatePathTestBase;

/**
 * Tests the upgrade path for updating the node type visibility condition.
 *
 * @group Update
 */
class BlockNodeTypeVisibilityUpdateTest extends UpdatePathTestBase {

  /**
   * {@inheritdoc}
   */
  protected function setDatabaseDumpFiles() {
    $this->databaseDumpFiles = [
      __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-9.0.0.filled.standard.php.gz',
    ];
  }

  /**
   * Tests that block context mapping is updated properly.
   *
   * @group legacy
   */
  public function testBlock() {
    $bundles = [
      'article' => 'article',
      'test_content_type' => 'test_content_type',
    ];

    $block = \Drupal::config('block.block.stark_testblock');
    $this->assertEquals($bundles, $block->get('visibility.node_type.bundles'));
    $this->assertNull($block->get('visibility.entity_bundle:node'));

    $this->runUpdates();

    $block = \Drupal::config('block.block.stark_testblock');
    $this->assertEquals($bundles, $block->get('visibility.entity_bundle:node.bundles'));
    $this->assertEquals('entity_bundle:node', $block->get('visibility.entity_bundle:node.id'));
    $this->assertNull($block->get('visibility.node_type'));
  }

}
Loading