@@ -86,7 +86,33 @@ public function test_content_filter_one_link() {
8686 $ this ->assertEquals ( $ expected , $ test ->content_filter ( $ content ) );
8787 }
8888
89- public function test_content_filter_two_links () {
89+ public function test_content_filter_zero_links () {
90+ $ collection = \Mockery::mock ( MslsBlogCollection::class );
91+ $ collection ->shouldReceive ( 'get_filtered ' )->once ()->andReturn ( array () );
92+
93+ $ options = \Mockery::mock ( MslsOptions::class );
94+ $ options ->shouldReceive ( 'is_content_filter ' )->andReturn ( true );
95+
96+ $ post = \Mockery::mock ( 'WP_Post ' );
97+ $ post ->post_status = 'publish ' ;
98+ $ post ->post_type = 'post ' ;
99+
100+ $ post_object = \Mockery::mock ( 'WP_Post_Type ' );
101+ $ post_object ->rewrite ['with_front ' ] = true ;
102+
103+ Functions \expect ( 'is_front_page ' )->once ()->andReturn ( false );
104+ Functions \expect ( 'is_singular ' )->once ()->andReturn ( true );
105+ Functions \expect ( 'msls_options ' )->once ()->andReturn ( $ options );
106+ Functions \expect ( 'msls_blog_collection ' )->once ()->andReturn ( $ collection );
107+
108+ $ test = new MslsContentFilter ( $ options );
109+
110+ $ content = '<p>Test>/p> ' ;
111+ $ expected = '<p>Test>/p> ' ;
112+ $ this ->assertEquals ( $ expected , $ test ->content_filter ( $ content ) );
113+ }
114+
115+ public function test_content_filter_more_links () {
90116 $ a = \Mockery::mock ( MslsBlog::class );
91117 $ a ->shouldReceive ( 'get_language ' )->once ()->andReturn ( 'it_IT ' );
92118 $ a ->shouldReceive ( 'get_description ' )->once ()->andReturn ( 'Italiano ' );
@@ -95,13 +121,20 @@ public function test_content_filter_two_links() {
95121 $ b ->shouldReceive ( 'get_language ' )->once ()->andReturn ( 'de_DE ' );
96122 $ b ->shouldReceive ( 'get_description ' )->once ()->andReturn ( 'Deutsch ' );
97123
124+ $ c = \Mockery::mock ( MslsBlog::class );
125+ $ c ->shouldReceive ( 'get_language ' )->once ()->andReturn ( 'fr_FR ' );
126+ $ c ->shouldReceive ( 'get_description ' )->once ()->andReturn ( 'Français ' );
127+
128+ $ blogs = array ( $ a , $ b , $ c );
129+ $ times = count ( $ blogs );
130+
98131 $ collection = \Mockery::mock ( MslsBlogCollection::class );
99- $ collection ->shouldReceive ( 'get_filtered ' )->once ()->andReturn ( array ( $ a , $ b ) );
100- $ collection ->shouldReceive ( 'is_current_blog ' )->twice ( )->andReturn ( false );
132+ $ collection ->shouldReceive ( 'get_filtered ' )->once ()->andReturn ( $ blogs );
133+ $ collection ->shouldReceive ( 'is_current_blog ' )->times ( $ times )->andReturn ( false );
101134
102135 $ options = \Mockery::mock ( MslsOptions::class );
103136 $ options ->shouldReceive ( 'is_content_filter ' )->andReturn ( true );
104- $ options ->shouldReceive ( 'get_flag_url ' )->twice ( )->andReturn ( 'https://msls.co/wp-content/plugins/msls/flags/de.png ' );
137+ $ options ->shouldReceive ( 'get_flag_url ' )->times ( $ times )->andReturn ( 'https://msls.co/wp-content/plugins/msls/flags/de.png ' );
105138
106139 $ post = \Mockery::mock ( 'WP_Post ' );
107140 $ post ->post_status = 'publish ' ;
@@ -110,8 +143,11 @@ public function test_content_filter_two_links() {
110143 $ post_object = \Mockery::mock ( 'WP_Post_Type ' );
111144 $ post_object ->rewrite ['with_front ' ] = true ;
112145
113- Functions \expect ( 'get_post ' )->twice ()->andReturn ( $ post );
146+ Functions \expect ( 'msls_options ' )->once ()->andReturn ( $ options );
147+ Functions \expect ( 'msls_blog_collection ' )->once ()->andReturn ( $ collection );
148+
114149 Functions \expect ( 'get_post_type_object ' )->once ()->andReturn ( $ post_object );
150+ Functions \expect ( 'is_singular ' )->once ()->andReturn ( true );
115151 Functions \expect ( 'is_front_page ' )->twice ()->andReturn ( false );
116152 Functions \expect ( 'is_admin ' )->once ()->andReturn ( false );
117153 Functions \expect ( 'is_search ' )->once ()->andReturn ( false );
@@ -127,19 +163,18 @@ public function test_content_filter_two_links() {
127163 array (
128164 'de_DE ' => 42 ,
129165 'it_IT ' => 17 ,
166+ 'fr_FR ' => 23 ,
130167 )
131168 );
132- Functions \expect ( 'is_singular ' )->once ()->andReturn ( true );
133- Functions \expect ( 'msls_options ' )->once ()->andReturn ( $ options );
134- Functions \expect ( 'msls_blog_collection ' )->once ()->andReturn ( $ collection );
135- Functions \expect ( 'get_permalink ' )->twice ()->andReturn ( 'https://msls.co/de/testpage/ ' );
136- Functions \expect ( 'switch_to_blog ' )->twice ();
137- Functions \expect ( 'restore_current_blog ' )->twice ();
169+ Functions \expect ( 'get_post ' )->times ( $ times )->andReturn ( $ post );
170+ Functions \expect ( 'get_permalink ' )->times ( $ times )->andReturn ( 'https://msls.co/de/testpage/ ' );
171+ Functions \expect ( 'switch_to_blog ' )->times ( $ times );
172+ Functions \expect ( 'restore_current_blog ' )->times ( $ times );
138173
139174 $ test = new MslsContentFilter ( $ options );
140175
141176 $ content = '<p>Test>/p> ' ;
142- $ expected = '<p>Test>/p><p id="msls">This post is also available in <a href="https://msls.co/de/testpage/" title="Italiano">Italiano</a> and <a href="https://msls.co/de/testpage/" title="Deutsch">Deutsch</a>.</p> ' ;
177+ $ expected = '<p>Test>/p><p id="msls">This post is also available in <a href="https://msls.co/de/testpage/" title="Italiano">Italiano</a>, <a href="https://msls.co/de/testpage/" title="Deutsch">Deutsch</a> and <a href="https://msls.co/de/testpage/" title="Français">Français </a>.</p> ' ;
143178 $ this ->assertEquals ( $ expected , $ test ->content_filter ( $ content ) );
144179 }
145180
0 commit comments