| 1 |
<?php |
| 2 |
|
| 3 |
class WP_Test_Edit_Flow_Class_Module extends WP_UnitTestCase { |
| 4 |
|
| 5 |
protected static $admin_user_id; |
| 6 |
protected static $EditFlowModule; |
| 7 |
|
| 8 |
public static function wpSetUpBeforeClass( $factory ) { |
| 9 |
self::$admin_user_id = $factory->user->create( array( 'role' => 'administrator' ) ); |
| 10 |
} |
| 11 |
|
| 12 |
function _flush_roles() { |
| 13 |
// we want to make sure we're testing against the db, not just in-memory data |
| 14 |
// this will flush everything and reload it from the db |
| 15 |
global $wp_roles; |
| 16 |
if ( is_object( $wp_roles ) ) { |
| 17 |
$wp_roles->for_site(); |
| 18 |
} |
| 19 |
} |
| 20 |
|
| 21 |
function setUp() { |
| 22 |
parent::setUp(); |
| 23 |
|
| 24 |
self::$EditFlowModule = new EF_Module(); |
| 25 |
|
| 26 |
$this->_flush_roles(); |
| 27 |
} |
| 28 |
|
| 29 |
function tearDown() { |
| 30 |
self::$EditFlowModule = null; |
| 31 |
} |
| 32 |
|
| 33 |
function test_add_caps_to_role() { |
| 34 |
$usergroup_roles = array( |
| 35 |
'administrator' => array( 'edit_usergroups' ), |
| 36 |
); |
| 37 |
|
| 38 |
foreach( $usergroup_roles as $role => $caps ) { |
| 39 |
self::$EditFlowModule->add_caps_to_role( $role, $caps ); |
| 40 |
} |
| 41 |
|
| 42 |
$user = new WP_User( self::$admin_user_id ); |
| 43 |
|
| 44 |
//Verify before flush |
| 45 |
$this->assertTrue( $user->has_cap( 'edit_usergroups' ), 'User did not have role edit_usergroups' ); |
| 46 |
|
| 47 |
$this->_flush_roles(); |
| 48 |
|
| 49 |
$this->assertTrue( $user->has_cap( 'edit_usergroups' ), 'User did not have role edit_usergroups' ); |
| 50 |
} |
| 51 |
|
| 52 |
function test_current_post_type_post_type_set() { |
| 53 |
$_REQUEST['post_type'] = 'not-real'; |
| 54 |
|
| 55 |
$this->assertEquals( 'not-real', self::$EditFlowModule->get_current_post_type() ); |
| 56 |
} |
| 57 |
|
| 58 |
function test_current_post_type_post_screen() { |
| 59 |
set_current_screen( 'post.php' ); |
| 60 |
|
| 61 |
$post_id = $this->factory->post->create( array ( |
| 62 |
'post_author' => self::$admin_user_id |
| 63 |
) ); |
| 64 |
|
| 65 |
$_REQUEST['post'] = $post_id; |
| 66 |
|
| 67 |
$this->assertEquals( 'post', self::$EditFlowModule->get_current_post_type() ); |
| 68 |
|
| 69 |
unset( $_REQUEST['post_type'] ); |
| 70 |
set_current_screen( 'front' ); |
| 71 |
} |
| 72 |
|
| 73 |
function test_current_post_type_edit_screen() { |
| 74 |
set_current_screen( 'edit.php' ); |
| 75 |
|
| 76 |
$this->assertEquals( 'post', self::$EditFlowModule->get_current_post_type() ); |
| 77 |
|
| 78 |
set_current_screen( 'front' ); |
| 79 |
} |
| 80 |
|
| 81 |
function test_current_post_type_custom_post_type() { |
| 82 |
register_post_type( 'content' ); |
| 83 |
set_current_screen( 'content' ); |
| 84 |
|
| 85 |
$this->assertEquals( 'content', self::$EditFlowModule->get_current_post_type() ); |
| 86 |
|
| 87 |
_unregister_post_type( 'content' ); |
| 88 |
set_current_screen( 'front' ); |
| 89 |
} |
| 90 |
|
| 91 |
public static function wpTearDownAfterClass() { |
| 92 |
self::delete_user( self::$admin_user_id ); |
| 93 |
} |
| 94 |
} |