-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from 10up/feature/first-pass-at-phpunit-tests
First pass at phpunit tests
- Loading branch information
Showing
9 changed files
with
287 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: Test | ||
|
||
on: | ||
push: | ||
branches: | ||
- develop | ||
- master | ||
pull_request: | ||
branches: | ||
- develop | ||
|
||
jobs: | ||
phpunit: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- uses: getong/[email protected] | ||
|
||
- name: Set PHP version | ||
uses: shivammathur/setup-php@v1 | ||
with: | ||
php-version: '7.2' | ||
coverage: none | ||
|
||
- name: Install dependencies | ||
run: composer install | ||
|
||
- name: Setup WP Tests | ||
run: bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 | ||
|
||
- name: PHPUnit | ||
run: './vendor/bin/phpunit' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"includes/ConvertToBlocks/*.php": { | ||
"type": "plugin", | ||
"test": "tests/ConvertToBlocks/%sTest.php" | ||
}, | ||
"tests/ConvertToBlocks/*Test.php": { | ||
"type": "test", | ||
"alternate": "includes/ConvertToBlocks/%s.php" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace ConvertToBlocks; | ||
|
||
class AdminBarMenuSupportTest extends \WP_UnitTestCase { | ||
|
||
public $support; | ||
|
||
function setUp() { | ||
parent::setUp(); | ||
|
||
$this->support = new AdminBarMenuSupport(); | ||
$this->support->container = $this; | ||
} | ||
|
||
function test_it_has_a_container() { | ||
$this->assertNotEmpty( $this->support->container ); | ||
$this->assertSame( $this, $this->support->container ); | ||
} | ||
|
||
function test_it_will_not_register_if_not_logged_in() { | ||
$actual = $this->support->can_register(); | ||
$this->assertFalse( $actual ); | ||
} | ||
|
||
function test_it_will_register_if_logged_in() { | ||
wp_set_current_user( 1 ); | ||
$actual = $this->support->can_register(); | ||
$this->assertTrue( $actual ); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace ConvertToBlocks; | ||
|
||
class AdminMenuSupportTest extends \WP_UnitTestCase { | ||
|
||
public $support; | ||
|
||
function setUp() { | ||
parent::setUp(); | ||
|
||
$this->support = new AdminMenuSupport(); | ||
$this->support->container = $this; | ||
} | ||
|
||
function test_it_has_a_container() { | ||
$this->assertSame( $this, $this->support->container ); | ||
} | ||
|
||
function test_it_will_be_registered_on_admin_pages() { | ||
$GLOBALS['current_screen'] = | ||
$mock = $this->getMockBuilder( stdObject::class ) | ||
->setMethods( ['in_admin'] ) | ||
->getMock(); | ||
|
||
$mock->expects( $this->once() ) | ||
->method( 'in_admin' ) | ||
->will( $this->returnValue( true ) ); | ||
|
||
$actual = $this->support->can_register(); | ||
$this->assertTrue( $actual ); | ||
|
||
$GLOBALS['current_screen'] = null; | ||
} | ||
|
||
function test_it_will_be_registered_if_logged_in() { | ||
wp_set_current_user( 1 ); | ||
$actual = $this->support->can_register(); | ||
$this->assertTrue( $actual ); | ||
} | ||
|
||
function test_it_will_not_be_registered_by_default() { | ||
$actual = $this->support->can_register(); | ||
$this->assertFalse( $actual ); | ||
} | ||
|
||
function test_it_can_sort_classic_menu_item() { | ||
$menu_items = [ | ||
[ 'Add New' ], | ||
[ 'Categories' ], | ||
[ 'Tags' ], | ||
[ 'Add New (Classic)' ], | ||
]; | ||
|
||
$this->support->sort_post_type_menu( $menu_items ); | ||
|
||
$this->assertEquals( 'Add New', $menu_items[0][0] ); | ||
$this->assertEquals( 'Add New (Classic)', $menu_items[1][0] ); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
namespace ConvertToBlocks; | ||
|
||
class AssetsTest extends \WP_UnitTestCase { | ||
|
||
public $assets; | ||
|
||
function setUp() { | ||
parent::setUp(); | ||
|
||
$this->assets = new Assets(); | ||
} | ||
|
||
function test_it_knows_if_not_on_block_editor() { | ||
$actual = $this->assets->is_block_editor(); | ||
$this->assertFalse( $actual ); | ||
} | ||
|
||
function test_it_knows_if_on_block_editor_screen() { | ||
$GLOBALS['current_screen'] = | ||
$mock = $this->getMockBuilder( stdObject::class ) | ||
->setMethods( ['is_block_editor'] ) | ||
->getMock(); | ||
|
||
$mock->expects( $this->once() ) | ||
->method( 'is_block_editor' ) | ||
->will( $this->returnValue( true ) ); | ||
|
||
$actual = $this->assets->is_block_editor(); | ||
$this->assertTrue( $actual ); | ||
|
||
$GLOBALS['current_screen'] = null; | ||
} | ||
|
||
function test_it_will_not_be_registered_on_frontend() { | ||
$actual = $this->assets->can_register(); | ||
$this->assertFalse( $actual ); | ||
} | ||
|
||
function test_it_will_be_registered_on_admin_screens() { | ||
$GLOBALS['current_screen'] = | ||
$mock = $this->getMockBuilder( stdObject::class ) | ||
->setMethods( ['in_admin'] ) | ||
->getMock(); | ||
|
||
$mock->expects( $this->once() ) | ||
->method( 'in_admin' ) | ||
->will( $this->returnValue( true ) ); | ||
|
||
$actual = $this->assets->can_register(); | ||
$this->assertTrue( $actual ); | ||
|
||
$GLOBALS['current_screen'] = null; | ||
} | ||
|
||
function test_it_registers_gutenbridge_script_on_registration() { | ||
$this->assets->register(); | ||
$actual = wp_script_is( 'convert_to_blocks_editor', 'registered' ); | ||
$this->assertTrue( $actual ); | ||
} | ||
|
||
function test_it_enqueues_script_on_assets_hook() { | ||
$this->assets->register(); | ||
$actual = wp_script_is( 'convert_to_blocks_editor', 'queue' ); | ||
|
||
$this->assertFalse( $actual ); | ||
|
||
$this->assets->do_assets(); | ||
|
||
$actual = wp_script_is( 'convert_to_blocks_editor', 'queue' ); | ||
|
||
$this->assertTrue( $actual ); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
namespace ConvertToBlocks; | ||
|
||
class ClassicEditorSupportTest extends \WP_UnitTestCase { | ||
|
||
public $support; | ||
public $post_supports; | ||
public $classic_param; | ||
|
||
function setUp() { | ||
parent::setUp(); | ||
|
||
$this->support = new ClassicEditorSupport(); | ||
$this->support->container = $this; | ||
} | ||
|
||
function test_it_has_a_container() { | ||
$this->assertSame( $this, $this->support->container ); | ||
} | ||
|
||
function test_it_will_not_be_registered_by_default() { | ||
$actual = $this->support->can_register(); | ||
$this->assertFalse( $actual ); | ||
} | ||
|
||
function test_it_can_be_registered_on_admin_pages() { | ||
$GLOBALS['current_screen'] = | ||
$mock = $this->getMockBuilder( stdObject::class ) | ||
->setMethods( ['in_admin'] ) | ||
->getMock(); | ||
|
||
$mock->expects( $this->once() ) | ||
->method( 'in_admin' ) | ||
->will( $this->returnValue( true ) ); | ||
|
||
$actual = $this->support->can_register(); | ||
$this->assertTrue( $actual ); | ||
|
||
$GLOBALS['current_screen'] = null; | ||
} | ||
|
||
function test_it_will_disable_block_editor_if_post_does_not_support_gutenbridge() { | ||
$this->post_supports = false; | ||
$actual = $this->support->enable_block_editor( true, 1 ); | ||
|
||
$this->assertFalse( $actual ); | ||
} | ||
|
||
function test_it_will_disable_block_editor_if_classic_query_param_is_present() { | ||
$this->post_supports = true; | ||
$this->classic_param = true; | ||
|
||
$actual = $this->support->enable_block_editor( true, 1 ); | ||
|
||
$this->assertFalse( $actual ); | ||
} | ||
|
||
/* helpers */ | ||
|
||
function post_supports_convert_to_blocks() { | ||
return $this->post_supports; | ||
} | ||
|
||
function has_classic_param() { | ||
return $this->classic_param; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters