You are here

abstract class TestSuiteBase in Drupal driver for SQL Server and SQL Azure 3.0.x

Same name in this branch
  1. 3.0.x dev/appveyor/TestSuites/TestSuiteBase.php \Drupal\Tests\sqlsrv\TestSuites\TestSuiteBase
  2. 3.0.x dev/travis/TestSuites/TestSuiteBase.php \Drupal\Tests\sqlsrv\TestSuites\TestSuiteBase
Same name and namespace in other branches
  1. 4.2.x dev/TestSuites/TestSuiteBase.php \Drupal\Tests\sqlsrv\TestSuites\TestSuiteBase
  2. 3.1.x dev/appveyor/TestSuites/TestSuiteBase.php \Drupal\Tests\sqlsrv\TestSuites\TestSuiteBase
  3. 3.1.x dev/travis/TestSuites/TestSuiteBase.php \Drupal\Tests\sqlsrv\TestSuites\TestSuiteBase
  4. 4.0.x dev/appveyor/TestSuites/TestSuiteBase.php \Drupal\Tests\sqlsrv\TestSuites\TestSuiteBase
  5. 4.0.x dev/travis/TestSuites/TestSuiteBase.php \Drupal\Tests\sqlsrv\TestSuites\TestSuiteBase
  6. 4.1.x dev/TestSuites/TestSuiteBase.php \Drupal\Tests\sqlsrv\TestSuites\TestSuiteBase

Base class for Drupal test suites.

Hierarchy

  • class \Drupal\Tests\sqlsrv\TestSuites\TestSuiteBase extends \PHPUnit\Framework\TestSuite

Expanded class hierarchy of TestSuiteBase

File

dev/travis/TestSuites/TestSuiteBase.php, line 11

Namespace

Drupal\Tests\sqlsrv\TestSuites
View source
abstract class TestSuiteBase extends TestSuite {

  /**
   * Regex patterns to split up core Kernel extensions.
   *
   * @var array
   */
  protected static $coreExtensionPatterns = [
    '[a-i]',
    '[j-q]',
    '[r-z]',
  ];

  /**
   * The failing test files.
   *
   * @var array
   */
  protected $failingClasses = [
    // Kernel Test Failures.
    '/core/tests/Drupal/KernelTests/Core/Database/SelectSubqueryTest.php',
    '/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php',
    '/core/modules/aggregator/tests/src/Kernel/Migrate/MigrateAggregatorStubTest.php',
    '/core/modules/migrate_drupal/tests/src/Kernel/d7/FieldDiscoveryTest.php',
    '/core/modules/field/tests/src/Kernel/Views/HandlerFieldFieldTest.php',
    '/core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php',
    '/core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php',
    // Functional Test Failures.
    '/core/modules/aggregator/tests/src/Functional/Rest/FeedJsonAnonTest.php',
    '/core/modules/aggregator/tests/src/Functional/Rest/FeedJsonBasicAuthTest.php',
    '/core/modules/aggregator/tests/src/Functional/Hal/FeedHalJsonAnonTest.php',
    '/core/modules/datetime/tests/src/Functional/Views/FilterDateTest.php',
    '/core/modules/language/tests/src/Functional/ConfigurableLanguageManagerTest.php',
    '/core/modules/locale/tests/src/Functional/LocaleLocaleLookupTest.php',
    '/core/modules/path/tests/src/Functional/PathAliasTest.php',
    '/core/modules/taxonomy/tests/src/Functional/Views/TermDisplayConfigurableTest.php',
    // Update Test Failures.
    '/core/modules/block_content/tests/src/Functional/Update/BlockContentReusableUpdateTest.php',
    '/core/modules/block_content/tests/src/Functional/Update/BlockContentUpdateTest.php',
    '/core/modules/content_moderation/tests/src/Functional/Update/DefaultContentModerationStateRevisionUpdateTest.php',
    '/core/modules/dblog/tests/src/Functional/Update/DblogFiltersAndFieldsUpgradeTest.php',
    '/core/modules/dblog/tests/src/Functional/Update/DblogRecentLogsUsingViewsUpdateTest.php',
    '/core/modules/aggregator/tests/src/Functional/Update/AggregatorUpdateTest.php',
    '/core/modules/field/tests/src/Functional/Update/EntityReferenceHandlerSettingUpdateTest.php',
    '/core/modules/field/tests/src/Functional/Update/EmailWidgetSizeSettingUpdateTest.php',
    '/core/modules/field/tests/src/Functional/Update/FieldUpdateTest.php',
    '/core/modules/file/tests/src/Functional/Update/FileUpdateTest.php',
    '/core/modules/file/tests/src/Functional/Update/FileUsageTemporaryDeletionConfigurationUpdateTest.php',
    '/core/modules/hal/tests/src/Functional/Update/CreateHalSettingsForLinkDomainUpdateTest.php',
    '/core/modules/hal/tests/src/Functional/Update/MigrateLinkDomainSettingFromRestToHalUpdateTest.php',
    '/core/modules/layout_builder/tests/src/Functional/Update/LayoutBuilderContextMappingUpdatePathTest.php',
    '/core/modules/layout_builder/tests/src/Functional/Update/TempstoreKeyUpdatePathTest.php',
    '/core/modules/system/tests/src/Functional/Update/AutomatedCronUpdateWithAutomatedCronTest.php',
    '/core/modules/system/tests/src/Functional/Update/ConfigOverridesUpdateTest.php',
    '/core/modules/system/tests/src/Functional/Update/EntityUpdateAddRevisionDefaultTest.php',
    '/core/modules/system/tests/src/Functional/Update/EntityUpdateAddRevisionTranslationAffectedTest.php',
    '/core/modules/system/tests/src/Functional/Update/LocalActionsAndTasksConvertedIntoBlocksUpdateTest.php',
    '/core/modules/system/tests/src/Functional/Update/MenuTreeSerializationTitleTest.php',
    '/core/modules/system/tests/src/Functional/Update/SiteBrandingConvertedIntoBlockUpdateTest.php',
    '/core/modules/system/tests/src/Functional/Update/UpdateActionsWithEntityPluginsTest.php',
    '/core/modules/views/tests/src/Functional/Update/CacheabilityMetadataUpdateTest.php',
    '/core/modules/workspaces/tests/src/Functional/Update/WorkspacesUpdateTest.php',
  ];

