Skip to content

Commit

Permalink
Merge pull request #243 from lloc/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
lloc authored Aug 7, 2023
2 parents 48cb5c6 + 6edfa3f commit 17ee9d1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace lloc\MslsTests;

use lloc\Msls\MslsBlog;
use lloc\Msls\MslsBlogCollection;
use PHPUnit\Framework\TestCase;
use Brain\Monkey;
use Brain\Monkey\Functions;
Expand All @@ -25,6 +27,31 @@ protected function setUp(): void {
Functions\when( '__' )->returnArg();
}

/**
* Get a of the MslsBlogCollection class that contains some blogs
*
* @param $map
*
* @return void
*/
public function getBlogsCollection( $map = [ 'de_DE' => 'de', 'en_US' => 'en' ] ): MslsBlogCollection {
foreach ( $map as $locale => $alpha2 ) {
$blog = \Mockery::mock( MslsBlog::class );
$blog->shouldReceive( [
'get_alpha2' => $alpha2,
'get_language' => $locale,
] );

$blogs[] = $blog;
}

$collection = \Mockery::mock( MslsBlogCollection::class );
$collection->shouldReceive( 'get_objects' )->andReturn( $blogs );
$collection->shouldReceive( 'get' )->andReturn( $blogs );

return $collection;
}

protected function tearDown(): void {
restore_error_handler();

Expand Down
13 changes: 13 additions & 0 deletions tests/test-mslscustomcolumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,23 @@
use lloc\Msls\MslsCustomColumn;
use lloc\Msls\MslsOptions;
use lloc\Msls\MslsBlogCollection;
use Brain\Monkey\Functions;

class WP_Test_MslsCustomColumn extends Msls_UnitTestCase {

function test_th() {
Functions\expect( 'add_query_arg' )->twice()->andReturn( 'https://example.org/added-args' );
Functions\expect( 'get_the_ID' )->twice()->andReturnValues( [ 1, 2 ] );
Functions\when( 'plugin_dir_path' )->justReturn( dirname( __DIR__, 1 ) . '/' );

$options = \Mockery::mock( MslsOptions::class );
$obj = new MslsCustomColumn( $options, $this->getBlogsCollection() );
$expected = [ 'mslscol' => '<span class="flag-icon flag-icon-de">de_DE</span>&nbsp;<span class="flag-icon flag-icon-us">en_US</span>' ];

$this->assertEquals( $expected, $obj->th( [] ) );
}

function test_th_empty() {
$options = \Mockery::mock( MslsOptions::class );
$collection = \Mockery::mock( MslsBlogCollection::class );
$collection->shouldReceive( 'get' )->once()->andReturn( [] );
Expand Down

0 comments on commit 17ee9d1

Please sign in to comment.