You are here

class S3fsCssOptimizerTest in S3 File System 4.0.x

Same name and namespace in other branches
  1. 8.3 tests/src/Unit/S3fsCssOptimizerTest.php \Drupal\Tests\s3fs\Unit\S3fsCssOptimizerTest

Tests the S3fsCssOptimizer.

@group s3fs

Hierarchy

Expanded class hierarchy of S3fsCssOptimizerTest

File

tests/src/Unit/S3fsCssOptimizerTest.php, line 15

Namespace

Drupal\Tests\s3fs\Unit
View source
class S3fsCssOptimizerTest extends UnitTestCase {

  /**
   * Test general asset link re-writing.
   */
  public function testRewriteUri() {
    $configFactory = $this
      ->getConfigFactoryStub([
      's3fs.settings' => [
        'use_https' => FALSE,
        'use_cssjs_host' => FALSE,
        'cssjs_host' => '',
      ],
    ]);
    $cssOptimizer = new S3fsCssOptimizer($configFactory);
    $cssOptimizer->rewriteFileURIBasePath = '';
    $this
      ->assertEquals('url(//www.example.org/test/file.txt)', $cssOptimizer
      ->rewriteFileURI([
      '',
      '/test/file.txt',
    ]));
    $this
      ->assertEquals('url(//www.example.org/test/file.txt)', $cssOptimizer
      ->rewriteFileURI([
      '',
      '/core/../test/file.txt',
    ]));
    $this
      ->assertEquals('url(//www.example.org/test/file.txt)', $cssOptimizer
      ->rewriteFileURI([
      '',
      '/core/data/../../test/file.txt',
    ]));
  }

  /**
   * Test asset links generated using HTTPS://.
   */
  public function testRewriteUriAlwaysHttps() {
    $configFactory = $this
      ->getConfigFactoryStub([
      's3fs.settings' => [
        'use_https' => TRUE,
        'use_cssjs_host' => FALSE,
        'cssjs_host' => '',
      ],
    ]);
    $cssOptimizer = new S3fsCssOptimizer($configFactory);
    $cssOptimizer->rewriteFileURIBasePath = '';
    $this
      ->assertEquals('url(https://www.example.org/test/file.txt)', $cssOptimizer
      ->rewriteFileURI([
      '',
      '/test/file.txt',
    ]));
  }

  /**
   * Test asset links with custom host.
   */
  public function testRewriteUriCustomCssHost() {
    $configFactory = $this
      ->getConfigFactoryStub([
      's3fs.settings' => [
        'use_https' => FALSE,
        'use_cssjs_host' => TRUE,
        'cssjs_host' => 'test.example.org',
      ],
    ]);
    $cssOptimizer = new S3fsCssOptimizer($configFactory);
    $cssOptimizer->rewriteFileURIBasePath = '';
    $this
      ->assertEquals('url(//test.example.org/test/file.txt)', $cssOptimizer
      ->rewriteFileURI([
      '',
      '/test/file.txt',
    ]));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PhpUnitWarnings::$deprecationWarnings private static property Deprecation warnings from PHPUnit to raise with @trigger_error().
PhpUnitWarnings::addWarning public function Converts PHPUnit deprecation warnings to E_USER_DEPRECATED.
S3fsCssOptimizerTest::testRewriteUri public function Test general asset link re-writing.
S3fsCssOptimizerTest::testRewriteUriAlwaysHttps public function Test asset links generated using HTTPS://.
S3fsCssOptimizerTest::testRewriteUriCustomCssHost public function Test asset links with custom host.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals Deprecated protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUp protected function 308
UnitTestCase::setUpBeforeClass public static function