This repository has been archived by the owner on Jul 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SSR: Handle attribute directives separately from tag directives (#140)
- Create new subfolders `attributes` and `tags` inside both `src/directives/` and `phpunit/directives/`. - In `wp-directives.php`, use separate arrays for attribute and tag directives. - Remove now-obsolete code and tests from attribute directive processors (that would've dealt with being called on a tag directive). - Differentiate `process_wp_context_tag` and `process_wp_context_attribute`. - Disable unit test for `wp-context` attribute directive, as it's not implemented yet.
- Loading branch information
Showing
11 changed files
with
107 additions
and
127 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,43 @@ | ||
<?php | ||
/** | ||
* wp-context attribute directive test. | ||
*/ | ||
|
||
// require_once __DIR__ . '/../../../src/directives/attributes/wp-context.php'; // TODO | ||
|
||
require_once __DIR__ . '/../../../src/directives/class-wp-directive-context.php'; | ||
|
||
require_once __DIR__ . '/../../../../gutenberg/lib/experimental/html/index.php'; | ||
|
||
/** | ||
* Tests for the wp-context attribute directive. | ||
* | ||
* @group directives | ||
* @covers process_wp_context_attribute | ||
*/ | ||
class Tests_Directives_Attributes_WpContext extends WP_UnitTestCase { | ||
public function test_directive_merges_context_correctly_upon_wp_context_attribute_on_opening_tag() { | ||
$this->markTestSkipped( 'Need to implement the wp-context attribute directive processor first.' ); | ||
|
||
$context = new WP_Directive_Context( | ||
array( | ||
'myblock' => array( 'open' => false ), | ||
'otherblock' => array( 'somekey' => 'somevalue' ), | ||
) | ||
); | ||
|
||
$markup = '<div wp-context=\'{ "myblock": { "open": true } }\'>'; | ||
$tags = new WP_HTML_Tag_Processor( $markup ); | ||
$tags->next_tag(); | ||
|
||
process_wp_context_attribute( $tags, $context ); | ||
|
||
$this->assertSame( | ||
array( | ||
'myblock' => array( 'open' => true ), | ||
'otherblock' => array( 'somekey' => 'somevalue' ), | ||
), | ||
$context->get_context() | ||
); | ||
} | ||
} |
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
10 changes: 1 addition & 9 deletions
10
src/directives/wp-bind.php → src/directives/attributes/wp-bind.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
10 changes: 1 addition & 9 deletions
10
src/directives/wp-class.php → src/directives/attributes/wp-class.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
10 changes: 1 addition & 9 deletions
10
src/directives/wp-style.php → src/directives/attributes/wp-style.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
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,19 @@ | ||
<?php | ||
|
||
function process_wp_context_tag( $tags, $context ) { | ||
if ( $tags->is_tag_closer() ) { | ||
$context->rewind_context(); | ||
return; | ||
} | ||
|
||
$value = $tags->get_attribute( 'data' ); | ||
if ( null === $value ) { | ||
// No wp-context directive. | ||
return; | ||
} | ||
|
||
$new_context = json_decode( $value, true ); | ||
// TODO: Error handling. | ||
|
||
$context->set_context( $new_context ); | ||
} |
This file was deleted.
Oops, something went wrong.
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