You are here

class ExtensionsTest in Autoload 7.2

Same name and namespace in other branches
  1. 7 src/Tests/Unit/ExtensionsTest.php \Drupal\autoload\Tests\Unit\ExtensionsTest

Class ExtensionsTest.

Hierarchy

  • class \Drupal\autoload\Tests\Unit\AutoloadTestBase extends \Drupal\autoload\Tests\Unit\DrupalWebTestCase

Expanded class hierarchy of ExtensionsTest

File

src/Tests/Unit/ExtensionsTest.php, line 8

Namespace

Drupal\autoload\Tests\Unit
View source
class ExtensionsTest extends AutoloadTestBase {

  /**
   * {@inheritdoc}
   */
  protected static $modules = array(
    'autoload_test_extensions',
  );

  /**
   * {@inheritdoc}
   */
  public static function getInfo() {
    return static::info(t('Ensure registered file extensions are available for autoloading.'));
  }

  /**
   * {@inheritdoc}
   */
  public function test() {

    // These extensions are always available!
    $this
      ->assertExtensions(array(
      '.php',
      '.inc',
    ));

    // Only Drupal can change this. Modules cannot!
    spl_autoload_extensions('.test');

    // List of extensions changed as expected.
    $this
      ->assertExtensions(array(
      '.php',
      '.inc',
      '.test',
    ));

    // Class must not exist since an extension was registered not by Drupal.
    $this
      ->assertFalse(class_exists('Drupal\\autoload_test_extensions\\PSR4'), 'A class cannot be loaded despite on registered file extension.');
  }

  /**
   * Assert registered extensions for autoloading.
   *
   * @param string[] $extensions
   *   Extensions list. Each one must start from dot.
   */
  protected function assertExtensions(array $extensions) {
    $this
      ->assertFalse(array_diff(autoload_extensions(), $extensions), 'Required extensions available.');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AutoloadTestBase::$autoloadFile protected property A path to file with the autoloading class map.
AutoloadTestBase::$profile protected property
AutoloadTestBase::info protected static function Returns an information about the test.
AutoloadTestBase::preloadRegistry protected function
AutoloadTestBase::setUp protected function
ExtensionsTest::$modules protected static property Modules which should enabled for testing. Overrides AutoloadTestBase::$modules
ExtensionsTest::assertExtensions protected function Assert registered extensions for autoloading.
ExtensionsTest::getInfo public static function
ExtensionsTest::test public function