Skip to content

Commit

Permalink
tests: fix order of expected/actual values passed to asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
justlevine committed Sep 17, 2024
1 parent 43ad50d commit 6bcd960
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 59 deletions.
5 changes: 5 additions & 0 deletions .changeset/many-waves-cry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wpengine/wp-graphql-content-blocks": patch
---

tests: fix order of expected/actual values passed to asserts.
4 changes: 2 additions & 2 deletions tests/unit/BlockAttributesObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public function test_resolve_attribute_object_type() {
// Verify that the ID of the first post matches the one we just created.
$this->assertEquals( $this->post_id, $node['databaseId'] );
// There should be only 1 block
$this->assertEquals( count( $node['editorBlocks'] ), 1 );
$this->assertEquals( 1, count( $node['editorBlocks'] ) );
// There should be a style attribute that matches the json for the content of the attribute
$this->assertEquals( $node['editorBlocks'][0]['attributes']['style'], '{"color":{"background":"#a62929"}}' );
$this->assertEquals( '{"color":{"background":"#a62929"}}', $node['editorBlocks'][0]['attributes']['style'] );
}
}
16 changes: 8 additions & 8 deletions tests/unit/BlockQueriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public function test_retrieve_non_flatten_editor_blocks() {
$this->assertEquals( $this->post_id, $node['databaseId'] );

// There should be only one block using that query when not using flat: true
$this->assertEquals( count( $node['editorBlocks'] ), 1 );
$this->assertEquals( $node['editorBlocks'][0]['name'], 'core/columns' );
$this->assertEquals( 1, count( $node['editorBlocks'] ) );
$this->assertEquals( 'core/columns', $node['editorBlocks'][0]['name'] );
}

public function test_retrieve_flatten_editor_blocks() {
Expand All @@ -93,21 +93,21 @@ public function test_retrieve_flatten_editor_blocks() {
$this->assertEquals( $this->post_id, $node['databaseId'] );

// There should more than one block using that query when using flat: true
$this->assertEquals( count( $node['editorBlocks'] ), 5 );
$this->assertEquals( 5, count( $node['editorBlocks'] ) );

$this->assertEquals( $node['editorBlocks'][0]['name'], 'core/columns' );
$this->assertEquals( 'core/columns', $node['editorBlocks'][0]['name'] );
$this->assertNull( $node['editorBlocks'][0]['parentClientId'] );

$this->assertEquals( $node['editorBlocks'][1]['name'], 'core/column' );
$this->assertEquals( 'core/column', $node['editorBlocks'][1]['name'] );
$this->assertNotNull( $node['editorBlocks'][1]['parentClientId'] );

$this->assertEquals( $node['editorBlocks'][2]['name'], 'core/paragraph' );
$this->assertEquals( 'core/paragraph', $node['editorBlocks'][2]['name'] );
$this->assertNotNull( $node['editorBlocks'][2]['parentClientId'] );

$this->assertEquals( $node['editorBlocks'][3]['name'], 'core/column' );
$this->assertEquals( 'core/column', $node['editorBlocks'][3]['name'] );
$this->assertNotNull( $node['editorBlocks'][3]['parentClientId'] );

$this->assertEquals( $node['editorBlocks'][4]['name'], 'core/paragraph' );
$this->assertEquals( 'core/paragraph', $node['editorBlocks'][4]['name'] );
$this->assertNotNull( $node['editorBlocks'][4]['parentClientId'] );
}
}
18 changes: 9 additions & 9 deletions tests/unit/BlockSupportsAnchorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function test_register_anchor_schema_fields() {
$this->instance::register( $block );

// Verify BlockWithSupportsAnchor fields registration
$query = '
$query = '
query BlockWithSupportsAnchorMeta {
__type(name: "BlockWithSupportsAnchor") {
fields {
Expand Down Expand Up @@ -92,7 +92,7 @@ public function test_register_anchor_schema_fields() {
],
];
$this->assertArrayHasKey( 'data', $actual, json_encode( $actual ) );
$this->assertEquals( $actual['data']['__type']['fields'], $expected['fields'] );
$this->assertEquals( $expected['fields'], $actual['data']['__type']['fields'] );
$this->assertContains( $expected['possibleTypes'][0], $actual['data']['__type']['possibleTypes'] );
$this->assertContains( $expected['possibleTypes'][1], $actual['data']['__type']['possibleTypes'] );
}
Expand Down Expand Up @@ -121,17 +121,17 @@ public function test_register_anchor_query_field() {
$actual = graphql( [ 'query' => $query ] );
$node = $actual['data']['posts']['nodes'][0];

$this->assertEquals( count( $node['editorBlocks'] ), 4 );
$this->assertEquals( $node['editorBlocks'][0]['name'], 'core/paragraph' );
$this->assertEquals( $node['editorBlocks'][0]['anchor'], 'example' );
$this->assertEquals( 4, count( $node['editorBlocks'] ) );
$this->assertEquals( 'core/paragraph', $node['editorBlocks'][0]['name'] );
$this->assertEquals( 'example', $node['editorBlocks'][0]['anchor'] );

$this->assertEquals( $node['editorBlocks'][1]['name'], 'core/paragraph' );
$this->assertEquals( 'core/paragraph', $node['editorBlocks'][1]['name'] );
$this->assertNull( $node['editorBlocks'][1]['anchor'] );

$this->assertEquals( $node['editorBlocks'][2]['name'], 'core/group' );
$this->assertEquals( 'core/group', $node['editorBlocks'][2]['name'] );
$this->assertNull( $node['editorBlocks'][2]['anchor'] );

$this->assertEquals( $node['editorBlocks'][3]['name'], 'core/paragraph' );
$this->assertEquals( $node['editorBlocks'][3]['anchor'], 'example-inner' );
$this->assertEquals( 'core/paragraph', $node['editorBlocks'][3]['name'] );
$this->assertEquals( 'example-inner', $node['editorBlocks'][3]['anchor'] );
}
}
12 changes: 6 additions & 6 deletions tests/unit/CoreImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ public function test_retrieve_core_image_media_details() {
$node = $actual['data']['posts']['nodes'][0];

$this->assertEquals(
$node['editorBlocks'][0]['mediaDetails'],
[
'width' => 50,
'height' => 50,
]
],
$node['editorBlocks'][0]['mediaDetails']
);
}

