Updated to Drupal 8.5. Core Media not yet in use.
[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  */
14 class FieldSchemaDataUninstallUpdateTest extends UpdatePathTestBase {
15
16   /**
17    * {@inheritdoc}
18    */
19   protected function setDatabaseDumpFiles() {
20     $this->databaseDumpFiles = [
21       __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
22       __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.block-content-uninstall.php',
23       __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.field-schema-data-uninstall-2573667.php',
24     ];
25   }
26
27   /**
28    * Tests the upgrade path after fixing field schema data uninstallation.
29    */
30   public function testUpdateHookN() {
31     $this->assertFieldSchemaData(TRUE, 'Field schema data to be purged found before update.');
32     $this->runUpdates();
33     $this->assertFieldSchemaData(FALSE, 'No field schema data to be purged found after update.');
34   }
35
36   /**
37    * Asserts that field schema data to be purged is found.
38    *
39    * @param bool $found
40    *   Whether field schema data is expected to be found or not.
41    * @param string $message
42    *   The assert message.
43    *
44    * @return bool
45    *   TRUE if the assertion succeeded, FALSE otherwise.
46    */
47   protected function assertFieldSchemaData($found, $message) {
48     $query = \Drupal::database()
49       ->select('key_value', 'kv')
50       ->fields('kv');
51     $query
52       ->condition('kv.collection', 'entity.storage_schema.sql')
53       ->condition('kv.name', 'block_content.field_schema_data.%', 'LIKE');
54     $items = $query
55       ->execute()
56       ->fetchAll();
57
58     return $this->assertEqual((bool) $items, $found, $message);
59   }
60
61 }