-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ae307cd
commit 03415f8
Showing
1 changed file
with
99 additions
and
0 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,99 @@ | ||
<?php | ||
|
||
namespace WPGraphQL\ContentBlocks\Unit; | ||
|
||
final class CorePostTermsTest extends PluginTestCase { | ||
|
||
/** | ||
* The ID of the post created for the test. | ||
* | ||
* @var int | ||
*/ | ||
public $post_id; | ||
|
||
public function setUp(): void { | ||
parent::setUp(); | ||
|
||
$this->post_id = wp_insert_post( | ||
[ | ||
'post_title' => 'Test Post', | ||
'post_content' => '', | ||
'post_status' => 'publish', | ||
] | ||
); | ||
|
||
\WPGraphQL::clear_schema(); | ||
} | ||
|
||
public function tearDown(): void { | ||
wp_delete_post($this->post_id, true); | ||
\WPGraphQL::clear_schema(); | ||
|
||
parent::tearDown(); | ||
} | ||
|
||
/** | ||
* Get the GraphQL query for the CorePostTerms block. | ||
*/ | ||
public function query(): string { | ||
return ' | ||
query TestPostTerms($id: ID!) { | ||
post(id: $id, idType: DATABASE_ID) { | ||
databaseId | ||
editorBlocks { | ||
__typename | ||
... on CorePostTerms { | ||
prefix | ||
suffix | ||
term | ||
terms { | ||
__typename | ||
nodes { | ||
id | ||
name | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
'; | ||
} | ||
|
||
/** | ||
* Test that the CorePostTerms block retrieves attributes and terms correctly. | ||
*/ | ||
public function test_retrieve_core_post_terms(): void { | ||
$block_content = '<!-- wp:post-terms {"prefix":"Before","suffix":"After","term":"category"} /-->'; | ||
|
||
wp_update_post( | ||
[ | ||
'ID' => $this->post_id, | ||
'post_content' => $block_content, | ||
] | ||
); | ||
|
||
$variables = [ 'id' => $this->post_id ]; | ||
$query = $this->query(); | ||
$actual = graphql(compact('query', 'variables')); | ||
|
||
$node = $actual['data']['post']; | ||
|
||
$this->assertEquals($this->post_id, $node['databaseId']); | ||
$this->assertArrayHasKey('editorBlocks', $node); | ||
$this->assertCount(1, $node['editorBlocks']); | ||
|
||
$block = $node['editorBlocks'][0]; | ||
|
||
$this->assertEquals('CorePostTerms', $block['__typename']); | ||
$this->assertEquals('Before', $block['prefix']); | ||
$this->assertEquals('After', $block['suffix']); | ||
$this->assertEquals('category', $block['term']); | ||
|
||
$this->assertArrayHasKey('terms', $block); | ||
$this->assertArrayHasKey('nodes', $block['terms']); | ||
$this->assertIsArray($block['terms']['nodes']); | ||
|
||
$this->assertEquals('CorePostTermsToTermNodeConnection', $block['terms']['__typename']); | ||
} | ||
} |