From bd67f3de354f95d2de080dade873702111e09654 Mon Sep 17 00:00:00 2001 From: Dennis Ploetner Date: Sat, 2 Dec 2023 18:19:28 +0100 Subject: [PATCH] MslsAdminIcon tests finished --- includes/MslsAdminIcon.php | 19 ++++++------------- tests/test-mslsadminicon.php | 27 ++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/includes/MslsAdminIcon.php b/includes/MslsAdminIcon.php index 9aa9b601..53df54eb 100644 --- a/includes/MslsAdminIcon.php +++ b/includes/MslsAdminIcon.php @@ -17,55 +17,48 @@ class MslsAdminIcon { /** - * IconType * @var string */ - protected $iconType = 'action'; + protected $icon_type = 'action'; /** - * Language * @var string */ protected $language; /** - * Origin Language * @var string */ public $origin_language; /** - * Source * @var string */ protected $src; /** - * URL * @var string */ protected $href; /** - * Blog id * @var int */ protected $blog_id; /** - * Type * @var string */ protected $type; /** - * Path * @var string */ protected $path = 'post-new.php'; /** * The current object ID + * * @var int */ protected $id; @@ -111,12 +104,12 @@ public static function create( ?string $type = null ) { /** * Set the icon path * - * @param $iconType + * @param $icon_type * * @return MslsAdminIcon */ - public function set_icon_type( $iconType ): MslsAdminIcon { - $this->iconType = $iconType; + public function set_icon_type( $icon_type ): MslsAdminIcon { + $this->icon_type = $icon_type; return $this; } @@ -236,7 +229,7 @@ public function get_icon(): string { return ''; } - switch ( $this->iconType ) { + switch ( $this->icon_type ) { case MslsAdminIcon::TYPE_FLAG: $icon = sprintf( '%s', ( new IconSvg() )->get( $this->language ), diff --git a/tests/test-mslsadminicon.php b/tests/test-mslsadminicon.php index ce59d741..817a4fb8 100644 --- a/tests/test-mslsadminicon.php +++ b/tests/test-mslsadminicon.php @@ -163,7 +163,32 @@ public function test_set_icon_type() { $this->assertInstanceOf( MslsAdminIcon::class, $obj->set_icon_type( 'flag' ) ); } - public function test_get_icon() { + public function icon_type_provider() { + return [ + [ 'flag', 'de_DE', 'de_DE' ], + [ 'label', 'it_IT', 'itIT'], + [ null, 'fr_FR', '' ], + [ null, null, '' ], + ]; + } + + /** + * @dataProvider icon_type_provider + */ + public function test_get_icon_flag( $icon_type, $language, $expected ) { + Functions\expect( 'plugin_dir_path' )->atLeast( 1 )->andReturn( dirname( __DIR__, 1 ) . '/' ); + + $obj = new MslsAdminIcon( 'post' ); + $obj->set_icon_type( $icon_type ); + + if ( ! is_null( $language ) ) { + $obj->set_language( $language ); + } + + $this->assertEquals( $expected, $obj->get_icon() ); + } + + public function test_get_icon_label() { Functions\expect( 'plugin_dir_path' )->atLeast( 1 )->andReturn( dirname( __DIR__, 1 ) . '/' ); $obj = new MslsAdminIcon( 'post' );