diff --git a/Test/Integration/AbstractTestCase.php b/Test/Integration/AbstractTestCase.php new file mode 100644 index 0000000..1f51fd0 --- /dev/null +++ b/Test/Integration/AbstractTestCase.php @@ -0,0 +1,16 @@ +_objectManager->get(ScopeConfigInterface::class); + $this->assertEquals($expectedValue, $scopeConfig->getValue('system/yireo_linkpreload/enabled')); + } +} diff --git a/Test/Integration/BodyTest.php b/Test/Integration/BodyTest.php new file mode 100644 index 0000000..88c7333 --- /dev/null +++ b/Test/Integration/BodyTest.php @@ -0,0 +1,55 @@ +assertEnabledValue(1); + $this->dispatch('/'); + $body = (string)$this->getResponse()->getBody(); + foreach ((new LinkDataProvider())->getLinks() as $link) { + $this->assertBodyContainsLink($link[0], $link[1], $body); + } + } + + /** + * @magentoAdminConfigFixture system/yireo_linkpreload/enabled 1 + * @magentoCache full_page enabled + * @magentoDbIsolation enabled + * @magentoAppIsolation enabled + */ + public function testIfLinkHeadersExistsWhenModuleIsEnabledAndWithFullPageCache() + { + if (constant('TESTS_CLEANUP') === 'disabled') { + $this->markTestSkipped('Test does not work with TESTS_CLEANUP disabled'); + } + + $this->assertEnabledValue(1); + $this->dispatch('/'); + $body = (string)$this->getResponse()->getBody(); + $this->assertNotEmpty($body); + + foreach ((new LinkDataProvider())->getLinks() as $link) { + $this->assertBodyContainsLink($link[0], $link[1], $body); + } + } + + private function assertBodyContainsLink(string $type, string $uri, string $body) + { + preg_match_all('##', $body, $matches); + + $foundUri = false; + foreach ($matches[0] as $match) { + if (strstr($match, $uri)) { + $foundUri = true; + } + } + + $this->assertTrue($foundUri, 'URI "'.$uri.'" not found in body: '.$body); + } +} diff --git a/Test/Integration/LinkDataProvider.php b/Test/Integration/LinkDataProvider.php new file mode 100644 index 0000000..763aac1 --- /dev/null +++ b/Test/Integration/LinkDataProvider.php @@ -0,0 +1,19 @@ + - -