Completed
Push — story-block/add/more-media-opt... ( 53fda1...42cfc5 )
by
unknown
107:17 queued 96:49
created

WP_Test_Jetpack_SEO_Titles   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 49
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A test_sanitize_title_formats() 0 44 3
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