namespace Drupal\image\Tests;
use Drupal\image\Entity\ImageStyle;
+use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\simpletest\WebTestBase;
/**
*
* @var array
*/
- public static $modules = ['image', 'image_module_test'];
+ public static $modules = ['image', 'image_module_test', 'language'];
/**
+ * The image style.
+ *
* @var \Drupal\image\ImageStyleInterface
*/
protected $style;
+ /**
+ * {@inheritdoc}
+ */
protected function setUp() {
parent::setUp();
- $this->style = ImageStyle::create(['name' => 'style_foo', 'label' => $this->randomString()]);
+ $this->style = ImageStyle::create([
+ 'name' => 'style_foo',
+ 'label' => $this->randomString(),
+ ]);
$this->style->save();
+
+ // Create a new language.
+ ConfigurableLanguage::createFromLangcode('fr')->save();
}
/**
$this->doImageStyleUrlAndPathTests('private', FALSE);
}
+ /**
+ * Tests an image style URL with the "public://" schema and language prefix.
+ */
+ public function testImageStyleUrlAndPathPublicLanguage() {
+ $this->doImageStyleUrlAndPathTests('public', TRUE, TRUE, 'fr');
+ }
+
+ /**
+ * Tests an image style URL with the "private://" schema and language prefix.
+ */
+ public function testImageStyleUrlAndPathPrivateLanguage() {
+ $this->doImageStyleUrlAndPathTests('private', TRUE, TRUE, 'fr');
+ }
+
/**
* Tests an image style URL with a file URL that has an extra slash in it.
*/
/**
* Tests building an image style URL.
*/
- public function doImageStyleUrlAndPathTests($scheme, $clean_url = TRUE, $extra_slash = FALSE) {
+ public function doImageStyleUrlAndPathTests($scheme, $clean_url = TRUE, $extra_slash = FALSE, $langcode = FALSE) {
$this->prepareRequestForGenerator($clean_url);
// Make the default scheme neither "public" nor "private" to verify the
$status = file_prepare_directory($directory, FILE_CREATE_DIRECTORY);
$this->assertNotIdentical(FALSE, $status, 'Created the directory for the generated images for the test style.');
+ // Override the language to build the URL for the correct language.
+ if ($langcode) {
+ $language_manager = \Drupal::service('language_manager');
+ $language = $language_manager->getLanguage($langcode);
+ $language_manager->setConfigOverrideLanguage($language);
+ }
+
// Create a working copy of the file.
$files = $this->drupalGetTestFiles('image');
$file = array_shift($files);
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
$generate_url = $this->style->buildUrl($original_uri, $clean_url);
+ // Make sure that language prefix is never added to the image style URL.
+ if ($langcode) {
+ $this->assertTrue(strpos($generate_url, "/$langcode/") === FALSE, 'Langcode was not found in the image style URL.');
+ }
+
// Ensure that the tests still pass when the file is generated by accessing
// a poorly constructed (but still valid) file URL that has an extra slash
// in it.
$this->assertEqual($this->drupalGetHeader('Content-Length'), $image->getFileSize(), 'Expected Content-Length was reported.');
// Check that we did not download the original file.
- $original_image = $this->container->get('image.factory')->get($original_uri);
+ $original_image = $this->container->get('image.factory')
+ ->get($original_uri);
$this->assertNotEqual($this->drupalGetHeader('Content-Length'), $original_image->getFileSize());
if ($scheme == 'private') {
$this->drupalGet($generate_url_noaccess);
$this->assertResponse(403, 'Confirmed that access is denied for the private image style.');
- // Verify that images are not appended to the response. Currently this test only uses PNG images.
+ // Verify that images are not appended to the response.
+ // Currently this test only uses PNG images.
if (strpos($generate_url, '.png') === FALSE) {
$this->fail('Confirming that private image styles are not appended require PNG file.');
}
else {
- // Check for PNG-Signature (cf. http://www.libpng.org/pub/png/book/chapter08.html#png.ch08.div.2) in the
- // response body.
+ // Check for PNG-Signature
+ // (cf. http://www.libpng.org/pub/png/book/chapter08.html#png.ch08.div.2)
+ // in the response body.
$this->assertNoRaw(chr(137) . chr(80) . chr(78) . chr(71) . chr(13) . chr(10) . chr(26) . chr(10), 'No PNG signature found in the response body.');
}
}
// Allow insecure image derivatives to be created for the remainder of this
// test.
- $this->config('image.settings')->set('allow_insecure_derivatives', TRUE)->save();
+ $this->config('image.settings')
+ ->set('allow_insecure_derivatives', TRUE)
+ ->save();
// Create another working copy of the file.
$files = $this->drupalGetTestFiles('image');
// Stop supressing the security token in the URL.
$this->config('image.settings')->set('suppress_itok_output', FALSE)->save();
// Ensure allow_insecure_derivatives is enabled.
- $this->assertEqual($this->config('image.settings')->get('allow_insecure_derivatives'), TRUE);
+ $this->assertEqual($this->config('image.settings')
+ ->get('allow_insecure_derivatives'), TRUE);
// Check that a security token is still required when generating a second
// image derivative using the first one as a source.
$nested_url = $this->style->buildUrl($generated_uri, $clean_url);