  /**
   * Finds extensions in a Drupal installation.
   *
   * An extension is defined as a directory with an *.info.yml file in it.
   *
   * @param string $root
   *   Path to the root of the Drupal installation.
   *
   * @return string[]
   *   Associative array of extension paths, with extension name as keys.
   */
  protected function findExtensionDirectories($root) {
    $extension_roots = \drupal_phpunit_contrib_extension_directory_roots($root);
    $extension_directories = array_map('drupal_phpunit_find_extension_directories', $extension_roots);
    return array_reduce($extension_directories, 'array_merge', []);
  }

  /**
   * Find and add tests to the suite for core and any extensions.
   *
   * @param string $root
   *   Path to the root of the Drupal installation.
   * @param string $suite_namespace
   *   SubNamespace used to separate test suite. Examples: Unit, Functional.
   * @param string $pattern
   *   REGEXP pattern to apply to file name.
   */
  protected function addExtensionTestsBySuiteNamespace($root, $suite_namespace, $pattern) {
    $failing_classes = [];
    foreach ($this->failingClasses as $failing_class) {
      $failing_classes[] = $root . $failing_class;
    }

    // Extensions' tests will always be in the namespace
    // Drupal\Tests\$extension_name\$suite_namespace\ and be in the
    // $extension_path/tests/src/$suite_namespace directory. Not all extensions
    // will have all kinds of tests.
    foreach ($this
      ->findExtensionDirectories($root) as $extension_name => $dir) {
      if (preg_match("#^{$pattern}(.*)\$#i", $extension_name) !== 0) {
        $test_path = "{$dir}/tests/src/{$suite_namespace}";
        if (is_dir($test_path)) {
          $passing_tests = [];
          $tests = TestDiscovery::scanDirectory("Drupal\\Tests\\{$extension_name}\\{$suite_namespace}\\", $test_path);
          foreach ($tests as $test) {
            if (!in_array($test, $failing_classes)) {
              $passing_tests[] = $test;
            }
          }
          $this
            ->addTestFiles($passing_tests);
        }
      }
    }
  }

  /**
   * Find and add tests to the suite for core and any extensions.
   *
   * @param string $root
   *   Path to the root of the Drupal installation.
   * @param string $suite_namespace
   *   SubNamespace used to separate test suite. Examples: Unit, Functional.
   * @param int $index
   *   The chunk number to test.
   */
  protected function addExtensionTestsBySuiteNamespaceAndChunk($root, $suite_namespace, $index = 0) {
    $failing_classes = [];
    foreach ($this->failingClasses as $failing_class) {
      $failing_classes[] = $root . $failing_class;
    }

    // Extensions' tests will always be in the namespace
    // Drupal\Tests\$extension_name\$suite_namespace\ and be in the
    // $extension_path/tests/src/$suite_namespace directory. Not all extensions
    // will have all kinds of tests.
    $passing_tests = [];
    foreach ($this
      ->findExtensionDirectories($root) as $extension_name => $dir) {
      $test_path = "{$dir}/tests/src/{$suite_namespace}";
      if (is_dir($test_path)) {
        $tests = TestDiscovery::scanDirectory("Drupal\\Tests\\{$extension_name}\\{$suite_namespace}\\", $test_path);
        foreach ($tests as $test) {
          if (!in_array($test, $failing_classes)) {
            $passing_tests[] = $test;
          }
        }
      }
    }
    $sizes = [
      17,
      34,
      25,
      30,
      30,
      25,
      25,
      25,
      30,
      25,
      25,
      15,
      25,
      25,
      25,
      25,
      25,
      25,
      30,
      25,
      25,
      25,
      25,
      25,
      25,
      25,
      25,
      25,
      25,
      25,
      25,
      25,
      25,
      20,
      20,
      25,
      25,
      25,
      25,
      25,
      25,
      25,
      25,
      25,
      25,
      30,
      25,
      25,
      25,
      25,
      25,
      25,
      25,
      25,
      25,
      25,
      25,
      25,
      25,
    ];
    $index = rand(0, 58);
    $length = $sizes[$index];
    $offset = $index == 0 ? 0 : array_sum(array_splice($sizes, 0, $index));
    $subset = array_splice($passing_tests, $offset, $length);
    fwrite(STDOUT, "SPLICE:" . $index);
    $this
      ->addTestFiles($subset);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TestSuiteBase::$coreExtensionPatterns protected static property Regex patterns to split up core Kernel extensions.
TestSuiteBase::$failingClasses protected property The failing test files.
TestSuiteBase::addExtensionTestsBySuiteNamespace protected function Find and add tests to the suite for core and any extensions.
TestSuiteBase::addExtensionTestsBySuiteNamespaceAndChunk protected function Find and add tests to the suite for core and any extensions.
TestSuiteBase::findExtensionDirectories protected function Finds extensions in a Drupal installation.