Skip to content

Commit 17ee9d1

Browse files
authored
Merge pull request #243 from lloc/dev
Dev
2 parents 48cb5c6 + 6edfa3f commit 17ee9d1

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

tests/bootstrap.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace lloc\MslsTests;
44

5+
use lloc\Msls\MslsBlog;
6+
use lloc\Msls\MslsBlogCollection;
57
use PHPUnit\Framework\TestCase;
68
use Brain\Monkey;
79
use Brain\Monkey\Functions;
@@ -25,6 +27,31 @@ protected function setUp(): void {
2527
Functions\when( '__' )->returnArg();
2628
}
2729

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+
2855
protected function tearDown(): void {
2956
restore_error_handler();
3057

tests/test-mslscustomcolumn.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,23 @@
55
use lloc\Msls\MslsCustomColumn;
66
use lloc\Msls\MslsOptions;
77
use lloc\Msls\MslsBlogCollection;
8+
use Brain\Monkey\Functions;
89

910
class WP_Test_MslsCustomColumn extends Msls_UnitTestCase {
1011

1112
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>&nbsp;<span class="flag-icon flag-icon-us">en_US</span>' ];
20+
21+
$this->assertEquals( $expected, $obj->th( [] ) );
22+
}
23+
24+
function test_th_empty() {
1225
$options = \Mockery::mock( MslsOptions::class );
1326
$collection = \Mockery::mock( MslsBlogCollection::class );
1427
$collection->shouldReceive( 'get' )->once()->andReturn( [] );

0 commit comments

Comments
 (0)