feedback-3.x-dev/tests/src/Functional/Update/FeedbackUpdateHookTest.php

tests/src/Functional/Update/FeedbackUpdateHookTest.php
<?php

declare(strict_types=1);

namespace Drupal\Tests\feedback\Functional\Update;

use Drupal\FunctionalTests\Update\UpdatePathTestBase;

/**
 * Tests database updates to the feedback module.
 *
 * @group Update
 * @group feedback
 */
class FeedbackUpdateHookTest extends UpdatePathTestBase {

  /**
   * {@inheritdoc}
   */
  protected function setDatabaseDumpFiles(): void {
    $this->databaseDumpFiles = [
      $this->root . '/core/modules/system/tests/fixtures/update/drupal-10.3.0.filled.standard.php.gz',
      __DIR__ . '/../../../fixtures/update/feedback-10000.php',
    ];
  }

  /**
   * Test that the original no-op update hook functioned correctly.
   *
   * @see \Drupal\Tests\system\Functional\UpdateSystem\UpdateSchemaTest::testUpdateHooks()
   */
  public function testUpdateHook10001(): void {
    // Setup: Look at the schema version and database structure before.
    $this->assertEquals(10000, $this->getSchemaVersion('feedback'));
    $this->assertTrue($this->doesTableExist('feedback_message'));

    // System under test: Run updates.
    $this->runUpdates();

    // Assertions: Check that the schema version and structure has changed.
    $this->assertEquals(10001, $this->getSchemaVersion('feedback'));
    $this->assertTrue($this->doesTableExist('feedback_message'));
  }

  /**
   * Determine if a table with the given name exists.
   *
   * @param string $table
   *   The table name to test.
   *
   * @return bool
   *   TRUE if the table name exists; FALSE if it does not.
   */
  protected function doesTableExist(string $table): bool {
    return $this->container->get('database')->schema()->tableExists($table);
  }

  /**
   * Get the installed schema version of a module.
   *
   * @param string $module
   *   The module to get the installed schema version of.
   *
   * @return int|null
   *   The schema version of the given module.
   */
  protected function getSchemaVersion(string $module): ?int {
    return $this->container->get('update.update_hook_registry')->getInstalledVersion($module);
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc