-
Notifications
You must be signed in to change notification settings - Fork 383
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sanitizer to disable auto lightbox (#6936)
Co-authored-by: Dhaval Parekh <[email protected]>
- Loading branch information
1 parent
bc74cd7
commit 3ba9db9
Showing
4 changed files
with
86 additions
and
0 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
24 changes: 24 additions & 0 deletions
24
includes/sanitizers/class-amp-auto-lightbox-disable-sanitizer.php
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,24 @@ | ||
<?php | ||
/** | ||
* Class AMP_Auto_Lightbox_Disable_Sanitizer | ||
* | ||
* @package AmpProject\AmpWP | ||
*/ | ||
|
||
/** | ||
* Disable auto lightbox for images. | ||
* | ||
* @since 2.2.2 | ||
* @internal | ||
*/ | ||
class AMP_Auto_Lightbox_Disable_Sanitizer extends AMP_Base_Sanitizer { | ||
|
||
/** | ||
* Add "data-amp-auto-lightbox-disable" attribute to body tag. | ||
* | ||
* @return void | ||
*/ | ||
public function sanitize() { | ||
$this->dom->body->setAttributeNode( $this->dom->createAttribute( 'data-amp-auto-lightbox-disable' ) ); | ||
} | ||
} |
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
30 changes: 30 additions & 0 deletions
30
tests/php/test-class-amp-auto-lightbox-disable-sanitizer.php
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,30 @@ | ||
<?php | ||
/** | ||
* Class AMP_Auto_Lightbox_Disable_Sanitizer_Test. | ||
* | ||
* @package AmpProject\AmpWP | ||
*/ | ||
|
||
use AmpProject\AmpWP\Tests\TestCase; | ||
|
||
/** | ||
* Tests the auto lightbox disable sanitizer class. | ||
* | ||
* @coversDefaultClass AMP_Auto_Lightbox_Disable_Sanitizer | ||
*/ | ||
class AMP_Auto_Lightbox_Disable_Sanitizer_Test extends TestCase { | ||
|
||
/** | ||
* @covers ::sanitize() | ||
*/ | ||
public function test_sanitize() { | ||
|
||
$source = '<html><body class="body-class"><span>Hello World!</span></body></html>'; | ||
$dom = AMP_DOM_Utils::get_dom_from_content( $source ); | ||
|
||
$sanitizer = new AMP_Auto_Lightbox_Disable_Sanitizer( $dom ); | ||
$sanitizer->sanitize(); | ||
|
||
$this->assertTrue( $dom->body->hasAttribute( 'data-amp-auto-lightbox-disable' ) ); | ||
} | ||
} |