Expand Down Expand Up @@ -111,11 +111,10 @@ public function test_retrieve_core_image_attributes() {
// Verify that the ID of the first post matches the one we just created.
$this->assertEquals( $this->post_id, $node['databaseId'] );
// There should be only one block using that query when not using flat: true
$this->assertEquals( count( $node['editorBlocks'] ), 1 );
$this->assertEquals( $node['editorBlocks'][0]['name'], 'core/image' );
$this->assertEquals( 1, count( $node['editorBlocks'] ) );
$this->assertEquals( 'core/image', $node['editorBlocks'][0]['name'] );

$this->assertEquals(
$node['editorBlocks'][0]['attributes'],
[
'width' => '500',
'height' => 500.0,
Expand All @@ -130,7 +129,8 @@ public function test_retrieve_core_image_attributes() {
'align' => null,
'caption' => '',
'cssClassName' => 'wp-block-image size-full is-resized',
]
],
$node['editorBlocks'][0]['attributes']
);
}
}
12 changes: 6 additions & 6 deletions tests/unit/CoreTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function tearDown(): void {

public function test_retrieve_core_table_attribute_fields() {
$this->markTestSkipped( 'must be revisited since the test is failing on the CI for an unknown reason' );
$query = '
$query = '
fragment CoreTableBlockFragment on CoreTable {
attributes {
caption
Expand All @@ -64,18 +64,18 @@ public function test_retrieve_core_table_attribute_fields() {

$actual = graphql( [ 'query' => $query ] );

$node = $actual['data']['posts']['nodes'][0];
$node = $actual['data']['posts']['nodes'][0];

$this->assertEquals( $node['editorBlocks'][0]['name'], 'core/table' );
$this->assertEquals( 'core/table', $node['editorBlocks'][0]['name'] );
// There should be only one block using that query when not using flat: true
$this->assertEquals( count( $node['editorBlocks'] ), 1 );
$this->assertEquals( 1, count( $node['editorBlocks'] ) );
$this->assertEquals(
$node['editorBlocks'][0]['attributes'],
[
'caption' => 'Caption',
'align' => null,
'anchor' => null,
]
],
$node['editorBlocks'][0]['attributes']
);
}
}
8 changes: 4 additions & 4 deletions tests/unit/CoreVideoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,10 @@ public function test_retrieve_core_video_attributes() {
// Verify that the ID of the first post matches the one we just created.
$this->assertEquals( $this->post_id, $node['databaseId'] );
// There should be only one block using that query when not using flat: true
$this->assertEquals( count( $node['editorBlocks'] ), 1 );
$this->assertEquals( $node['editorBlocks'][0]['name'], 'core/video' );
$this->assertEquals( 1, count( $node['editorBlocks'] ) );
$this->assertEquals( 'core/video', $node['editorBlocks'][0]['name'] );

$this->assertEquals(
$node['editorBlocks'][0]['attributes'],
[
'align' => null,
'anchor' => null,
Expand All @@ -95,7 +94,8 @@ public function test_retrieve_core_video_attributes() {
'loop' => true,
'poster' => 'http://mysite.local/wp-content/uploads/2023/05/pexels-egor-komarov-14420089-scaled.jpg',
'id' => 1636.0,
]
],
$node['editorBlocks'][0]['attributes']
);
}
}
36 changes: 18 additions & 18 deletions tests/unit/DOMHelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ public function testParseAttribute(): void {
// $html
$this->assertNull( DOMHelpers::parse_attribute( '', $no_existent_selector, $data_attribute ) );
$this->assertNull( DOMHelpers::parse_attribute( $html, $no_existent_selector, $data_attribute ) );
$this->assertEquals( DOMHelpers::parse_attribute( $html, $no_existent_selector, $data_attribute, 'Bar' ), 'Bar' );
$this->assertEquals( DOMHelpers::parse_attribute( $html, $id_selector, $data_attribute ), 'foo-data' );
$this->assertEquals( DOMHelpers::parse_attribute( $html, $id_selector, $class_attribute ), 'foo-class' );
$this->assertEquals( DOMHelpers::parse_attribute( $html, $id_selector, $id_attribute ), 'foo-id' );
$this->assertEquals( DOMHelpers::parse_attribute( $html, $class_selector, $data_attribute ), 'foo-data' );
$this->assertEquals( DOMHelpers::parse_attribute( $html, $class_selector, $class_attribute ), 'foo-class' );
$this->assertEquals( DOMHelpers::parse_attribute( $html, $class_selector, $id_attribute ), 'foo-id' );
$this->assertEquals( DOMHelpers::parse_attribute( $html, $element_selector, $data_attribute ), 'foo-data' );
$this->assertEquals( DOMHelpers::parse_attribute( $html, $element_selector, $class_attribute ), 'foo-class' );
$this->assertEquals( DOMHelpers::parse_attribute( $html, $element_selector, $id_attribute ), 'foo-id' );
$this->assertEquals( 'Bar', DOMHelpers::parse_attribute( $html, $no_existent_selector, $data_attribute, 'Bar' ) );
$this->assertEquals( 'foo-data', DOMHelpers::parse_attribute( $html, $id_selector, $data_attribute ) );
$this->assertEquals( 'foo-class', DOMHelpers::parse_attribute( $html, $id_selector, $class_attribute ) );
$this->assertEquals( 'foo-id', DOMHelpers::parse_attribute( $html, $id_selector, $id_attribute ) );
$this->assertEquals( 'foo-data', DOMHelpers::parse_attribute( $html, $class_selector, $data_attribute ) );
$this->assertEquals( 'foo-class', DOMHelpers::parse_attribute( $html, $class_selector, $class_attribute ) );
$this->assertEquals( 'foo-id', DOMHelpers::parse_attribute( $html, $class_selector, $id_attribute ) );
$this->assertEquals( 'foo-data', DOMHelpers::parse_attribute( $html, $element_selector, $data_attribute ) );
$this->assertEquals( 'foo-class', DOMHelpers::parse_attribute( $html, $element_selector, $class_attribute ) );
$this->assertEquals( 'foo-id', DOMHelpers::parse_attribute( $html, $element_selector, $id_attribute ) );

// $html2
$this->assertEquals( 'center', DOMHelpers::parse_attribute( $html2, '*', 'data-align' ) );
Expand All @@ -52,10 +52,10 @@ public function testParseHTML(): void {

$this->assertNull( DOMHelpers::parse_html( '', $no_existent_selector ) );
$this->assertEmpty( DOMHelpers::parse_html( $html, $no_existent_selector ) );
$this->assertEquals( DOMHelpers::parse_html( $html, $no_existent_selector, 'Bar' ), 'Bar' );
$this->assertEquals( DOMHelpers::parse_html( $html, $id_selector ), '<span>Bar</span>' );
$this->assertEquals( DOMHelpers::parse_html( $html, $class_selector ), '<span>Bar</span>' );
$this->assertEquals( DOMHelpers::parse_html( $html, $element_selector ), '<span>Bar</span>' );
$this->assertEquals( 'Bar', DOMHelpers::parse_html( $html, $no_existent_selector, 'Bar' ) );
$this->assertEquals( '<span>Bar</span>', DOMHelpers::parse_html( $html, $id_selector ) );
$this->assertEquals( '<span>Bar</span>', DOMHelpers::parse_html( $html, $class_selector ) );
$this->assertEquals( '<span>Bar</span>', DOMHelpers::parse_html( $html, $element_selector ) );
}

public function testGetElementsFromHTML(): void {
Expand All @@ -64,7 +64,7 @@ public function testGetElementsFromHTML(): void {
$no_existent_selector = 'span';

$this->assertNull( DOMHelpers::get_elements_from_html( '', $no_existent_selector ) );
$this->assertEquals( DOMHelpers::get_elements_from_html( $html, $element_selector ), '<p>First paragraph</p><p>Second paragraph</p>' );
$this->assertEquals( '<p>First paragraph</p><p>Second paragraph</p>', DOMHelpers::get_elements_from_html( $html, $element_selector ) );
$this->assertEmpty( DOMHelpers::get_elements_from_html( $html, $no_existent_selector ) );
}

Expand All @@ -78,10 +78,10 @@ public function getTextFromSelector(): void {

// getTextFromSelector should get all text (even descendents) according to "textContent"
// https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent
$this->assertEquals( DOMHelpers::getTextFromSelector( $html, $blockquote_element ), 'First paragraphMy divSecond paragraph' );
$this->assertEquals( 'First paragraphMy divSecond paragraph', DOMHelpers::getTextFromSelector( $html, $blockquote_element ) );

$this->assertEquals( DOMHelpers::getTextFromSelector( $html, $p_element ), 'First paragraph' );
$this->assertEquals( DOMHelpers::getTextFromSelector( $html, $div_element ), 'My div' );
$this->assertEquals( 'First paragraph', DOMHelpers::getTextFromSelector( $html, $p_element ) );
$this->assertEquals( 'My div', DOMHelpers::getTextFromSelector( $html, $div_element ) );
$this->assertEmpty( DOMHelpers::get_elements_from_html( $html, $no_existent_selector ) );
}
}
4 changes: 2 additions & 2 deletions tests/unit/EditorBlockInterfaceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function test_register_type() {
],
];
$this->assertArrayHasKey( 'data', $response, json_encode( $response ) );
$this->assertEquals( $response['data']['__type'], $expected );
$this->assertEquals( $expected, $response['data']['__type'] );

$queryContentBlockMeta = '
query ContentBlockMeta {
Expand Down Expand Up @@ -107,6 +107,6 @@ static function ( $val ) {
);
sort( $actual );
sort( $expected );
$this->assertEquals( $actual, $expected );
$this->assertEquals( $expected, $actual );
}
}
4 changes: 2 additions & 2 deletions tests/unit/PostTypeBlockInterfaceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function test_register_type() {
],
];
$this->assertArrayHasKey( 'data', $response, json_encode( $response ) );
$this->assertEquals( $response['data']['__type'], $expected );
$this->assertEquals( $expected, $response['data']['__type'] );

