forked from ampproject/amp-wp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-amp-twitter-embed.php
92 lines (83 loc) · 3.08 KB
/
test-amp-twitter-embed.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
class AMP_Twitter_Embed_Test extends WP_UnitTestCase {
public function get_conversion_data() {
return array(
'no_embed' => array(
'<p>Hello world.</p>',
'<p>Hello world.</p>' . PHP_EOL,
),
'url_simple' => array(
'https://twitter.com/wordpress/status/118252236836061184' . PHP_EOL,
'<p><amp-twitter data-tweetid="118252236836061184" layout="responsive" width="600" height="480"></amp-twitter></p>' . PHP_EOL,
),
'url_with_big_tweet_id' => array(
'https://twitter.com/wordpress/status/705219971425574912' . PHP_EOL,
'<p><amp-twitter data-tweetid="705219971425574912" layout="responsive" width="600" height="480"></amp-twitter></p>' . PHP_EOL,
),
'shortcode_without_id' => array(
'[tweet]' . PHP_EOL,
'' . PHP_EOL,
),
'shortcode_simple' => array(
'[tweet 118252236836061184]' . PHP_EOL,
'<amp-twitter data-tweetid="118252236836061184" layout="responsive" width="600" height="480"></amp-twitter>' . PHP_EOL,
),
'shortcode_with_tweet_attribute' => array(
'[tweet tweet=118252236836061184]' . PHP_EOL,
'<amp-twitter data-tweetid="118252236836061184" layout="responsive" width="600" height="480"></amp-twitter>' . PHP_EOL,
),
'shortcode_with_big_tweet_id' => array(
'[tweet 705219971425574912]' . PHP_EOL,
'<amp-twitter data-tweetid="705219971425574912" layout="responsive" width="600" height="480"></amp-twitter>' . PHP_EOL,
),
'shortcode_with_url' => array(
'[tweet https://twitter.com/wordpress/status/118252236836061184]' . PHP_EOL,
'<amp-twitter data-tweetid="118252236836061184" layout="responsive" width="600" height="480"></amp-twitter>' . PHP_EOL,
),
'shortcode_with_url_with_big_tweet_id' => array(
'[tweet https://twitter.com/wordpress/status/705219971425574912]' . PHP_EOL,
'<amp-twitter data-tweetid="705219971425574912" layout="responsive" width="600" height="480"></amp-twitter>' . PHP_EOL,
),
'shortcode_with_non_numeric_tweet_id' => array(
'[tweet abcd]' . PHP_EOL,
'' . PHP_EOL,
),
);
}
/**
* @dataProvider get_conversion_data
*/
public function test__conversion( $source, $expected ) {
$embed = new AMP_Twitter_Embed_Handler();
$embed->register_embed();
$filtered_content = apply_filters( 'the_content', $source );
$this->assertEquals( $expected, $filtered_content );
}
public function get_scripts_data() {
return array(
'not_converted' => array(
'<p>Hello World.</p>',
array(),
),
'converted' => array(
'https://twitter.com/altjoen/status/118252236836061184' . PHP_EOL,
array( 'amp-twitter' => true ),
),
);
}
/**
* @dataProvider get_scripts_data
*/
public function test__get_scripts( $source, $expected ) {
$embed = new AMP_Twitter_Embed_Handler();
$embed->register_embed();
$source = apply_filters( 'the_content', $source );
$whitelist_sanitizer = new AMP_Tag_And_Attribute_Sanitizer( AMP_DOM_Utils::get_dom_from_content( $source ) );
$whitelist_sanitizer->sanitize();
$scripts = array_merge(
$embed->get_scripts(),
$whitelist_sanitizer->get_scripts()
);
$this->assertEquals( $expected, $scripts );
}
}