-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5cc52f3
commit d03d2a6
Showing
9 changed files
with
155 additions
and
70 deletions.
There are no files selected for viewing
This file contains 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,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace HTML\Sourceopt\Middleware; | ||
|
||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\StreamInterface; | ||
use Psr\Http\Server\MiddlewareInterface; | ||
use TYPO3\CMS\Core\Http\NullResponse; | ||
use TYPO3\CMS\Core\Http\Stream; | ||
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; | ||
|
||
abstract class AbstractMiddleware implements MiddlewareInterface | ||
{ | ||
protected function responseIsAlterable(ResponseInterface $response): bool | ||
{ | ||
if (!$response instanceof NullResponse) { | ||
return false; | ||
} | ||
|
||
if (!$GLOBALS['TSFE'] instanceof TypoScriptFrontendController) { // need for configuration | ||
return false; | ||
} | ||
|
||
if ('text/html' !== substr($response->getHeaderLine('Content-Type'), 0, 9)) { | ||
return false; | ||
} | ||
|
||
if (empty($response->getBody())) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
protected function getStringStream(string $content): StreamInterface | ||
{ | ||
$body = new Stream('php://temp', 'rw'); | ||
$body->write($content); | ||
|
||
return $body; | ||
} | ||
} |
This file contains 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 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 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 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,8 @@ | ||
services: | ||
_defaults: | ||
autowire: true | ||
autoconfigure: true | ||
public: false | ||
|
||
HTML\Sourceopt\: | ||
resource: '../Classes/*' |
This file contains 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,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace HTML\Sourceopt\Tests\Unit; | ||
|
||
abstract class AbstractUnitTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
} |
This file contains 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,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace HTML\Sourceopt\Tests\Unit\Service; | ||
|
||
use HTML\Sourceopt\Manipulation\RemoveComments; | ||
use HTML\Sourceopt\Tests\Unit\AbstractUnitTest; | ||
|
||
/** | ||
* @internal | ||
* | ||
* @coversNothing | ||
*/ | ||
class RemoveCommentTest extends AbstractUnitTest | ||
{ | ||
/** | ||
* @dataProvider generatorProvider | ||
*/ | ||
public function testRemoveComment($before, $after): void | ||
{ | ||
$cleanService = new RemoveComments(); | ||
$result = $cleanService->manipulate($before); | ||
|
||
$this->assertEquals($after, $result); | ||
} | ||
|
||
public static function generatorProvider(): array | ||
{ | ||
return [ | ||
[ | ||
'<head> | ||
<meta name="Regisseur" content="Peter Jackson"> | ||
<meta name="generator" content="Tester"> | ||
<!-- Ich bin ein Test --> | ||
</head>', | ||
'<head> | ||
<meta name="Regisseur" content="Peter Jackson"> | ||
<meta name="generator" content="Tester"> | ||
</head>', | ||
], | ||
[ | ||
'<head> | ||
<!-- Ich bin ein Test --> | ||
<meta name="Regisseur" content="Peter Jackson"> | ||
<meta name="generator" content="Tester"> | ||
<!-- Ich bin ein Test --> | ||
</head>', | ||
'<head> | ||
<meta name="Regisseur" content="Peter Jackson"> | ||
<meta name="generator" content="Tester"> | ||
</head>', | ||
], | ||
]; | ||
} | ||
} |
This file contains 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 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