Skip to content

Commit

Permalink
Strict assertions (fix type validations)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoryHogeveen committed Nov 21, 2024
1 parent 54d4045 commit 5569b21
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
22 changes: 11 additions & 11 deletions tests/test-module-role-defaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,14 @@ function test_import_export() {

// @todo Patch if data only is possible.
$result = $class->import_role_defaults( $editor_import );
$this->assertNotEquals( true, $result );
$this->assertNotSame( true, $result );

$import = array(
'editor' => $editor_import,
);

$result = $class->import_role_defaults( $import );
$this->assertEquals( true, $result );
$this->assertSame( true, $result );
$this->assertEquals( $import, $class->get_role_defaults() );

/**
Expand All @@ -157,7 +157,7 @@ function test_import_export() {
$result = $class->import_role_defaults( $import );

// Should return error list array because of the invalid meta key.
$this->assertNotEquals( true, $result );
$this->assertNotSame( true, $result );

// Make sure the key doesn't exists in the role defaults.
unset( $import['editor']['invalid_key'] );
Expand All @@ -170,7 +170,7 @@ function test_import_export() {
$overwrite['editor']['admin_color'] = 'dark';

$result = $class->import_role_defaults( $overwrite, 'merge' );
$this->assertEquals( true, $result );
$this->assertSame( true, $result );

// Check export import overwrite.
$this->assertEquals( $overwrite, $class->export_role_defaults() );
Expand All @@ -180,7 +180,7 @@ function test_import_export() {
* Import append.
*/
$result = $class->import_role_defaults( $import, 'append' );
$this->assertEquals( true, $result );
$this->assertSame( true, $result );

// Check export import append. Editor admin color should still be `dark`.
$this->assertEquals( $overwrite, $class->export_role_defaults() );
Expand All @@ -192,7 +192,7 @@ function test_import_export() {
),
);
$result = $class->import_role_defaults( $import_admin );
$this->assertEquals( true, $result );
$this->assertSame( true, $result );

/**
* Check export for a single role.
Expand Down Expand Up @@ -225,13 +225,13 @@ function test_get_copy() {
* Invalid, non existing role.
*/
$result = $class->copy_role_defaults( 'editor', 'non_existing_role' );
$this->assertNotEquals( true, $result );
$this->assertNotSame( true, $result );

/**
* Copy defaults.
*/
$result = $class->copy_role_defaults( 'editor', 'author' );
$this->assertEquals( true, $result );
$this->assertSame( true, $result );

// Check if copy was actually successful. Also checks getting role defaults with role parameter.
$check = array(
Expand Down Expand Up @@ -260,15 +260,15 @@ function test_clear() {
*/
$result = $class->clear_role_defaults( 'non_existing_role' );
// @todo Currently still returns true, maybe return false if role doesn't exists?
$this->assertEquals( true, $result );
$this->assertSame( true, $result );
// Should still be the same.
$this->assertEquals( $defaults, $class->get_role_defaults() );

/**
* Clear defaults, single role.
*/
$result = $class->clear_role_defaults( 'author' );
$this->assertEquals( true, $result );
$this->assertSame( true, $result );

$new_defaults = $defaults;
unset( $new_defaults['author'] );
Expand All @@ -279,7 +279,7 @@ function test_clear() {
* Clear all.
*/
$result = $class->clear_role_defaults( '__all__' );
$this->assertEquals( true, $result );
$this->assertSame( true, $result );

$this->assertEquals( array(), $class->get_role_defaults() );

Expand Down
32 changes: 16 additions & 16 deletions tests/test-module-role-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ function test_import() {
*/
$result = $class->import_roles( 'test' );
// We expect an error string.
$this->assertNotEquals( true, $result );
$this->assertNotSame( true, $result );

$caps = array(
'read' => array( 'yay' ),
'test' => true,
);
$result = $class->import_roles( $caps );
// We expect an error array.
$this->assertNotEquals( true, $result );
$this->assertNotSame( true, $result );

/**
* Correct.
Expand All @@ -123,7 +123,7 @@ function test_import() {
$result = $class->import_roles( array(
'data' => array( $role => $caps ),
) );
$this->assertEquals( true, $result );
$this->assertSame( true, $result );

$test_import = get_role( $role );

Expand All @@ -144,14 +144,14 @@ function test_clone() {
*/
$result = $class->clone_role( 'non_existing_role', $role );
// We expect an error string.
$this->assertNotEquals( true, $result );
$this->assertNotSame( true, $result );

/**
* Correct.
*/
$result = $class->clone_role( 'editor', $role );
// We expect an error string.
$this->assertEquals( true, $result );
$this->assertSame( true, $result );

$editor = get_role( 'editor' );
$test_clone = get_role( $role );
Expand All @@ -173,24 +173,24 @@ function test_rename() {
*/
$result = $class->rename_role( 'non_existing_role', $rename );
// We expect an error string.
$this->assertNotEquals( true, $result );
$this->assertNotSame( true, $result );

/**
* Correct.
*/
$result = $class->rename_role( 'editor', $rename );
// We expect an error string.
$this->assertEquals( true, $result );
$this->assertSame( true, $result );

$editor = get_role( 'editor' );
// The editor name should be the new name.
$this->assertEquals( $editor->name, $rename );
$this->assertSame( $editor->name, $rename );

// Revert change.
$class->rename_role( 'editor', 'Editor' );
$editor = get_role( 'editor' );
// Verify that the role is renamed.
$this->assertEquals( $editor->name, 'Editor' );
$this->assertSame( $editor->name, 'Editor' );

}

Expand All @@ -208,18 +208,18 @@ function test_delete() {
*/
$result = $class->delete_role( 'non_existing_role' );
// We expect an error string.
$this->assertNotEquals( true, $result );
$this->assertNotSame( true, $result );

/**
* Protected roles.
*/
$result = $class->delete_role( 'administrator' );
// We expect an error string.
$this->assertNotEquals( true, $result );
$this->assertNotSame( true, $result );

$result = $class->delete_role( get_option( 'default_role' ) );
// We expect an error string.
$this->assertNotEquals( true, $result );
$this->assertNotSame( true, $result );

/**
* Correct.
Expand Down Expand Up @@ -258,11 +258,11 @@ function test_migrate_users() {
*/
$result = $class->delete_role( 'editor', 'non_existing_role' );
// We expect an error string.
$this->assertNotEquals( true, $result );
$this->assertNotSame( true, $result );

$result = $class->delete_role( 'editor', 'editor' );
// We expect an error string.
$this->assertNotEquals( true, $result );
$this->assertNotSame( true, $result );

/**
* Correct.
Expand All @@ -271,7 +271,7 @@ function test_migrate_users() {

$result = $class->delete_role( 'editor', 'test_migrate' );
// Should be ok!
$this->assertEquals( true, $result );
$this->assertSame( true, $result );

/**
* Revert
Expand All @@ -284,7 +284,7 @@ function test_migrate_users() {
'new_role' => 'editor',
) );
// Should be ok!
$this->assertEquals( true, $result );
$this->assertSame( true, $result );

// Load all roles again after removal.
VAA_UnitTest_Factory::vaa_reinit();
Expand Down

0 comments on commit 5569b21

Please sign in to comment.