Skip to content

Commit

Permalink
Merge pull request #258 from lloc/WP_Test_MslsAdminIcon
Browse files Browse the repository at this point in the history
MslsAdminIcon tests finished
  • Loading branch information
lloc authored Dec 2, 2023
2 parents b4e68ad + bd67f3d commit 2839920
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
19 changes: 6 additions & 13 deletions includes/MslsAdminIcon.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -236,7 +229,7 @@ public function get_icon(): string {
return '';
}

switch ( $this->iconType ) {
switch ( $this->icon_type ) {
case MslsAdminIcon::TYPE_FLAG:
$icon = sprintf( '<span class="flag-icon %s">%s</span>',
( new IconSvg() )->get( $this->language ),
Expand Down
27 changes: 26 additions & 1 deletion tests/test-mslsadminicon.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', '<span class="flag-icon flag-icon-de">de_DE</span>' ],
[ 'label', 'it_IT', '<span class="language-badge it_IT"><span>it</span><span>IT</span></span>'],
[ null, 'fr_FR', '<span class="dashicons dashicons-plus"></span>' ],
[ 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' );
Expand Down

0 comments on commit 2839920

Please sign in to comment.