Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MslsAdminIcon tests finished #258

Merged
merged 1 commit into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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