Skip to content

Commit

Permalink
Unit test reorganized
Browse files Browse the repository at this point in the history
  • Loading branch information
lloc committed Apr 11, 2021
1 parent e045245 commit 314b470
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 25 deletions.
12 changes: 5 additions & 7 deletions MslsSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Plugin Name: MslsSelect
Plugin URI: https://github.com/lloc/MslsSelect
Description: Transforms the output of the Multisite Language Switcher to an HTML select
Version: 2.2.3
Version: 2.2.4
Author: Dennis Ploetner
Author URI: http://lloc.de/
*/
Expand Down Expand Up @@ -35,7 +35,7 @@
*/
class MslsSelect {

const VERSION = '2.2.3';
const VERSION = '2.2.4';

public function __construct() {
$options = get_option( 'msls' );
Expand Down Expand Up @@ -64,10 +64,8 @@ public static function init(): self {

/**
* Enqueue scripts action
*
* @codeCoverageIgnore
*/
public function enqueue_scripts(): void {
public static function enqueue_scripts(): void {
wp_enqueue_script( 'mslsselect', plugins_url( '/js/mslsselect.min.js', __FILE__ ), [], self::VERSION, true );
}

Expand All @@ -80,7 +78,7 @@ public function enqueue_scripts(): void {
*
* @return string
*/
public function output_get( string $url, $link, bool $current ): string {
public static function output_get( string $url, $link, bool $current ): string {
return sprintf( '<option value="%s"%s>%s</option>', $url, ( $current ? ' selected="selected"' : '' ), $link->txt );
}

Expand All @@ -89,7 +87,7 @@ public function output_get( string $url, $link, bool $current ): string {
*
* @return array
*/
public function get_tags(): array {
public static function get_tags(): array {
return [
'before_item' => '',
'after_item' => '',
Expand Down
8 changes: 6 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ Contributors: realloc
Donate link: http://www.greenpeace.org/international/
Tags: multilingual, multisite, language, switcher, international, localization, i18n, menu, select-box, html select
Requires at least: 3.6.1
Tested up to: 5.6
Tested up to: 5.7
Requires PHP: 7.1
Stable tag: 2.2.3
Stable tag: 2.2.4
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand All @@ -26,6 +26,10 @@ But if you look for an **easy way** to change the output of the _Multisite Langu

== Changelog ==

= 2.2.4 =
* Unit test reorganized
* WordPress 5.7 tested

= 2.2.3 =
* strict types and PHPStan tested

Expand Down
42 changes: 26 additions & 16 deletions tests/MslsSelectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,29 @@

class MslsSelectTest extends TestCase {

public function get_test() {
Functions\expect( 'get_option' )->once()->andReturn( [] );
Functions\expect( 'update_option' )->once();
protected function setUp(): void {
parent::setUp();
Monkey\setUp();
}

public function test_enqueue_scripts() {
Functions\expect( 'wp_enqueue_script' )->once();
Functions\expect( 'plugins_url' )->once()->andReturn( 'an_url' );

return new MslsSelect();
MslsSelect::enqueue_scripts();

$this->expectOutputString( '' );
}

public function test_get_tags() {
$test = $this->get_test();

$this->assertNotEmpty( $test->get_tags() );
$expected = [
'before_item' => '',
'after_item' => '',
'before_output' => '<select class="msls_languages">',
'after_output' => '</select>',
];

$this->assertEquals( $expected, MslsSelect::get_tags() );
}

public function test_init_admin_true() {
Expand All @@ -42,30 +54,28 @@ public function test_init_admin_false() {
}

public function test_output_get_true() {
$test = $this->get_test();

$url = '/test/';
$link = (object) [ 'txt' => 'Test' ];

$expected = '<option value="/test/" selected="selected">Test</option>';

$this->assertEquals( $expected, $test->output_get( $url, $link, true ) );
$this->assertEquals( $expected, MslsSelect::output_get( $url, $link, true ) );
}

public function test_output_get_false() {
$test = $this->get_test();

$url = '/test/';
$link = (object) [ 'txt' => 'Test' ];

$expected = '<option value="/test/">Test</option>';

$this->assertEquals( $expected, $test->output_get( $url, $link, false ) );
$this->assertEquals( $expected, MslsSelect::output_get( $url, $link, false ) );
}

protected function setUp(): void {
parent::setUp();
Monkey\setUp();
public function test_update_option_in_constructor() {
Functions\expect( 'get_option' )->once()->andReturn( [] );
Functions\expect( 'update_option' )->once()->andReturn( true );

$this->assertIsObject( ( new MslsSelect() ) );
}

protected function tearDown(): void {
Expand Down

0 comments on commit 314b470

Please sign in to comment.