Skip to content

Commit

Permalink
Unit tests adjusted
Browse files Browse the repository at this point in the history
  • Loading branch information
lloc committed Nov 30, 2023
1 parent d406679 commit 6e7529c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 30 deletions.
33 changes: 18 additions & 15 deletions includes/MslsAdminIcon.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,25 +232,28 @@ public function get_a(): string {
* @return string
*/
public function get_icon(): string {
if ( 'flag' === $this->iconType ) {
return sprintf( '<span class="flag-icon %s">%s</span>',
( new IconSvg() )->get( $this->language ),
$this->language
);
if ( ! $this->language ) {
return '';
}

if ( 'label' === $this->iconType ) {
return sprintf( '<span class="language-badge %s">%s</span>',
$this->language,
( new IconLabel() )->get( $this->language )
);
}

if ( empty( $this->href ) ) {
return '<span class="dashicons dashicons-plus"></span>';
switch ( $this->iconType ) {
case MslsAdminIcon::TYPE_FLAG:
$icon = sprintf( '<span class="flag-icon %s">%s</span>',
( new IconSvg() )->get( $this->language ),
$this->language
);
break;
case MslsAdminIcon::TYPE_LABEL:
$icon = sprintf( '<span class="language-badge %s">%s</span>',
$this->language,
( new IconLabel() )->get( $this->language )
);
break;
default:
$icon = sprintf( '<span class="dashicons %s"></span>', empty( $this->href ) ? 'dashicons-plus' : 'dashicons-edit' );
}

return '<span class="dashicons dashicons-edit"></span>';
return $icon;
}

/**
Expand Down
14 changes: 4 additions & 10 deletions includes/MslsBlog.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ public function __construct( $obj, $description ) {
$this->language = MslsBlogCollection::get_blog_language( $this->obj->userblog_id );
}

$this->options = MslsOptions::instance();

$this->description = (string) $description;
}

Expand Down Expand Up @@ -71,16 +69,12 @@ public function get_description(): string {
/**
* Gets a customized title for the blog
*
* @param string $icon_type
*
* @return string
*/
public function get_title(): string {
$icon = new MslsAdminIcon( null );
$icon->set_language( $this->language );
if( $this->options->admin_display === 'label' ) {
$icon->set_icon_type( 'label' );
} else {
$icon->set_icon_type( 'flag' );
}
public function get_title( string $icon_type = 'flag' ): string {
$icon = ( new MslsAdminIcon( null ) )->set_language( $this->language )->set_icon_type( $icon_type );

return sprintf( '%1$s %2$s', $this->obj->blogname, '<span class="msls-icon-wrapper flag">' . $icon->get_icon() . '</span>' );
}
Expand Down
8 changes: 5 additions & 3 deletions includes/MslsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,18 @@ public static function get_output() {
* @return void
*/
public static function update_adminbar( \WP_Admin_Bar $wp_admin_bar ): void {
$icon_type = MslsAdminIcon::TYPE_LABEL === MslsOptions::instance()->admin_display ? MslsAdminIcon::TYPE_LABEL : MslsAdminIcon::TYPE_FLAG;

$blog_collection = MslsBlogCollection::instance();
foreach ( $blog_collection->get_plugin_active_blogs() as $blog ) {
$title = $blog->get_blavatar() . $blog->get_title();
$title = $blog->get_blavatar() . $blog->get_title( $icon_type );

$wp_admin_bar->add_node( [ 'id' => 'blog-' . $blog->userblog_id, 'title' => $title ] );
}

$blog = $blog_collection->get_current_blog();
if ( is_object( $blog ) && method_exists( $blog, 'get_title' ) ) {
$wp_admin_bar->add_node( [ 'id' => 'site-name', 'title' => $blog->get_title() ] );
$wp_admin_bar->add_node( [ 'id' => 'site-name', 'title' => $blog->get_title( $icon_type ) ] );
}
}

Expand All @@ -148,7 +150,7 @@ public static function print_alternate_links() {
*
* @return string
*/
function content_filter( $content ) {
public function content_filter( $content ) {
if ( ! is_front_page() && is_singular() ) {
$options = $this->options;

Expand Down
2 changes: 1 addition & 1 deletion tests/test-mslsadminicon.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function test_set_icon_type() {
}

public function test_get_icon() {
Functions\when( 'plugin_dir_path' )->justReturn( dirname( __DIR__, 1 ) . '/' );
Functions\expect( 'plugin_dir_path' )->atLeast( 1 )->andReturn( dirname( __DIR__, 1 ) . '/' );

$obj = new MslsAdminIcon( 'post' );
$obj->set_icon_type( 'flag' );
Expand Down
4 changes: 3 additions & 1 deletion tests/test-mslsblog.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class WP_Test_MslsBlog extends Msls_UnitTestCase {
*/
function test___get_method() {
Functions\expect( 'get_blog_option' )->once()->andReturn( 'it_IT' );
Functions\expect( 'add_query_arg' )->once()->andReturn( 'https://example.org/added-args' );
Functions\expect( 'plugin_dir_path' )->atLeast( 1 )->andReturn( dirname( __DIR__, 1 ) . '/' );

$blog = new \stdClass();
$blog->userblog_id = 1;
Expand All @@ -23,7 +25,7 @@ function test___get_method() {
$this->assertEquals( 'Italiano', $obj->get_description() );
$this->assertEquals( 'it_IT', $obj->get_language() );
$this->assertEquals( 'it', $obj->get_alpha2() );
$this->assertEquals( 'Test (Italiano)', $obj->get_title() );
$this->assertEquals( 'Test <span class="msls-icon-wrapper flag"><span class="flag-icon flag-icon-it">it_IT</span></span>', $obj->get_title() );
}

/**
Expand Down

0 comments on commit 6e7529c

Please sign in to comment.