-
Notifications
You must be signed in to change notification settings - Fork 1
bugfix-add-resource-loader #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # Exclude from release archives | ||
| /.github export-ignore | ||
| /Tests export-ignore | ||
| .gitattributes export-ignore | ||
| .gitignore export-ignore | ||
| grumphp.yml export-ignore | ||
| Makefile export-ignore | ||
| phpstan.neon export-ignore | ||
| phpstan-baseline.neon export-ignore | ||
| phpunit.xml export-ignore | ||
| rector.php export-ignore |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,3 +3,4 @@ vendor | |
| public | ||
| composer.lock | ||
| var/ | ||
| .phpunit.result.cache | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| use Pluswerk\PlusMinify\Middleware\MinifyMiddleware; | ||
|
|
||
| return [ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| ACT_IMAGE ?= efrecon/act:v0.2.80 | ||
| WORKDIR ?= /work | ||
| UID_GID := $(shell id -u):$(shell id -g) | ||
| DOCKER_GID := $(shell stat -c '%g' /var/run/docker.sock) | ||
|
|
||
| PLATFORM ?= -P ubuntu-latest=ghcr.io/catthehacker/ubuntu:act-24.04 | ||
|
|
||
| # Secrets-File in ENV format | ||
| SECRETS ?= --secret-file .secrets | ||
|
|
||
| ACT_ARGS ?= \ | ||
| --artifact-server-path /home/act/.cache/artifacts | ||
|
|
||
| define DOCKER_RUN | ||
| docker run --rm -it \ | ||
| -u $(UID_GID) \ | ||
| --group-add $(DOCKER_GID) \ | ||
| -e HOME=/home/act \ | ||
| -e XDG_CACHE_HOME=/home/act/.cache \ | ||
| -e ACT_CACHE_DIR=/home/act/.cache/actcache \ | ||
| -v /var/run/docker.sock:/var/run/docker.sock \ | ||
| -v $(PWD):$(WORKDIR) -w $(WORKDIR) \ | ||
| -v $$HOME/.cache:/home/act/.cache \ | ||
| $(ACT_IMAGE) | ||
| endef | ||
|
|
||
| # ---- Targets ---- | ||
| .PHONY: all ci clean | ||
|
|
||
| all: ci clean | ||
|
|
||
| ci: ## Standard-Event "push" | ||
| $(DOCKER_RUN) $(PLATFORM) $(SECRETS) $(ACT_ARGS) 2>&1 | tee /tmp/act-output.log; \ | ||
| echo ""; \ | ||
| echo "=== 🏁 Summary ==="; \ | ||
| grep "🏁" /tmp/act-output.log || true | ||
|
|
||
|
|
||
| clean: | ||
| docker rm -f $$(docker ps -aq --filter "name=act-") 2>/dev/null || true | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Pluswerk\PlusMinify\Tests\Unit\Service; | ||
|
|
||
| use PHPUnit\Framework\Attributes\Test; | ||
| use PHPUnit\Framework\TestCase; | ||
| use Pluswerk\PlusMinify\Service\MinifyService; | ||
|
|
||
| class MinifyServiceTest extends TestCase | ||
| { | ||
| private MinifyService $subject; | ||
|
|
||
| protected function setUp(): void | ||
| { | ||
| parent::setUp(); | ||
|
|
||
| // Reset all minify feature flags — everything disabled by default | ||
| $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['minify'] = []; | ||
|
|
||
| $this->subject = new MinifyService(); | ||
| } | ||
|
|
||
| // ------------------------------------------------------------------------- | ||
| // All features off (default) | ||
| // ------------------------------------------------------------------------- | ||
|
|
||
| #[Test] | ||
| public function minifyKeepsHtmlCommentsWhenNoFeaturesAreEnabled(): void | ||
| { | ||
| $html = '<html><head><meta charset="utf-8"><!-- a comment --></head><body><p>Hello</p></body></html>'; | ||
|
|
||
| $result = $this->subject->minify($html); | ||
|
|
||
| self::assertStringContainsString('<!-- a comment -->', $result); | ||
| } | ||
|
|
||
| #[Test] | ||
| public function minifyKeepsTypo3CommentWhenNoFeaturesAreEnabled(): void | ||
| { | ||
| $html = '<html><head><meta charset="utf-8"><!-- TYPO3 page info --></head><body><p>Hello</p></body></html>'; | ||
|
|
||
| $result = $this->subject->minify($html); | ||
|
|
||
| self::assertStringContainsString('<!-- TYPO3 page info -->', $result); | ||
| } | ||
|
|
||
| // ------------------------------------------------------------------------- | ||
| // remove_comments alone — comment removal needs the DOM parser too, | ||
| // so the output stays unchanged when only remove_comments is set. | ||
| // ------------------------------------------------------------------------- | ||
|
|
||
| #[Test] | ||
| public function minifyDoesNotRemoveCommentsWithOnlyRemoveCommentsFlagEnabled(): void | ||
| { | ||
| $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['minify']['remove_comments'] = '1'; | ||
|
|
||
| $html = '<html><head><meta charset="utf-8"></head><body><!-- just a comment --><p>Hello</p></body></html>'; | ||
|
|
||
| $result = $this->subject->minify($html); | ||
|
|
||
| // Without the DOM parser the minifier cannot parse the tree, | ||
| // so the comment is left in the output. | ||
| self::assertStringContainsString('<!-- just a comment -->', $result); | ||
| } | ||
|
|
||
| // ------------------------------------------------------------------------- | ||
| // remove_comments + optimize_via_html_dom_parser (the realistic combination) | ||
| // ------------------------------------------------------------------------- | ||
|
|
||
| #[Test] | ||
| public function minifyRemovesRegularCommentsWhenRemoveCommentsAndDomParserAreEnabled(): void | ||
| { | ||
| $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['minify']['remove_comments'] = '1'; | ||
| $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['minify']['optimize_via_html_dom_parser'] = '1'; | ||
|
|
||
| $html = '<html><head><meta charset="utf-8"></head><body><!-- just a comment --><p>Hello</p></body></html>'; | ||
|
|
||
| $result = $this->subject->minify($html); | ||
|
|
||
| self::assertStringNotContainsString('<!-- just a comment -->', $result); | ||
| self::assertStringContainsString('<p>Hello</p>', $result); | ||
| } | ||
|
|
||
| #[Test] | ||
| public function minifyPreservesTypo3CommentWhenRemoveCommentsAndDomParserAreEnabled(): void | ||
| { | ||
| $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['minify']['remove_comments'] = '1'; | ||
| $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['minify']['optimize_via_html_dom_parser'] = '1'; | ||
|
|
||
| $html = '<html><head><meta charset="utf-8"><!-- TYPO3CMS id=1 --></head><body><p>Hello</p></body></html>'; | ||
|
|
||
| $result = $this->subject->minify($html); | ||
|
|
||
| self::assertStringContainsString('<!-- TYPO3CMS id=1 -->', $result); | ||
| } | ||
|
|
||
| #[Test] | ||
| public function minifyRemovesRegularCommentButKeepsTypo3CommentWhenBothFlagsAreEnabled(): void | ||
| { | ||
| $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['minify']['remove_comments'] = '1'; | ||
| $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['minify']['optimize_via_html_dom_parser'] = '1'; | ||
|
|
||
| $html = '<html><head><meta charset="utf-8"><!-- TYPO3 page --></head><body><!-- drop me --><p>Hello</p></body></html>'; | ||
|
|
||
| $result = $this->subject->minify($html); | ||
|
|
||
| self::assertStringContainsString('<!-- TYPO3 page -->', $result); | ||
| self::assertStringNotContainsString('<!-- drop me -->', $result); | ||
| } | ||
|
|
||
| // ------------------------------------------------------------------------- | ||
| // Output integrity | ||
| // ------------------------------------------------------------------------- | ||
|
|
||
| #[Test] | ||
| public function minifyReturnsFallbackHtmlWhenMinifierProducesEmptyString(): void | ||
| { | ||
| // An empty string causes the minifier to return '' which triggers | ||
| // the $originalHtml fallback — the method must not crash. | ||
| $result = $this->subject->minify(''); | ||
|
|
||
| self::assertSame('', $result); | ||
| } | ||
|
|
||
| #[Test] | ||
| public function minifyAppendsClosingBodyTagWhenAbsentFromMinifiedOutput(): void | ||
| { | ||
| // Enable features that actually cause HtmlMin to strip closing tags. | ||
| $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['minify']['remove_comments'] = '1'; | ||
| $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['minify']['optimize_via_html_dom_parser'] = '1'; | ||
| $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['minify']['remove_omitted_html_tags'] = '1'; | ||
|
|
||
| $html = '<html><head><meta charset="utf-8"></head><body><p>Hello</p></body></html>'; | ||
|
|
||
| $result = $this->subject->minify($html); | ||
|
|
||
| self::assertStringEndsWith('</body>', $result); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| use Composer\InstalledVersions; | ||
|
|
||
| /** @var string $_EXTKEY */ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <phpunit | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd" bootstrap="vendor/autoload.php" executionOrder="depends,defects" beStrictAboutOutputDuringTests="true" failOnRisky="true" failOnWarning="true"> | ||
| <testsuites> | ||
| <testsuite name="default"> | ||
| <directory>Tests</directory> | ||
| </testsuite> | ||
| </testsuites> | ||
| <source> | ||
| <include> | ||
| <directory suffix=".php">Classes</directory> | ||
| </include> | ||
| </source> | ||
| </phpunit> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.