Skip to content

Commit 2065a93

Browse files
authored
Test update
1 parent 2023705 commit 2065a93

File tree

6 files changed

+136
-0
lines changed

6 files changed

+136
-0
lines changed

.github/workflows/integration-test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ jobs:
3232
php_version: ${{ matrix.php-version }}
3333
wordpress_version: ${{ matrix.wordpress-version }}
3434
plugin_slug: 'simple-wp-optimizer'
35+
phpunit_config: 'phpunit.xml'
3536

3637
- name: Add labels to any PRs
3738
if: github.event_name == 'pull_request'

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
- Fixed action parameters using the correct input names: php_version, wordpress_version, plugin_slug
1818
- Added automated PR labeling with "automated", "documentation", and "plugin update" tags
1919
- Set up proper GitHub permissions for integration test workflow
20+
- Created test infrastructure with PHPUnit Polyfills for cross-version compatibility
21+
- Added basic plugin loading tests and WordPress environment configuration
2022

2123
## [1.5.4] - 2025-05-04
2224
### Changed

phpunit.xml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0"?>
2+
<phpunit
3+
bootstrap="tests/bootstrap.php"
4+
backupGlobals="false"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
>
10+
<testsuites>
11+
<testsuite name="Simple WP Optimizer Tests">
12+
<directory prefix="test-" suffix=".php">./tests/</directory>
13+
</testsuite>
14+
</testsuites>
15+
<coverage>
16+
<include>
17+
<directory suffix=".php">./</directory>
18+
</include>
19+
<exclude>
20+
<directory>./tests</directory>
21+
<directory>./vendor</directory>
22+
</exclude>
23+
</coverage>
24+
<php>
25+
<env name="WP_PHPUNIT__TESTS_CONFIG" value="tests/wp-config.php" />
26+
</php>
27+
</phpunit>

tests/bootstrap.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
* PHPUnit bootstrap file.
4+
*
5+
* @package Simple_WP_Optimizer
6+
*/
7+
8+
// Load the Composer autoloader.
9+
require_once dirname( __DIR__ ) . '/vendor/autoload.php';
10+
11+
// Load the PHPUnit Polyfills for cross-version compatibility.
12+
require_once dirname( __DIR__ ) . '/vendor/yoast/phpunit-polyfills/phpunitpolyfills-autoload.php';
13+
14+
// Make sure the tests directory is in the include path.
15+
if ( ! defined( 'WP_CONTENT_DIR' ) ) {
16+
define( 'WP_CONTENT_DIR', dirname( __DIR__ ) . '/tests/wp-content' );
17+
}
18+
19+
if ( ! defined( 'WP_PLUGIN_DIR' ) ) {
20+
define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' );
21+
}
22+
23+
// Define a test plugin directory name.
24+
if ( ! defined( 'TEST_PLUGIN_DIR' ) ) {
25+
define( 'TEST_PLUGIN_DIR', dirname( __DIR__ ) );
26+
}
27+
28+
// Manually load the plugin being tested.
29+
function _manually_load_plugin() {
30+
require dirname( __DIR__ ) . '/simple-wp-optimizer.php';
31+
}
32+
33+
// Start up the WP testing environment.
34+
// Ideally, this would be automatically handled by the integration test action.
35+
// If WP_TESTS_DIR is defined, we'll use it, otherwise we'll set up a basic mock.
36+
if ( defined( 'WP_TESTS_DIR' ) && file_exists( WP_TESTS_DIR . '/includes/bootstrap.php' ) ) {
37+
require WP_TESTS_DIR . '/includes/bootstrap.php';
38+
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
39+
} else {
40+
// Simple mock class if WP test suite isn't available
41+
class WP_UnitTestCase extends \Yoast\PHPUnitPolyfills\TestCases\TestCase {
42+
// Include test helper methods here
43+
}
44+
}

tests/test-plugin-loading.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* Basic integration test for Simple WP Optimizer
4+
*
5+
* @package Simple_WP_Optimizer
6+
*/
7+
8+
/**
9+
* Class Test_Simple_WP_Optimizer
10+
*/
11+
class Test_Simple_WP_Optimizer extends WP_UnitTestCase {
12+
13+
/**
14+
* Test that the plugin can be loaded correctly.
15+
*/
16+
public function test_plugin_loads() {
17+
// Check if the plugin main class or function exists
18+
$this->assertTrue(function_exists('simple_wp_optimizer_init') || class_exists('Simple_WP_Optimizer'),
19+
'Plugin does not appear to be loaded correctly');
20+
}
21+
22+
/**
23+
* A basic test ensuring that the WordPress version is set.
24+
*/
25+
public function test_wp_version() {
26+
$this->assertTrue(defined('ABSPATH'), 'WordPress not loaded properly');
27+
// Use assertNotEmpty to accommodate PHPUnit versions (polyfill handles compatibility)
28+
$this->assertNotEmpty(get_bloginfo('version'), 'WordPress version not available');
29+
}
30+
}

tests/wp-config.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
* WordPress test environment configuration.
4+
*
5+
* @package Simple_WP_Optimizer
6+
*/
7+
8+
// Test with WordPress debug mode on
9+
define( 'WP_DEBUG', true );
10+
11+
// Database settings - will be overridden by the test framework
12+
define( 'DB_NAME', 'wordpress_test' );
13+
define( 'DB_USER', 'root' );
14+
define( 'DB_PASSWORD', '' );
15+
define( 'DB_HOST', 'localhost' );
16+
define( 'DB_CHARSET', 'utf8' );
17+
define( 'DB_COLLATE', '' );
18+
19+
$table_prefix = 'wptests_';
20+
21+
define( 'WP_TESTS_DOMAIN', 'example.org' );
22+
define( 'WP_TESTS_EMAIL', '[email protected]' );
23+
define( 'WP_TESTS_TITLE', 'Test Blog' );
24+
25+
define( 'WP_PHP_BINARY', 'php' );
26+
27+
// For integration testing
28+
define( 'WPLANG', '' );
29+
define( 'WP_CONTENT_DIR', dirname( __DIR__ ) . '/wp-content' );
30+
31+
// Prevent filesystem operations in tests
32+
define( 'FS_METHOD', 'direct' );

0 commit comments

Comments
 (0)