File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace lloc \MslsTests ;
4
4
5
+ use lloc \Msls \MslsBlog ;
6
+ use lloc \Msls \MslsBlogCollection ;
5
7
use PHPUnit \Framework \TestCase ;
6
8
use Brain \Monkey ;
7
9
use Brain \Monkey \Functions ;
@@ -25,6 +27,31 @@ protected function setUp(): void {
25
27
Functions \when ( '__ ' )->returnArg ();
26
28
}
27
29
30
+ /**
31
+ * Get a of the MslsBlogCollection class that contains some blogs
32
+ *
33
+ * @param $map
34
+ *
35
+ * @return void
36
+ */
37
+ public function getBlogsCollection ( $ map = [ 'de_DE ' => 'de ' , 'en_US ' => 'en ' ] ): MslsBlogCollection {
38
+ foreach ( $ map as $ locale => $ alpha2 ) {
39
+ $ blog = \Mockery::mock ( MslsBlog::class );
40
+ $ blog ->shouldReceive ( [
41
+ 'get_alpha2 ' => $ alpha2 ,
42
+ 'get_language ' => $ locale ,
43
+ ] );
44
+
45
+ $ blogs [] = $ blog ;
46
+ }
47
+
48
+ $ collection = \Mockery::mock ( MslsBlogCollection::class );
49
+ $ collection ->shouldReceive ( 'get_objects ' )->andReturn ( $ blogs );
50
+ $ collection ->shouldReceive ( 'get ' )->andReturn ( $ blogs );
51
+
52
+ return $ collection ;
53
+ }
54
+
28
55
protected function tearDown (): void {
29
56
restore_error_handler ();
30
57
Original file line number Diff line number Diff line change 5
5
use lloc \Msls \MslsCustomColumn ;
6
6
use lloc \Msls \MslsOptions ;
7
7
use lloc \Msls \MslsBlogCollection ;
8
+ use Brain \Monkey \Functions ;
8
9
9
10
class WP_Test_MslsCustomColumn extends Msls_UnitTestCase {
10
11
11
12
function test_th () {
13
+ Functions \expect ( 'add_query_arg ' )->twice ()->andReturn ( 'https://example.org/added-args ' );
14
+ Functions \expect ( 'get_the_ID ' )->twice ()->andReturnValues ( [ 1 , 2 ] );
15
+ Functions \when ( 'plugin_dir_path ' )->justReturn ( dirname ( __DIR__ , 1 ) . '/ ' );
16
+
17
+ $ options = \Mockery::mock ( MslsOptions::class );
18
+ $ obj = new MslsCustomColumn ( $ options , $ this ->getBlogsCollection () );
19
+ $ expected = [ 'mslscol ' => '<span class="flag-icon flag-icon-de">de_DE</span> <span class="flag-icon flag-icon-us">en_US</span> ' ];
20
+
21
+ $ this ->assertEquals ( $ expected , $ obj ->th ( [] ) );
22
+ }
23
+
24
+ function test_th_empty () {
12
25
$ options = \Mockery::mock ( MslsOptions::class );
13
26
$ collection = \Mockery::mock ( MslsBlogCollection::class );
14
27
$ collection ->shouldReceive ( 'get ' )->once ()->andReturn ( [] );
You can’t perform that action at this time.
0 commit comments