Skip to content
This repository was archived by the owner on Nov 6, 2022. It is now read-only.

Commit be58f0c

Browse files
committed
Add an integration test for all of the fields
This tests all of the fields except for the repeater. It ensures that when they are present as attributes, they work as expected in the block template.
1 parent cea55b3 commit be58f0c

File tree

6 files changed

+456
-4
lines changed

6 files changed

+456
-4
lines changed

php/blocks/class-loader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ public function get_attributes_from_field( $attributes, $field_name, $field ) {
275275
/**
276276
* Renders the block provided a template is provided.
277277
*
278-
* @param array $block The block to render.
278+
* @param Block $block The block to render.
279279
* @param array $attributes Attributes to render.
280280
*
281281
* @return mixed

php/class-util.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
namespace Block_Lab;
1212

1313
use Block_Lab\Blocks;
14-
use Block_Lab\Component_Abstract;
1514

1615
/**
1716
* Class Util

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
</testsuite>
1616

1717
<testsuite name="integration">
18-
<directory suffix=".php">./tests/php/integration/</directory>
18+
<directory prefix="test-" suffix=".php">./tests/php/integration/</directory>
1919
</testsuite>
2020
</testsuites>
2121

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
/**
3+
* A mock template for a block, testing all fields except the repeater.
4+
*
5+
* @package Block_Lab
6+
*/
7+
8+
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaping could interfere with testing block_value().
9+
10+
$string_fields = array(
11+
'text',
12+
'textarea',
13+
'url',
14+
'email',
15+
'number',
16+
'color',
17+
'image',
18+
'select',
19+
'toggle',
20+
'range',
21+
'checkbox',
22+
'radio',
23+
'rich-text',
24+
);
25+
26+
foreach ( $string_fields as $field ) :
27+
?>
28+
<p class="<?php block_field( 'className' ); ?>">
29+
<?php
30+
/* translators: %s is the field name */
31+
printf(
32+
'Here is the result of block_field() for %s: ',
33+
$field
34+
);
35+
block_field( $field );
36+
?>
37+
</p>
38+
39+
<p>
40+
<?php
41+
/* translators: %s is the field name, %s is the result of calling block_value() */
42+
printf(
43+
'And here is the result of calling block_value() for %s: %s',
44+
$field,
45+
block_value( $field )
46+
);
47+
?>
48+
</p>
49+
<?php
50+
endforeach;
51+
52+
$non_string_fields = array(
53+
'post' => array( 'ID', 'post_name' ),
54+
'taxonomy' => array( 'term_id', 'name' ),
55+
'user' => array( 'ID', 'first_name' ),
56+
);
57+
58+
foreach ( $non_string_fields as $name => $value ) :
59+
/* translators: %s is the field name */
60+
printf(
61+
'Here is the result of block_field() for %s: ',
62+
$name
63+
);
64+
block_field( $name );
65+
66+
$block_value = block_value( $name );
67+
foreach ( $value as $block_value_property ) :
68+
printf(
69+
'Here is the result of passing %s to block_value() with the property %s: %s',
70+
$name,
71+
$block_value_property,
72+
$block_value->$block_value_property
73+
);
74+
endforeach;
75+
endforeach;

0 commit comments

Comments
 (0)