Skip to content

Commit 556e06d

Browse files
rvdsteegeCopilot
andcommitted
Fix WordPress icon test environment
Install Composer dependencies automatically in the pinned WordPress 7.1 wp-env so the plugin autoloader and payment logo assets are available. Add an explicit API call regression test. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent e925057 commit 556e06d

4 files changed

Lines changed: 63 additions & 0 deletions

File tree

.wp-env.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"$schema": "https://schemas.wp.org/trunk/wp-env.json",
3+
"core": "WordPress/WordPress#7.1",
4+
"plugins": [
5+
"."
6+
],
7+
"testsEnvironment": false,
8+
"lifecycleScripts": {
9+
"afterStart": "composer install --no-interaction"
10+
}
11+
}

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,14 @@ composer lint
7474
composer phpcs
7575
composer test
7676
composer check
77+
wpenv start
7778
```
7879

80+
The wp-env lifecycle installs the Composer dependencies immediately after the
81+
environment starts, before browser or API checks load the plugin. This is
82+
required because the payment method assets and the plugin's autoloaded classes
83+
are provided through Composer.
84+
7985
The test suite verifies all catalog entries against the installed
8086
`pronamic/wp-pay-logos` package, including the presence of SVG shapes supported by
8187
the Core Icon API sanitizer. CI runs linting, coding standards, and tests on all

tests/IconRegistrarTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ final class IconRegistrarTest extends TestCase {
2121
* Reset registration state.
2222
*/
2323
protected function setUp(): void {
24+
$GLOBALS['pronamic_pay_wp_icons_api_calls'] = [];
2425
$GLOBALS['pronamic_pay_wp_icons_collections'] = [];
2526
$GLOBALS['pronamic_pay_wp_icons_icons'] = [];
2627
}
@@ -49,6 +50,38 @@ public function test_registers_collection_and_icons(): void {
4950
}
5051
}
5152

53+
/**
54+
* Test the WordPress 7.1 Icon API calls.
55+
*/
56+
public function test_calls_wordpress_71_icon_api_with_expected_arguments(): void {
57+
$registrar = new IconRegistrar( new AssetLocator( new ImageService() ) );
58+
59+
$registrar->register();
60+
61+
$calls = $GLOBALS['pronamic_pay_wp_icons_api_calls'];
62+
63+
$this->assertSame(
64+
[
65+
'function' => 'wp_register_icon_collection',
66+
'slug' => IconRegistrar::COLLECTION_SLUG,
67+
'args' => [
68+
'label' => 'Pronamic Pay',
69+
'description' => 'Payment method icons provided by Pronamic Pay.',
70+
],
71+
],
72+
$calls[0]
73+
);
74+
$this->assertCount( 1 + \count( IconCatalog::get_icons() ), $calls );
75+
76+
foreach ( \array_slice( $calls, 1 ) as $call ) {
77+
$this->assertSame( 'wp_register_icon', $call['function'] );
78+
$this->assertStringStartsWith( IconRegistrar::COLLECTION_SLUG . '/', $call['name'] );
79+
$this->assertSame( [ 'label', 'file_path' ], \array_keys( $call['args'] ) );
80+
$this->assertIsString( $call['args']['label'] );
81+
$this->assertFileIsReadable( $call['args']['file_path'] );
82+
}
83+
}
84+
5285
/**
5386
* Test icons are not registered when the collection registration fails.
5487
*/

tests/bootstrap.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
require_once $autoload_file;
1515

1616
$GLOBALS['pronamic_pay_wp_icons_actions'] = [];
17+
$GLOBALS['pronamic_pay_wp_icons_api_calls'] = [];
1718
$GLOBALS['pronamic_pay_wp_icons_collections'] = [];
1819
$GLOBALS['pronamic_pay_wp_icons_icons'] = [];
1920

@@ -55,6 +56,12 @@ function add_action( $hook, $callback ): void {
5556
* @return bool
5657
*/
5758
function wp_register_icon_collection( $slug, $args ): bool {
59+
$GLOBALS['pronamic_pay_wp_icons_api_calls'][] = [
60+
'function' => __FUNCTION__,
61+
'slug' => $slug,
62+
'args' => $args,
63+
];
64+
5865
if ( isset( $GLOBALS['pronamic_pay_wp_icons_collections'][ $slug ] ) ) {
5966
return false;
6067
}
@@ -72,6 +79,12 @@ function wp_register_icon_collection( $slug, $args ): bool {
7279
* @return bool
7380
*/
7481
function wp_register_icon( $name, $args ): bool {
82+
$GLOBALS['pronamic_pay_wp_icons_api_calls'][] = [
83+
'function' => __FUNCTION__,
84+
'name' => $name,
85+
'args' => $args,
86+
];
87+
7588
$GLOBALS['pronamic_pay_wp_icons_icons'][ $name ] = $args;
7689

7790
return true;

0 commit comments

Comments
 (0)