diff --git a/lib/common/src/Attribute.php b/lib/common/src/Attribute.php index 8321e408596..a7e4df5b05a 100644 --- a/lib/common/src/Attribute.php +++ b/lib/common/src/Attribute.php @@ -59,6 +59,8 @@ interface Attribute const ALL_AMP4ADS = [self::AMP4ADS, self::AMP4ADS_EMOJI, self::AMP4ADS_EMOJI_ALT]; const ALL_AMP4EMAIL = [self::AMP4EMAIL, self::AMP4EMAIL_EMOJI, self::AMP4EMAIL_EMOJI_ALT]; + const ALL_BOILERPLATES = [self::AMP_BOILERPLATE, self::AMP4ADS_BOILERPLATE, self::AMP4EMAIL_BOILERPLATE]; + const TYPE_HTML = 'text/html'; const TYPE_JSON = 'application/json'; const TYPE_LD_JSON = 'application/ld+json'; diff --git a/lib/optimizer/src/Transformer/AmpBoilerplate.php b/lib/optimizer/src/Transformer/AmpBoilerplate.php index e49d6ddfc2d..5acf7c405c6 100644 --- a/lib/optimizer/src/Transformer/AmpBoilerplate.php +++ b/lib/optimizer/src/Transformer/AmpBoilerplate.php @@ -4,7 +4,6 @@ use AmpProject\Amp; use AmpProject\Attribute; -use AmpProject\DevMode; use AmpProject\Dom\Document; use AmpProject\Optimizer\ErrorCollection; use AmpProject\Optimizer\Transformer; @@ -12,8 +11,8 @@ use DOMElement; /** - * Transformer that removes ' . @@ -57,65 +46,81 @@ public function dataTransform() $amp4EmailBoilerplate = ''; return [ - 'keeps boilerplate' => [ - $inputWithBoilerplate('', $ampBoilerplate), - $expected('', $ampBoilerplate), - ], + 'keeps boilerplate' => $repeatTwice( + $htmlDocument('', $ampBoilerplate) + ), - 'keeps boilerplate for amp4ads' => [ - $inputWithBoilerplate('', $amp4AdsBoilerplate), - $expected('', $amp4AdsBoilerplate), - ], + 'keeps boilerplate again' => $repeatTwice( + $htmlDocument('', $ampBoilerplate) + ), - 'keeps boilerplate for ⚡4ads' => [ - $inputWithBoilerplate('', $amp4AdsBoilerplate), - $expected('', $amp4AdsBoilerplate), + 'removes incorrect boilerplates' => [ + $htmlDocument('', $ampBoilerplate . $amp4AdsBoilerplate . $amp4EmailBoilerplate), + $htmlDocument('', $ampBoilerplate), ], - 'keeps boilerplate for amp4email' => [ - $inputWithBoilerplate('', $amp4EmailBoilerplate), - $expected('', $amp4EmailBoilerplate), - ], + 'leaves out boilerplate' => $repeatTwice( + $htmlDocument('') + ), - 'keeps boilerplate for ⚡4email' => [ - $inputWithBoilerplate('', $amp4EmailBoilerplate), - $expected('', $amp4EmailBoilerplate), + 'removes boilerplate' => [ + $htmlDocument('', $ampBoilerplate), + $htmlDocument(''), ], + 'keeps boilerplate for amp4ads' => $repeatTwice( + $htmlDocument('', $amp4AdsBoilerplate) + ), + + 'keeps boilerplate for ⚡4ads' => $repeatTwice( + $htmlDocument('', $amp4AdsBoilerplate) + ), + + 'keeps boilerplate for amp4email' => $repeatTwice( + $htmlDocument('', $amp4EmailBoilerplate) + ), + + 'keeps boilerplate for ⚡4email' => $repeatTwice( + $htmlDocument('', $amp4EmailBoilerplate) + ), + 'adds boilerplate if missing' => [ - $inputWithoutBoilerplate(''), - $expected('', $ampBoilerplate), + $htmlDocument(''), + $htmlDocument('', $ampBoilerplate), ], 'adds boilerplate if missing for amp4ads' => [ - $inputWithoutBoilerplate(''), - $expected('', $amp4AdsBoilerplate), + $htmlDocument(''), + $htmlDocument('', $amp4AdsBoilerplate), ], 'adds boilerplate if missing for ⚡4ads' => [ - $inputWithoutBoilerplate(''), - $expected('', $amp4AdsBoilerplate), + $htmlDocument(''), + $htmlDocument('', $amp4AdsBoilerplate), ], 'adds boilerplate if missing for amp4email' => [ - $inputWithoutBoilerplate(''), - $expected('', $amp4EmailBoilerplate), + $htmlDocument(''), + $htmlDocument('', $amp4EmailBoilerplate), ], 'adds boilerplate if missing for ⚡4email' => [ - $inputWithoutBoilerplate(''), - $expected('', $amp4EmailBoilerplate), + $htmlDocument(''), + $htmlDocument('', $amp4EmailBoilerplate), ], - 'keeps devmode nodes when in devmode' => [ - $inputWithBoilerplate('', '' . $ampBoilerplate), - $expected('', '' . $ampBoilerplate), - ], + 'leaves styles that lack boilerplate attribute' => $repeatTwice( + $htmlDocument('', '' . $ampBoilerplate) + ), - 'removes devmode nodes when not in devmode' => [ - $inputWithBoilerplate('', '' . $ampBoilerplate), - $expected('', $ampBoilerplate), + 'leaves styles that lack boilerplate attribute and adds boilerplate' => [ + $htmlDocument('', ''), + $htmlDocument('', '' . $ampBoilerplate), ], + + 'leaves styles that lack boilerplate attribute and leaves out boilerplate' => $repeatTwice( + $htmlDocument('', '') + ), ]; }