7
7
use lloc \Msls \MslsOutput ;
8
8
use lloc \Msls \MslsOptions ;
9
9
use lloc \Msls \MslsOptionsPost ;
10
+
10
11
use Brain \Monkey \Functions ;
12
+ use Brain \Monkey \Filters ;
11
13
12
14
class TestMslsOutput extends MslsUnitTestCase {
13
15
@@ -26,21 +28,113 @@ public function test_get_method(): void {
26
28
$ this ->assertEquals ( array (), $ this ->test ->get ( 0 ) );
27
29
}
28
30
29
- public function test_get_alternate_links () {
30
- $ blog = \Mockery::mock ( MslsBlog::class );
31
- $ blog ->shouldReceive ( 'get_alpha2 ' )->andReturn ( 'de ' );
32
- $ blog ->shouldReceive ( 'get_language ' )->andReturn ( 'de_DE ' );
31
+ public function test_get_alternate_links_two_url () {
32
+ $ blogs = array ();
33
+
34
+ $ a = \Mockery::mock ( MslsBlog::class );
35
+ $ a ->shouldReceive ( 'get_alpha2 ' )->andReturn ( 'de ' );
36
+ $ a ->shouldReceive ( 'get_language ' )->andReturn ( 'de_DE ' );
37
+ $ a ->shouldReceive ( 'get_url ' )->andReturn ( 'https://example.de/ ' );
38
+ $ a ->shouldReceive ( 'get_description ' )->andReturn ( 'Deutsch ' );
39
+
40
+ $ blogs [] = $ a ;
41
+
42
+ $ b = \Mockery::mock ( MslsBlog::class );
43
+ $ b ->shouldReceive ( 'get_alpha2 ' )->andReturn ( 'it ' );
44
+ $ b ->shouldReceive ( 'get_language ' )->andReturn ( 'it_IT ' );
45
+ $ b ->shouldReceive ( 'get_url ' )->andReturn ( 'https://example.it/ ' );
46
+ $ b ->shouldReceive ( 'get_description ' )->andReturn ( 'Italiano ' );
47
+
48
+ $ blogs [] = $ b ;
49
+
50
+ $ collection = \Mockery::mock ( MslsBlogCollection::class );
51
+ $ collection ->shouldReceive ( 'get_objects ' )->andReturn ( $ blogs );
52
+
53
+ Functions \expect ( 'msls_blog_collection ' )->once ()->andReturn ( $ collection );
54
+ Functions \expect ( 'is_admin ' )->once ()->andReturn ( false );
55
+ Functions \expect ( 'is_front_page ' )->once ()->andReturn ( false );
56
+ Functions \expect ( 'is_search ' )->once ()->andReturn ( false );
57
+ Functions \expect ( 'is_404 ' )->once ()->andReturn ( false );
58
+ Functions \expect ( 'is_category ' )->once ()->andReturn ( false );
59
+ Functions \expect ( 'is_tag ' )->once ()->andReturn ( false );
60
+ Functions \expect ( 'is_tax ' )->once ()->andReturn ( false );
61
+ Functions \expect ( 'is_date ' )->once ()->andReturn ( false );
62
+ Functions \expect ( 'is_author ' )->once ()->andReturn ( false );
63
+ Functions \expect ( 'is_post_type_archive ' )->once ()->andReturn ( false );
64
+ Functions \expect ( 'get_queried_object_id ' )->once ()->andReturn ( 42 );
65
+ Functions \expect ( 'get_option ' )->once ()->andReturn ( array () );
66
+ Functions \expect ( 'esc_attr ' )->times ( 3 )->andReturnFirstArg ();
67
+
68
+ Filters \expectApplied ( 'mlsl_output_get_alternate_links_arr ' )->once ();
69
+
70
+ $ expected =
71
+ '<link rel="alternate" hreflang="de" href="https://example.de/" title="Deutsch" /> ' . PHP_EOL .
72
+ '<link rel="alternate" hreflang="it" href="https://example.it/" title="Italiano" /> ' ;
73
+ $ this ->assertEquals ( $ expected , $ this ->test ->get_alternate_links () );
74
+ }
75
+
76
+ public function test_get_alternate_links_null_url () {
77
+ $ blogs = array ();
78
+
79
+ $ a = \Mockery::mock ( MslsBlog::class );
80
+ $ a ->shouldReceive ( 'get_alpha2 ' )->andReturn ( 'de ' );
81
+ $ a ->shouldReceive ( 'get_language ' )->andReturn ( 'de_DE ' );
82
+ $ a ->shouldReceive ( 'get_url ' )->andReturnNull ();
83
+
84
+ $ blogs [] = $ a ;
85
+
86
+ $ collection = \Mockery::mock ( MslsBlogCollection::class );
87
+ $ collection ->shouldReceive ( 'get_objects ' )->andReturn ( $ blogs );
88
+
89
+ Functions \expect ( 'msls_blog_collection ' )->once ()->andReturn ( $ collection );
90
+ Functions \expect ( 'is_admin ' )->once ()->andReturn ( false );
91
+ Functions \expect ( 'is_front_page ' )->once ()->andReturn ( false );
92
+ Functions \expect ( 'is_search ' )->once ()->andReturn ( false );
93
+ Functions \expect ( 'is_404 ' )->once ()->andReturn ( false );
94
+ Functions \expect ( 'is_category ' )->once ()->andReturn ( false );
95
+ Functions \expect ( 'is_tag ' )->once ()->andReturn ( false );
96
+ Functions \expect ( 'is_tax ' )->once ()->andReturn ( false );
97
+ Functions \expect ( 'is_date ' )->once ()->andReturn ( false );
98
+ Functions \expect ( 'is_author ' )->once ()->andReturn ( false );
99
+ Functions \expect ( 'is_post_type_archive ' )->once ()->andReturn ( false );
100
+ Functions \expect ( 'get_queried_object_id ' )->once ()->andReturn ( 42 );
101
+ Functions \expect ( 'get_option ' )->once ()->andReturn ( array () );
102
+
103
+ $ this ->assertEquals ( '' , $ this ->test ->get_alternate_links () );
104
+ }
105
+
106
+ public function test_get_alternate_links_one_url () {
107
+ $ blogs = array ();
108
+
109
+ $ a = \Mockery::mock ( MslsBlog::class );
110
+ $ a ->shouldReceive ( 'get_alpha2 ' )->andReturn ( 'de ' );
111
+ $ a ->shouldReceive ( 'get_language ' )->andReturn ( 'de_DE ' );
112
+ $ a ->shouldReceive ( 'get_url ' )->andReturn ( 'https://example.de/ ' );
113
+ $ a ->shouldReceive ( 'get_description ' )->andReturn ( 'Deutsch ' );
114
+
115
+ $ blogs [] = $ a ;
33
116
34
117
$ collection = \Mockery::mock ( MslsBlogCollection::class );
35
- $ collection ->shouldReceive ( 'get_objects ' )->andReturn ( array ( $ blog ) );
118
+ $ collection ->shouldReceive ( 'get_objects ' )->andReturn ( $ blogs );
36
119
37
120
Functions \expect ( 'msls_blog_collection ' )->once ()->andReturn ( $ collection );
38
121
Functions \expect ( 'is_admin ' )->once ()->andReturn ( false );
39
122
Functions \expect ( 'is_front_page ' )->once ()->andReturn ( false );
40
123
Functions \expect ( 'is_search ' )->once ()->andReturn ( false );
41
124
Functions \expect ( 'is_404 ' )->once ()->andReturn ( false );
125
+ Functions \expect ( 'is_category ' )->once ()->andReturn ( false );
126
+ Functions \expect ( 'is_tag ' )->once ()->andReturn ( false );
127
+ Functions \expect ( 'is_tax ' )->once ()->andReturn ( false );
128
+ Functions \expect ( 'is_date ' )->once ()->andReturn ( false );
129
+ Functions \expect ( 'is_author ' )->once ()->andReturn ( false );
130
+ Functions \expect ( 'is_post_type_archive ' )->once ()->andReturn ( false );
131
+ Functions \expect ( 'get_queried_object_id ' )->once ()->andReturn ( 42 );
132
+ Functions \expect ( 'get_option ' )->once ()->andReturn ( array () );
133
+ Functions \expect ( 'esc_attr ' )->twice ()->andReturnFirstArg ();
134
+
135
+ Filters \expectApplied ( 'mlsl_output_get_alternate_links_default ' )->once ();
42
136
43
- $ this ->assertEquals ( array () , $ this ->test ->get_alternate_links () );
137
+ $ this ->assertEquals ( ' <link rel="alternate" hreflang="x-default" href="https://example.de/" title="Deutsch" /> ' , $ this ->test ->get_alternate_links () );
44
138
}
45
139
46
140
public function test___toString () {
0 commit comments