From 5ec0f6c677b62d88a78e369c85fd379613cd1331 Mon Sep 17 00:00:00 2001 From: Andrey Savchenko Date: Mon, 19 Feb 2018 16:05:31 +0200 Subject: [PATCH] Added manager tests. --- tests/{ => Manager}/Asset_ManagerTest.php | 13 ++++- tests/Manager/Load_Order_ManagerTest.php | 50 +++++++++++++++++++ tests/Manager/Toolbar_ManagerTest.php | 58 +++++++++++++++++++++++ 3 files changed, 119 insertions(+), 2 deletions(-) rename tests/{ => Manager}/Asset_ManagerTest.php (79%) create mode 100644 tests/Manager/Load_Order_ManagerTest.php create mode 100644 tests/Manager/Toolbar_ManagerTest.php diff --git a/tests/Asset_ManagerTest.php b/tests/Manager/Asset_ManagerTest.php similarity index 79% rename from tests/Asset_ManagerTest.php rename to tests/Manager/Asset_ManagerTest.php index f4f0cfd..925c87f 100644 --- a/tests/Asset_ManagerTest.php +++ b/tests/Manager/Asset_ManagerTest.php @@ -1,12 +1,21 @@ 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] ); + } +} diff --git a/tests/Manager/Toolbar_ManagerTest.php b/tests/Manager/Toolbar_ManagerTest.php new file mode 100644 index 0000000..8e30b17 --- /dev/null +++ b/tests/Manager/Toolbar_ManagerTest.php @@ -0,0 +1,58 @@ + [] ] ); + $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 ); + } +}