Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions .github/workflows/js-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,21 @@ jobs:
with:
node-version: "22"

# The tests in tests/js only import Node built-ins and dependency-free
# modules from js/src, so no npm install is needed.
# Some tests parse plugin source with @babel/core, so install dev dependencies.
- name: Cache dependencies
id: cache-npm
uses: actions/cache@v5
with:
path: |
~/.npm
node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-modules-

- name: Install dependencies
if: steps.cache-npm.outputs.cache-hit != 'true'
run: npm ci --include=dev --legacy-peer-deps

- name: Run JS unit tests
run: node --test tests/js/*.test.mjs
19 changes: 15 additions & 4 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ jobs:
env:
WP_DEVELOP_DIR: /tmp/wordpress/
WP_MULTISITE: ${{ matrix.multisite }}
# The ubuntu-26.04 runner image no longer ships MySQL, so run it as a service.
services:
mysql:
image: mysql:8.4
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: wordpress_tests
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping -h 127.0.0.1 -proot"
--health-interval=5s
--health-timeout=5s
--health-retries=20
strategy:
matrix:
include:
Expand Down Expand Up @@ -72,6 +86,7 @@ jobs:
sed -i "s/youremptytestdbnamehere/wordpress_tests/" wp-tests-config.php
sed -i "s/yourusernamehere/root/" wp-tests-config.php
sed -i "s/yourpasswordhere/root/" wp-tests-config.php
sed -i "s/'localhost'/'127.0.0.1'/" wp-tests-config.php

- name: Read WP core's required Node version
id: wp-node
Expand All @@ -89,10 +104,6 @@ jobs:
cd /tmp/wordpress
npm ci
npm run build:dev
- name: Creating database
run: |
sudo /etc/init.d/mysql start
mysql -u root -proot -e "CREATE DATABASE wordpress_tests;"
- name: PhpUnit tests
run: |
cd "/tmp/wordpress/src/wp-content/plugins/formidable"
Expand Down
2 changes: 1 addition & 1 deletion classes/helpers/FrmBuilderPreviewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public static function supports( $field, $field_obj, $display ) {
* @param bool $supported Whether the preview can be drawn in the browser.
* @param object $field The field being added to the form builder.
*/
return apply_filters( 'frm_builder_preview_in_browser', true, $field );
return (bool) apply_filters( 'frm_builder_preview_in_browser', true, $field );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion classes/models/FrmFormApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ protected function api_url() {
* @return bool
*/
protected function include_boosts() {
return str_starts_with( (string) $this->cache_key, 'frm_addons_l' );
return str_starts_with( $this->cache_key, 'frm_addons_l' );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class RemoveUselessParenthesesSniff implements Sniff {
/**
* The Slevomat sniff instance, false when it is not installed, null until first use.
*
* @var object|false|null
* @var false|object|null
*/
private $inner;

Expand Down Expand Up @@ -102,7 +102,7 @@ public function process( File $phpcsFile, $stackPtr ) {
/**
* Load the Slevomat sniff once.
*
* @return object|false
* @return false|object
*/
private function getInner() {
if ( null === $this->inner ) {
Expand Down
33 changes: 33 additions & 0 deletions stubs.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,17 @@ public static function mod_other_vals( $values = false, $location = 'front' ) {
}
class FrmProEntryFormatter extends FrmEntryFormatter {
}
class FrmProFieldText extends FrmFieldText {
}
class FrmProCopy {
/**
* @param bool $force Whether to run the install even when the database is current.
*
* @return void
*/
public static function install( $force = false ) {
}
}
/**
* The Registration add-on's entry controller. Constructing it is what lets a
* registration form's entry run its user creation, and the abilities do that
Expand Down Expand Up @@ -858,6 +869,28 @@ function wp_get_ability_category( $slug ) {
*/
function wp_unregister_ability( $name ) {
}
/**
* @param string $slug Category slug.
*
* @return WP_Ability_Category|null
*/
function wp_unregister_ability_category( $slug ) {
}
/**
* Added in WordPress 6.1, after the wordpress-stubs release this plugin pins.
*
* @param string $hook_name The name of the filter hook.
*
* @return int The number of times the filter hook has been applied.
*/
function did_filter( $hook_name ) {
}
/**
* The exception the WordPress test suite throws from wp_die(). Tests catch it,
* and mago analyzes the tests without loading the WordPress test library.
*/
class WPDieException extends Exception {
}
}

/**
Expand Down
20 changes: 14 additions & 6 deletions tests/js/paypalBootstrap.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ test( 'PayPal initializes once on DOMContentLoaded when the script runs while lo
assert.equal( state.initRuns, 1 );
} );

/**
* Let pending microtasks run until a condition holds, giving up after a few ticks.
*
* @param {Function} isDone Returns true once the awaited state is reached.
* @return {Promise<void>} Resolves when the condition holds or the tick limit is reached.
*/
async function flushMicrotasksUntil( isDone ) {
for ( let tick = 0; tick < 10 && ! isDone(); tick++ ) {
await Promise.resolve();
}
}

/**
* Exercise the real initializer while wallet discovery is still waiting.
*
Expand Down Expand Up @@ -101,14 +113,10 @@ async function checkOverlappingInitialization() {
};
runInNewContext( `let thisForm, cardElementContainer, isRecurring, selectedMethod; let initRunId = 0;${ source.slice( start, end ) }`, context );
const first = context.paypalInit();
for ( let tick = 0; tick < 10 && waiting < 1; tick++ ) {
await Promise.resolve();
}
await flushMicrotasksUntil( () => waiting >= 1 );
assert.equal( waiting, 1 );
const second = context.paypalInit();
for ( let tick = 0; tick < 10 && waiting < 2; tick++ ) {
await Promise.resolve();
}
await flushMicrotasksUntil( () => waiting >= 2 );
assert.equal( waiting, 2 );
resume();
await Promise.all( [ first, second ] );
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/fields/test_FrmFieldAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ public function test_validate_checks_us_zip_format( $zip, $is_valid ) {
}

/**
* @return \Iterator<string, array<(array<string> | string)>>
* @return \Iterator<string, array{string, bool}>
*/
public static function us_zip_provider() {
yield 'five digits' => array( '62704', true );
Expand Down Expand Up @@ -603,7 +603,7 @@ public function test_address_string_to_array( $value, $expected ) {
}

/**
* @return \Iterator<string, array<(array | string)>>
* @return \Iterator<string, array{(array<string, string> | string | null), array<string, string>}>
*/
public static function address_string_provider() {
yield 'six parts map in order' => array(
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/fields/test_FrmFieldCombo.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ public function test_get_export_headings() {
)
);

$field_id = $field['id'];
$field_name = $field['name'];
$field_id = (int) $field['id'];
$field_name = (string) $field['name'];

$this->set_private_property( $combo_field, 'field', $field );

Expand Down
8 changes: 7 additions & 1 deletion tests/phpunit/fields/test_FrmFieldsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,13 @@ public function test_builder_settings_remain_inline_without_deferred_collector()
}

public function test_builder_placeholder_manifest_preserves_attributes_and_order() {
$form_id = $this->factory->form->create();
$form_id = $this->factory->form->create();

/**
* Filled in by FrmFieldsController::load_single_field() as each placeholder renders.
*
* @var stdClass $manifest
*/
$manifest = (object) array(
'definitions' => array(),
'fields' => array(),
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/misc/test_FrmAddon.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function test_checked_recently() {
*
* @param mixed $payload What the API request should come back with.
*
* @return \PHPUnit\Framework\MockObject\MockObject
* @return FrmTestAddon&\PHPUnit\Framework\MockObject\MockObject
*/
private function get_licensed_addon( $payload ) {
$addon = $this->getMockBuilder( 'FrmTestAddon' )
Expand Down
75 changes: 51 additions & 24 deletions tests/phpunit/phpunit-attributes-stubs.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,71 @@

declare(strict_types=1);

namespace PHPUnit\Framework\Attributes;

/**
* Attribute declarations for analysis jobs that do not install PHPUnit.
* PHPUnit declarations for analysis jobs that do not install PHPUnit.
*/
#[\Attribute( \Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE )]
class Group {
namespace PHPUnit\Framework\Attributes {

#[\Attribute( \Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE )]
class Group {

/**
* @param string $name The group name.
*/
public function __construct( $name ) {
}
}

#[\Attribute( \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE )]
class DataProvider {

/**
* @param string $methodName The static provider method name.
*/
public function __construct( $methodName ) {
}
}

#[\Attribute( \Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE )]
class CoversClass {

/**
* @param class-string $className The covered class name.
*/
public function __construct( $className ) {
}
}

/**
* @param string $name The group name.
* Marks tests whose target is outside the code coverage source directories.
*/
public function __construct( $name ) {
#[\Attribute( \Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD )]
class CoversNothing {
}
}

#[\Attribute( \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE )]
class DataProvider {

/**
* @param string $methodName The static provider method name.
* Runs a test, or every test in a class, in its own PHP process.
*/
public function __construct( $methodName ) {
#[\Attribute( \Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD )]
class RunInSeparateProcess {
}

#[\Attribute( \Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD )]
class PreserveGlobalState {

/**
* @param bool $enabled Whether the parent process globals are copied into the child process.
*/
public function __construct( $enabled ) {
}
}
}

#[\Attribute( \Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE )]
class CoversClass {
namespace PHPUnit\Framework {

/**
* @param class-string $className The covered class name.
* Thrown when an assertion fails.
*/
public function __construct( $className ) {
class ExpectationFailedException extends \Exception {
}
}

/**
* Marks tests whose target is outside the code coverage source directories.
*/
#[\Attribute( \Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD )]
class CoversNothing {
}
Loading