Skip to content

Commit

Permalink
Add test to ensure that the script sanitizer sets prefer_bento
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter committed Aug 27, 2021
1 parent cb98871 commit 23c518b
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions tests/php/test-amp-script-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ public function test_cascading_sanitizer_argument_changes_with_custom_scripts( $
<audio src="https://example.com/music.mp3" width="300" height="100"></audio>
<video src="https://example.com/movie.mp4" width="640" height="480"></video>
<iframe src="https://example.com/" width="100%" height="400"></iframe>
<amp-facebook-page width="340" height="130" layout="responsive" data-href="https://www.facebook.com/imdb/"></amp-facebook-page>
<form action="https://example.com/subscribe/" method="post">
<input type="email" name="email">
</form>
Expand All @@ -397,7 +398,7 @@ public function test_cascading_sanitizer_argument_changes_with_custom_scripts( $
);

$sanitizers = [
AMP_Script_Sanitizer::class => new AMP_Script_Sanitizer(
AMP_Script_Sanitizer::class => new AMP_Script_Sanitizer(
$dom,
[
'sanitize_js_scripts' => true,
Expand All @@ -406,31 +407,31 @@ public function test_cascading_sanitizer_argument_changes_with_custom_scripts( $
},
]
),
AMP_Img_Sanitizer::class => new AMP_Img_Sanitizer(
AMP_Img_Sanitizer::class => new AMP_Img_Sanitizer(
$dom,
[
'native_img_used' => false, // Overridden by AMP_Script_Sanitizer when there is a kept script.
]
),
AMP_Video_Sanitizer::class => new AMP_Video_Sanitizer(
AMP_Video_Sanitizer::class => new AMP_Video_Sanitizer(
$dom,
[
'native_video_used' => false, // Overridden by AMP_Script_Sanitizer when there is a kept script.
]
),
AMP_Audio_Sanitizer::class => new AMP_Audio_Sanitizer(
AMP_Audio_Sanitizer::class => new AMP_Audio_Sanitizer(
$dom,
[
'native_audio_used' => false, // Overridden by AMP_Script_Sanitizer when there is a kept script.
]
),
AMP_Iframe_Sanitizer::class => new AMP_Iframe_Sanitizer(
AMP_Iframe_Sanitizer::class => new AMP_Iframe_Sanitizer(
$dom,
[
'native_iframe_used' => false, // Overridden by AMP_Script_Sanitizer when there is a kept script.
]
),
AMP_Form_Sanitizer::class => new AMP_Form_Sanitizer(
AMP_Form_Sanitizer::class => new AMP_Form_Sanitizer(
$dom,
[
'native_post_forms_allowed' => false, // Overridden by AMP_Script_Sanitizer when there is a kept script.
Expand All @@ -439,13 +440,20 @@ public function test_cascading_sanitizer_argument_changes_with_custom_scripts( $
},
]
),
AMP_Style_Sanitizer::class => new AMP_Style_Sanitizer(
AMP_Style_Sanitizer::class => new AMP_Style_Sanitizer(
$dom,
[
'use_document_element' => true,
'skip_tree_shaking' => false, // Overridden by AMP_Script_Sanitizer when there is a kept script.
]
),
AMP_Tag_And_Attribute_Sanitizer::class => new AMP_Tag_And_Attribute_Sanitizer(
$dom,
[
'use_document_element' => true,
'prefer_bento' => false, // Overridden by AMP_Script_Sanitizer when there is a kept script.
]
),
];

/** @var AMP_Base_Sanitizer $sanitizer */
Expand Down Expand Up @@ -504,6 +512,16 @@ public function test_cascading_sanitizer_argument_changes_with_custom_scripts( $
} else {
$this->assertStringContainsString( 'body.loaded{background:green}', $style->textContent );
}

// Verify that prefer_bento got set.
$scripts = $sanitizers[ AMP_Tag_And_Attribute_Sanitizer::class ]->get_scripts();
if ( $remove_custom_scripts ) {
$this->assertArrayHasKey( Extension::FACEBOOK_PAGE, $scripts );
$this->assertArrayNotHasKey( Extension::FACEBOOK, $scripts );
} else {
$this->assertArrayNotHasKey( Extension::FACEBOOK_PAGE, $scripts );
$this->assertArrayHasKey( Extension::FACEBOOK, $scripts );
}
}

/**
Expand Down

0 comments on commit 23c518b

Please sign in to comment.