// Verify PostEditorBlock fields registration
$queryContentBlockMeta = '
Expand Down Expand Up @@ -99,6 +99,6 @@ static function ( $val ) {
);
sort( $actual );
sort( $expected );
$this->assertEquals( $actual, $expected );
$this->assertEquals( $expected, $actual );
}
}
4 changes: 2 additions & 2 deletions tests/unit/RegistryTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ interfaces {
$this->assertArrayHasKey( 'data', $response, json_encode( $response ) );
$this->assertNotEmpty( $response['data']['__type']['interfaces'] );
$this->assertTrue( in_array( $contains_interface, $response['data']['__type']['interfaces'] ) );
$this->assertEquals( array_intersect_key( $contains_detail, $response['data']['__type'] ), $contains_detail );
$this->assertEquals( $contains_detail, array_intersect_key( $contains_detail, $response['data']['__type'] ) );
$this->assertEquals( $contains_possible_types, $response['data']['__type']['possibleTypes'] );

// Verify NodeWithPostEditorBlocks meta
Expand All @@ -209,6 +209,6 @@ interfaces {
$this->assertArrayHasKey( 'data', $response, json_encode( $response ) );
$this->assertNotEmpty( $response['data']['__type']['interfaces'] );
$this->assertTrue( in_array( $contains_interface, $response['data']['__type']['interfaces'] ) );
$this->assertEquals( array_intersect_key( $contains_detail, $response['data']['__type'] ), $contains_detail );
$this->assertEquals( $contains_detail, array_intersect_key( $contains_detail, $response['data']['__type'] ) );
}
}

0 comments on commit 6bcd960

Please sign in to comment.