1beb62b73de78233bc57ec949a564930371a13fc
[yaffs-website] / web / core / modules / system / tests / src / Functional / Update / FieldSchemaDataUninstallUpdateTest.php
1 <?php
2
3 namespace Drupal\Tests\system\Functional\Update;
4
5 use Drupal\FunctionalTests\Update\UpdatePathTestBase;
6
7 /**
8  * Tests the upgrade path after fixing field schema data uninstallation.
9  *
10  * @see https://www.drupal.org/node/2573667
11  *
12  * @group Update
13  * @group legacy
14  */
15 class FieldSchemaDataUninstallUpdateTest extends UpdatePathTestBase {
16
17   /**
18    * {@inheritdoc}
19    */
20   protected function setDatabaseDumpFiles() {
21     $this->databaseDumpFiles = [
22       __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
23       __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.block-content-uninstall.php',
24       __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.field-schema-data-uninstall-2573667.php',
25     ];
26   }
27
28   /**
29    * Tests the upgrade path after fixing field schema data uninstallation.
30    */
31   public function testUpdateHookN() {
32     $this->assertFieldSchemaData(TRUE, 'Field schema data to be purged found before update.');
33     $this->runUpdates();
34     $this->assertFieldSchemaData(FALSE, 'No field schema data to be purged found after update.');
35   }
36
37   /**
38    * Asserts that field schema data to be purged is found.
39    *
40    * @param bool $found
41    *   Whether field schema data is expected to be found or not.
42    * @param string $message
43    *   The assert message.
44    *
45    * @return bool
46    *   TRUE if the assertion succeeded, FALSE otherwise.
47    */
48   protected function assertFieldSchemaData($found, $message) {
49     $query = \Drupal::database()
50       ->select('key_value', 'kv')
51       ->fields('kv');
52     $query
53       ->condition('kv.collection', 'entity.storage_schema.sql')
54       ->condition('kv.name', 'block_content.field_schema_data.%', 'LIKE');
55     $items = $query
56       ->execute()
57       ->fetchAll();
58
59     return $this->assertEqual((bool) $items, $found, $message);
60   }
61
62 }