-
Notifications
You must be signed in to change notification settings - Fork 446
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 #2763 from blakewilson/support-viewer-toolbar-visi…
…bility feat: support "Show Toolbar when viewing site" user setting
- Loading branch information
Showing
3 changed files
with
89 additions
and
20 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
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,60 @@ | ||
<?php | ||
|
||
class ShouldShowAdminToolbarQueryTest extends \Codeception\TestCase\WPTestCase { | ||
|
||
public function setUp(): void { | ||
parent::setUp(); | ||
WPGraphQL::clear_schema(); | ||
} | ||
|
||
public function tearDown(): void { | ||
WPGraphQL::clear_schema(); | ||
parent::tearDown(); | ||
} | ||
|
||
public function testViewerQuery() { | ||
|
||
$user_id = $this->factory->user->create( [ | ||
'role' => 'administrator', | ||
] ); | ||
|
||
$query = ' | ||
{ | ||
viewer{ | ||
userId | ||
roles { | ||
nodes { | ||
name | ||
} | ||
} | ||
shouldShowAdminToolbar | ||
} | ||
} | ||
'; | ||
|
||
/** | ||
* Set the current user so we can properly test the viewer query | ||
*/ | ||
wp_set_current_user( $user_id ); | ||
|
||
$actual = graphql( [ 'query' => $query ] ); | ||
|
||
codecept_debug( $actual ); | ||
|
||
$this->assertArrayNotHasKey( 'errors', $actual ); | ||
$this->assertEquals( $user_id, $actual['data']['viewer']['userId'] ); | ||
$this->assertSame( true, $actual['data']['viewer']['shouldShowAdminToolbar'] ); | ||
|
||
// Update the user's preference to not show admin bar. | ||
update_user_meta( $user_id, 'show_admin_bar_front', "false" ); | ||
|
||
$actual = graphql( [ 'query' => $query ] ); | ||
|
||
codecept_debug( $actual ); | ||
|
||
$this->assertArrayNotHasKey( 'errors', $actual ); | ||
$this->assertEquals( $user_id, $actual['data']['viewer']['userId'] ); | ||
$this->assertSame( false, $actual['data']['viewer']['shouldShowAdminToolbar'] ); | ||
} | ||
|
||
} |