Skip to content

Commit

Permalink
tests for Carbon_Breadcrumb_Admin::is_enabled()
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla committed Jan 5, 2016
1 parent a2bbb2f commit 85442e3
Showing 1 changed file with 71 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
/**
* @group admin
*/
class CarbonBreadcrumbAdminIsEnabledTest extends WP_UnitTestCase {

public function setUp() {
$this->admin = $this->getMock('Carbon_Breadcrumb_Admin', array('current_dir'), array(), '', false);
}

public function tearDown() {
unset( $this->admin );
}

/**
* @covers Carbon_Breadcrumb_Admin::is_enabled
*/
public function testWhenInstalledAsPlugin() {
$plugins_path = untrailingslashit( ABSPATH ) . DIRECTORY_SEPARATOR . 'wp-content' . DIRECTORY_SEPARATOR . 'plugins';
$this->admin->expects($this->any())
->method('current_dir')
->will($this->returnValue($plugins_path));

$this->assertTrue( $this->admin->is_enabled() );
}

/**
* @covers Carbon_Breadcrumb_Admin::is_enabled
* @runInSeparateProcess
*/
public function testWithAdminConstantDefined() {
$this->admin->expects($this->any())
->method('current_dir')
->will($this->returnValue(ABSPATH));

define('CARBON_BREADCRUMB_ENABLE_ADMIN', true);

$this->assertTrue( $this->admin->is_enabled() );
}

/**
* @covers Carbon_Breadcrumb_Admin::is_enabled
*/
public function testWithEnablingFilter() {
$this->admin->expects($this->any())
->method('current_dir')
->will($this->returnValue(ABSPATH));

add_filter( 'carbon_breadcrumb_enable_admin', array( $this, '__return_true' ) );

$this->assertTrue( $this->admin->is_enabled() );

remove_filter( 'carbon_breadcrumb_enable_admin', array( $this, '__return_true' ) );
}

/**
* @covers Carbon_Breadcrumb_Admin::is_enabled
*/
public function testWithNoEnabledConditions() {
$this->admin->expects($this->any())
->method('current_dir')
->will($this->returnValue(ABSPATH));

$this->assertFalse( $this->admin->is_enabled() );
}

public function __return_true() {
return true;
}

}

0 comments on commit 85442e3

Please sign in to comment.