Added manager tests.

This commit is contained in:
Andrey Savchenko committed 2018-02-19 16:12:01 +02:00
1 parent 1bf5e5c5ad
commit 5ec0f6c677
3 files changed
+119 -2

No files matched your search

@@ -1,12 +1,21 @@
<?php <?php
namespace Rarst\Laps\Tests; namespace Rarst\Laps\Tests\Manager;
use Brain\Monkey\Functions; use Brain\Monkey\Functions;
use Rarst\Laps\Manager\Asset_Manager; use Rarst\Laps\Manager\Asset_Manager;
use Rarst\Laps\Tests\LapsTestCase;
/**
* @coversDefaultClass Rarst\Laps\Manager\Asset_Manager
*/
class Asset_ManagerTest extends LapsTestCase { class Asset_ManagerTest extends LapsTestCase {
/**
* @covers ::__construct
*
* @return Asset_Manager
*/
public function test__construct() { public function test__construct() {
$manager = new Asset_Manager(); $manager = new Asset_Manager();
@@ -17,8 +26,8 @@ class Asset_ManagerTest extends LapsTestCase {
return $manager; return $manager;
} }
/** /**
* @covers ::enqueue_scripts
* @depends test__construct * @depends test__construct
*/ */
public function testEnqueue_scripts( Asset_Manager $manager ) { public function testEnqueue_scripts( Asset_Manager $manager ) {
+50
View File
@@ -0,0 +1,50 @@
<?php
namespace Rarst\Laps\Tests\Manager;
use Brain\Monkey\Functions;
use Rarst\Laps\Manager\Load_Order_Manager;
use Rarst\Laps\Tests\LapsTestCase;
/**
* @coversDefaultClass Rarst\Laps\Manager\Load_Order_Manager
*/
class Load_Order_ManagerTest extends LapsTestCase {
/**
* @covers ::__construct
*
* @return Load_Order_Manager
*/
public function test__construct() {
$manager = new Load_Order_Manager();
$this->assertTrue( has_action( 'pre_update_option_active_plugins', [ $manager, 'pre_update_option_active_plugins' ] ) );
$this->assertTrue( has_action( 'pre_update_site_option_active_sitewide_plugins', [ $manager, 'pre_update_option_active_plugins' ] ) );
return $manager;
}
/**
* @covers ::pre_update_option_active_plugins
* @depends test__construct
*/
public function testPre_update_option_active_plugins( Load_Order_Manager $manager ) {
$plugins = [
'foo/bar.php',
'laps/laps.php',
'baz/qux.php',
];
Functions\expect( 'plugin_basename' )->once()->andReturn( 'laps/laps.php' );
$plugins = $manager->pre_update_option_active_plugins( $plugins );
$this->assertInternalType( 'array', $plugins );
$this->assertCount( 3, $plugins );
$this->assertEquals( 'laps/laps.php', $plugins[0] );
}
}
+58
View File
@@ -0,0 +1,58 @@
<?php
namespace Rarst\Laps\Tests\Manager;
use Brain\Monkey\Functions;
use Rarst\Laps\Manager\Toolbar_Manager;
use Rarst\Laps\Plugin;
use Rarst\Laps\Tests\LapsTestCase;
/**
* @coversDefaultClass Rarst\Laps\Manager\Toolbar_Manager
*/
class Toolbar_ManagerTest extends LapsTestCase {
/**
* @covers ::__construct
*
* @return Toolbar_Manager
*/
public function test__construct() {
$laps = new Plugin( [ 'records' => [] ] );
$manager = new Toolbar_Manager( $laps );
$this->assertTrue( has_action( 'admin_bar_menu', [ $manager, 'admin_bar_menu' ] ) );
return $manager;
}
/**
* @covers ::admin_bar_menu
*
* @depends test__construct
*/
public function testAdmin_bar_menu( Toolbar_Manager $manager ) {
$wp_admin_bar = $this->getMockBuilder( 'WP_Admin_Bar' )
->allowMockingUnknownTypes()
->setMethods( [ 'add_node' ] )
->getMock();
$wp_admin_bar->method( 'add_node' )->willReturn( null );
$wp_admin_bar->expects( $this->exactly( 2 ) )
->method( 'add_node' )
->withConsecutive(
[ $this->isType( 'array' ) ],
[ $this->isType( 'array' ) ]
);
Functions\expect( 'current_user_can' )
->once()
->with( 'manage_options' )
->andReturn( true );
$manager->admin_bar_menu( $wp_admin_bar );
}
}