Skip to content

Commit

Permalink
Merge pull request #32 from City-of-Helsinki/UHF-3861
Browse files Browse the repository at this point in the history
UHF-3861: Remove special handling for image styles
  • Loading branch information
tuutti authored Mar 8, 2022
2 parents c28e56d + 21ba756 commit 68189cc
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ env:
SIMPLETEST_DB: "mysql://drupal:drupal@db:3306/drupal"
SIMPLETEST_BASE_URL: "http://127.0.0.1:8888"
SYMFONY_DEPRECATIONS_HELPER: disabled
BROWSERTEST_OUTPUT_DIRECTORY: 'sites/simpletest'
jobs:
tests:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -53,3 +54,11 @@ jobs:
vendor/bin/drush runserver $SIMPLETEST_BASE_URL > /dev/null 2>&1 &
chromedriver --port=4444 > /dev/null 2>&1 &
vendor/bin/phpunit --fail-on-skipped -c $DRUPAL_ROOT/phpunit.platform.xml --verbose --group ${{ secrets.MODULE_NAME }}
- name: Create an artifact from test report
uses: actions/upload-artifact@v2
if: always()
with:
name: results
path: ${{ env.DRUPAL_ROOT }}/sites/simpletest/browser_output/
retention-days: 1
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.phpunit.cache
14 changes: 3 additions & 11 deletions src/ProxyManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,6 @@ private function getAttributeValue(AttributeSelector $selector, Request $request
return $value;
}

// Image styles need special handling because they need to be run through
// PHP before they are uploaded to CDN.
if (str_contains($value, '/files/styles/')) {
if ($selector instanceof MultiValueAttributeSelector) {
return $this->handleMultiValue($value, $selector->multivalueSeparator,
function (string $value): string {
return $this->addDomain($value);
});
}
return $this->addDomain($value);
}
// Certain elements might be absolute URLs already (such as og:image:url).
// Make sure locally hosted files are always served from correct domain.
if ($selector instanceof AbsoluteUriAttributeSelector) {
Expand All @@ -138,6 +127,9 @@ function (string $value): string {
if ($selector instanceof MultiValueAttributeSelector) {
return $this->handleMultiValue($value, $selector->multivalueSeparator,
function (string $value) : string {
if ($this->isAbsoluteUri($value)) {
return $value;
}
return $this->addAssetPath($value);
}
);
Expand Down
Empty file.
8 changes: 5 additions & 3 deletions tests/src/Kernel/ProxyManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,14 @@ public function testMultivalueAttributeSelector() : void {
$html = $this->createHtmlTag('source', ['srcset' => implode(', ', $values)]);

$expectedValues = [
'//' . $this->getHostname() . '/sites/default/files/styles/test/public/image.png?h=948e8679&itok=FwETi0jH 1x',
'//' . $this->getHostname() . '/sites/default/files/styles/test/public/image.png?h=948e8679&itok=FwETi0jH 1x',
'/test-assets/sites/default/files/styles/test/public/image.png?h=948e8679&itok=FwETi0jH 1x',
'/test-assets/sites/default/files/styles/test/public/image.png?h=948e8679&itok=FwETi0jH 1x',
// Make sure absolute uris are ignored.
'//helfi-kymp.docker.so/sites/default/files/styles/3_2_xxs_2x/public/image%20%281%29.png?itok=pSa7Ws3i 2x',
];
$expected = $this->createHtmlTag('source', ['srcset' => implode(', ', $expectedValues)]);
$expected = $this->createHtmlTag('source', [
'srcset' => implode(', ', $expectedValues),
]);

$this->assertEquals(
$expected,
Expand Down

0 comments on commit 68189cc

Please sign in to comment.