1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Class WP_Test_Jetpack_SEO_Titles. |
4
|
|
|
* |
5
|
|
|
* @package automattic/jetpack |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
require_jetpack_file( 'modules/seo-tools/jetpack-seo-titles.php' ); |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class WP_Test_Jetpack_SEO_Titles |
12
|
|
|
*/ |
13
|
|
|
class WP_Test_Jetpack_SEO_Titles extends WP_UnitTestCase { |
14
|
|
|
/** |
15
|
|
|
* Test for expected output after sanitizing the custom SEO page title structures. |
16
|
|
|
*/ |
17
|
|
|
public function test_sanitize_title_formats() { |
18
|
|
|
$mock_inputs = array( |
19
|
|
|
'page_type' => array( |
20
|
|
|
array( |
21
|
|
|
'type' => 'string', |
22
|
|
|
'value' => 'test <script>alert(123)</script> test', |
23
|
|
|
'expected_sanitized_value' => 'test test', |
24
|
|
|
'test_message' => 'Script tags should be stripped including inner contents.', |
25
|
|
|
), |
26
|
|
|
array( |
27
|
|
|
'type' => 'string', |
28
|
|
|
'value' => 'test <h1>title</h1> test', |
29
|
|
|
'expected_sanitized_value' => 'test title test', |
30
|
|
|
'test_message' => 'Non-script tags should be stripped, with inner contents preseved.', |
31
|
|
|
), |
32
|
|
|
array( |
33
|
|
|
'type' => 'string', |
34
|
|
|
'value' => 'Welcome to [site_name] | [tagline]', |
35
|
|
|
'expected_sanitized_value' => 'Welcome to [site_name] | [tagline]', |
36
|
|
|
'test_message' => 'Spacing between arbitrary strings and known tokens should be preserved.', |
37
|
|
|
), |
38
|
|
|
array( |
39
|
|
|
'type' => 'string', |
40
|
|
|
'value' => ' test test ', |
41
|
|
|
'expected_sanitized_value' => ' test test ', |
42
|
|
|
'test_message' => 'Extraneous spacing should be removed.', |
43
|
|
|
), |
44
|
|
|
array( |
45
|
|
|
'type' => 'string', |
46
|
|
|
'value' => '< hello, world > & Welcome 🙂', |
47
|
|
|
'expected_sanitized_value' => '< hello, world > & Welcome 🙂', |
48
|
|
|
'test_message' => 'Reserved characters should be preserved as-is.', |
49
|
|
|
), |
50
|
|
|
), |
51
|
|
|
); |
52
|
|
|
|
53
|
|
|
$sanitized_title_formats = Jetpack_SEO_Titles::sanitize_title_formats( $mock_inputs ); |
54
|
|
|
|
55
|
|
|
foreach ( $sanitized_title_formats as $format_array ) { |
56
|
|
|
foreach ( $format_array as $item ) { |
57
|
|
|
$this->assertSame( $item['value'], $item['expected_sanitized_value'], $item['test_message'] ); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|