1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * @group formatting |
---|
5 | */ |
---|
6 | class Tests_Formatting_LinksAddTarget extends WP_UnitTestCase { |
---|
7 | |
---|
8 | /** |
---|
9 | * Test Content DataProvider |
---|
10 | * |
---|
11 | * array ( input_txt, converted_output_txt) |
---|
12 | */ |
---|
13 | public function get_input_output() { |
---|
14 | return array ( |
---|
15 | array ( |
---|
16 | 'MY CONTENT <div> SOME ADDITIONAL TEXT <a href="XYZ" src="ABC">LINK</a> HERE </div> END TEXT', |
---|
17 | null, |
---|
18 | null, |
---|
19 | 'MY CONTENT <div> SOME ADDITIONAL TEXT <a href="XYZ" src="ABC" target="_blank">LINK</a> HERE </div> END TEXT' |
---|
20 | ), |
---|
21 | array ( |
---|
22 | 'MY CONTENT <div> SOME ADDITIONAL TEXT <A href="XYZ" src="ABC">LINK</A> HERE </div> END TEXT', |
---|
23 | null, |
---|
24 | null, |
---|
25 | 'MY CONTENT <div> SOME ADDITIONAL TEXT <A href="XYZ" src="ABC" target="_blank">LINK</A> HERE </div> END TEXT' |
---|
26 | ), |
---|
27 | array ( |
---|
28 | 'MY CONTENT <div> SOME ADDITIONAL TEXT <a href="XYZ" src="ABC">LINK</a> HERE </div> <a href="XYZ" >LINK</a>END TEXT', |
---|
29 | null, |
---|
30 | null, |
---|
31 | 'MY CONTENT <div> SOME ADDITIONAL TEXT <a href="XYZ" src="ABC" target="_blank">LINK</a> HERE </div> <a href="XYZ" target="_blank">LINK</a>END TEXT' |
---|
32 | ), |
---|
33 | array ( |
---|
34 | 'MY CONTENT <div> SOME ADDITIONAL TEXT <a href="XYZ" src="ABC">LINK</a> HERE </div> <span>END TEXT</span>', |
---|
35 | "_top", |
---|
36 | null, |
---|
37 | 'MY CONTENT <div> SOME ADDITIONAL TEXT <a href="XYZ" src="ABC" target="_top">LINK</a> HERE </div> <span>END TEXT</span>' |
---|
38 | ), |
---|
39 | array ( |
---|
40 | 'MY CONTENT <div> SOME ADDITIONAL TEXT <a href="XYZ" src="ABC">LINK</a> HERE </div> <span>END TEXT</span>', |
---|
41 | "_top", |
---|
42 | array( 'span'), |
---|
43 | 'MY CONTENT <div> SOME ADDITIONAL TEXT <a href="XYZ" src="ABC">LINK</a> HERE </div> <span target="_top">END TEXT</span>' |
---|
44 | ), |
---|
45 | array ( |
---|
46 | 'MY CONTENT <div> SOME ADDITIONAL TEXT <a href="XYZ" src="ABC">LINK</a> HERE </div> <span>END TEXT</span>', |
---|
47 | "_top", |
---|
48 | array( 'SPAN'), |
---|
49 | 'MY CONTENT <div> SOME ADDITIONAL TEXT <a href="XYZ" src="ABC">LINK</a> HERE </div> <span target="_top">END TEXT</span>' |
---|
50 | ), |
---|
51 | array ( |
---|
52 | 'MY CONTENT <div> SOME ADDITIONAL TEXT <a href="XYZ" src="ABC">LINK</a> HERE </div> <span target="_top">END TEXT</span>', |
---|
53 | "_top", |
---|
54 | array( 'span', 'div'), |
---|
55 | 'MY CONTENT <div target="_top"> SOME ADDITIONAL TEXT <a href="XYZ" src="ABC">LINK</a> HERE </div> <span target="_top">END TEXT</span>' |
---|
56 | ), |
---|
57 | array ( |
---|
58 | 'MY CONTENT <div target=\'ABC\'> SOME ADDITIONAL TEXT <a href="XYZ" src="ABC">LINK</a> HERE </div> <span target="xyz">END TEXT</span>', |
---|
59 | "_top", |
---|
60 | array( 'span', 'div'), |
---|
61 | 'MY CONTENT <div target="_top"> SOME ADDITIONAL TEXT <a href="XYZ" src="ABC">LINK</a> HERE </div> <span target="_top">END TEXT</span>' |
---|
62 | ), |
---|
63 | array ( |
---|
64 | 'MY CONTENT <div> SOME ADDITIONAL TEXT <a href="XYZ" src="ABC">LINK</a> HERE </div> <span target="xyz" src="ABC">END TEXT</span>', |
---|
65 | "_top", |
---|
66 | array( 'span'), |
---|
67 | 'MY CONTENT <div> SOME ADDITIONAL TEXT <a href="XYZ" src="ABC">LINK</a> HERE </div> <span src="ABC" target="_top">END TEXT</span>' |
---|
68 | ), |
---|
69 | ); |
---|
70 | } |
---|
71 | |
---|
72 | /** |
---|
73 | * Validate the normalize_whitespace function |
---|
74 | * @dataProvider get_input_output |
---|
75 | */ |
---|
76 | function test_normalize_whitespace( $content, $target, $tags, $exp_str ) { |
---|
77 | |
---|
78 | if( true === is_null( $target ) ) { |
---|
79 | $this->assertEquals( $exp_str, links_add_target( $content ) ); |
---|
80 | } else if ( true === is_null( $tags ) ) { |
---|
81 | $this->assertEquals( $exp_str, links_add_target( $content, $target ) ); |
---|
82 | } else { |
---|
83 | $this->assertEquals( $exp_str, links_add_target( $content, $target, $tags ) ); |
---|
84 | } |
---|
85 | |
---|
86 | } |
---|
87 | } |
---|