Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Theme self tests #97

Merged
merged 17 commits into from
Dec 19, 2023
Merged
31 changes: 20 additions & 11 deletions _tests/QITSelfTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ class Context {
public static $action;
public static $suite;
public static $test;
public static $sut_slug;

/*
* To run tests in QIT, we need to assign the results to a plugin in the Marketplace.
* We use the extension "woocommerce-product-feeds" and theme "storefront", because their owned by the test user in Staging.
zhongruige marked this conversation as resolved.
Show resolved Hide resolved
*/
public static $extension_slug = 'woocommerce-product-feeds';
public static $theme_slug = 'wporg-theme-storefront';
}

Context::$action = $GLOBALS['argv'][1] ?? 'run';
Context::$suite = $GLOBALS['argv'][2] ?? null;
Context::$test = $GLOBALS['argv'][3] ?? null;

/*
* To run tests in QIT, we need to assign the results to a plugin in the Marketplace.
* We use "woocommerce-product-feeds", because it's a plugin owned by the test user in Staging.
*/
Context::$sut_slug = 'woocommerce-product-feeds';

require_once __DIR__ . '/test-result-parser.php';

try {
Expand Down Expand Up @@ -143,6 +143,13 @@ function generate_test_runs( array $test_types ): array {

foreach ( $woo_versions as $woo_version ) {
foreach ( $php_versions as $php_version ) {

if ( file_exists( $test . '/' . Context::$extension_slug ) ) {
$sut_slug = Context::$extension_slug;
} else {
$sut_slug = Context::$theme_slug;
}

$tests_to_run[ basename( $test_type ) ][] = [
'type' => basename( $test_type ),
'slug' => basename( $test ),
Expand All @@ -153,6 +160,7 @@ function generate_test_runs( array $test_types ): array {
'remove_from_snapshot' => $env['remove_from_snapshot'] ?? '',
'params' => $env['params'] ?? [],
'path' => $test,
'sut_slug' => $sut_slug,
];
}
}
Expand All @@ -176,8 +184,9 @@ function run_test_runs( array $test_runs ) {
// Dispatch all tests in parallel using the qit binary.
foreach ( $test_runs as $test_type => &$test_type_test_runs ) {
foreach ( $test_type_test_runs as $t ) {
$php = ( new PhpExecutableFinder() )->find( false );
$qit = realpath( __DIR__ . '/../qit' );
$php = ( new PhpExecutableFinder() )->find( false );
$qit = realpath( __DIR__ . '/../qit' );
$sut_slug = $t['sut_slug'];

$args = [
$php,
Expand Down Expand Up @@ -214,7 +223,7 @@ function run_test_runs( array $test_runs ) {
}
}

$args[] = Context::$sut_slug;
$args[] = $sut_slug;

$p = new Process( $args );
$p->setTimeout( null ); // Let QIT CLI handle timeouts.
Expand Down Expand Up @@ -384,7 +393,7 @@ function generate_zips( array $test_type_test_runs ) {
$processes = [];
foreach ( $test_type_test_runs as $t ) {
$path = $t['path'];
$slug = Context::$sut_slug;
$slug = $t['sut_slug'];

$args = [
"docker",
Expand Down
6 changes: 6 additions & 0 deletions _tests/activation/childtheme/env.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
return [
'php' => '8.2',
'wp' => 'stable',
'woo' => 'stable',
];
7 changes: 7 additions & 0 deletions _tests/activation/childtheme/wporg-theme-storefront/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
Theme Name: Storefront
Theme URI: https://woocommerce.com/products/storefront/
Description: Storefront Theme.
Template: twentytwentyfour
Version: 1.0.0
*/
6 changes: 6 additions & 0 deletions _tests/activation/parenttheme/env.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
return [
'php' => '8.2',
'wp' => 'stable',
'woo' => 'stable',
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
/**
* The main template file.
*
* This is the most generic template file in a WordPress theme
* and one of the two required files for a theme (the other being style.css).
* It is used to display a page when nothing more specific matches a query.
*/

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*
Theme Name: Storefront
Theme URI: https://woocommerce.com/products/storefront/
Description: Storefront Theme.
Version: 1.0.0
*/
6 changes: 6 additions & 0 deletions _tests/api/childtheme/env.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
return [
'php' => '8.2',
'wp' => 'stable',
'woo' => 'stable',
];
7 changes: 7 additions & 0 deletions _tests/api/childtheme/wporg-theme-storefront/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
Theme Name: Storefront
Theme URI: https://woocommerce.com/products/storefront/
Description: Storefront Theme.
Template: twentytwentyfour
Version: 1.0.0
*/
6 changes: 6 additions & 0 deletions _tests/api/parenttheme/env.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
return [
'php' => '8.2',
'wp' => 'stable',
'woo' => 'stable',
];
9 changes: 9 additions & 0 deletions _tests/api/parenttheme/wporg-theme-storefront/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
/**
* The main template file.
*
* This is the most generic template file in a WordPress theme
* and one of the two required files for a theme (the other being style.css).
* It is used to display a page when nothing more specific matches a query.
*/

6 changes: 6 additions & 0 deletions _tests/api/parenttheme/wporg-theme-storefront/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*
Theme Name: Storefront
Theme URI: https://woocommerce.com/products/storefront/
Description: Storefront Theme.
Version: 1.0.0
*/
6 changes: 6 additions & 0 deletions _tests/phpcompatibility/childtheme/env.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
return [
'params' => [
'--min_php_version' => '7.2',
],
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
Theme Name: Storefront
Theme URI: https://woocommerce.com/products/storefront/
Description: Storefront Theme.
Template: twentytwentyfour
Version: 1.0.0
*/
6 changes: 6 additions & 0 deletions _tests/phpcompatibility/parenttheme/env.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
return [
'params' => [
'--min_php_version' => '7.2',
],
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
/**
* The main template file.
*
* This is the most generic template file in a WordPress theme
* and one of the two required files for a theme (the other being style.css).
* It is used to display a page when nothing more specific matches a query.
*/

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*
Theme Name: Storefront
Theme URI: https://woocommerce.com/products/storefront/
Description: Storefront Theme.
Version: 1.0.0
*/
2 changes: 2 additions & 0 deletions _tests/phpstan/childtheme/env.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
return [];
7 changes: 7 additions & 0 deletions _tests/phpstan/childtheme/wporg-theme-storefront/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
Theme Name: Storefront
Theme URI: https://woocommerce.com/products/storefront/
Description: Storefront Theme.
Template: twentytwentyfour
Version: 1.0.0
*/
2 changes: 2 additions & 0 deletions _tests/phpstan/parenttheme/env.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
return [];
9 changes: 9 additions & 0 deletions _tests/phpstan/parenttheme/wporg-theme-storefront/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
/**
* The main template file.
*
* This is the most generic template file in a WordPress theme
* and one of the two required files for a theme (the other being style.css).
* It is used to display a page when nothing more specific matches a query.
*/

6 changes: 6 additions & 0 deletions _tests/phpstan/parenttheme/wporg-theme-storefront/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*
Theme Name: Storefront
Theme URI: https://woocommerce.com/products/storefront/
Description: Storefront Theme.
Version: 1.0.0
*/
2 changes: 2 additions & 0 deletions _tests/security/childtheme/env.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
return [];
7 changes: 7 additions & 0 deletions _tests/security/childtheme/wporg-theme-storefront/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
Theme Name: Storefront
Theme URI: https://woocommerce.com/products/storefront/
Description: Storefront Theme.
Template: twentytwentyfour
Version: 1.0.0
*/
2 changes: 2 additions & 0 deletions _tests/security/parenttheme/env.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
return [];
9 changes: 9 additions & 0 deletions _tests/security/parenttheme/wporg-theme-storefront/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
/**
* The main template file.
*
* This is the most generic template file in a WordPress theme
* and one of the two required files for a theme (the other being style.css).
* It is used to display a page when nothing more specific matches a query.
*/

6 changes: 6 additions & 0 deletions _tests/security/parenttheme/wporg-theme-storefront/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*
Theme Name: Storefront
Theme URI: https://woocommerce.com/products/storefront/
Description: Storefront Theme.
Version: 1.0.0
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php return '[
[
{
"run_id": 123456,
"test_type": "activation",
"wordpress_version": "6.0.0-normalized",
"woocommerce_version": "6.0.0-normalized",
"php_version": "8.2",
"max_php_version": "",
"min_php_version": "",
"additional_woo_plugins": [],
"additional_wp_plugins": [],
"test_log": "",
"status": "success",
"test_result_aws_url": "https:\\/\\/test-results-aws.com",
"test_result_aws_expiration": 1234567890,
"is_development": true,
"send_notifications": false,
"woo_extension": {
"id": 565154,
"host": "wporg",
"name": "Storefront",
"type": "theme"
},
"client": "qit_cli",
"event": "cli_development_extension_test",
"optional_features": {
"hpos": false,
"new_product_editor": false
},
"test_results_manager_url": "https:\\/\\/test-results-manager.com",
"test_results_manager_expiration": 1234567890,
"test_summary": "No errors detected.",
"debug_log": "",
"version": "Undefined",
"update_complete": true,
"ai_suggestion_status": "none",
"test_result_json_extracted": "{EXTRACTED}"
},
{
"test_result_json": []
}
]
]';
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"woo_extension": {
"id": 18619,
"host": "wccom",
"name": "Google Product Feed"
"name": "Google Product Feed",
"type": "extension"
},
"client": "qit_cli",
"event": "cli_development_extension_test",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"woo_extension": {
"id": 18619,
"host": "wccom",
"name": "Google Product Feed"
"name": "Google Product Feed",
"type": "extension"
},
"client": "qit_cli",
"event": "cli_development_extension_test",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"woo_extension": {
"id": 18619,
"host": "wccom",
"name": "Google Product Feed"
"name": "Google Product Feed",
"type": "extension"
},
"client": "qit_cli",
"event": "cli_development_extension_test",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"woo_extension": {
"id": 18619,
"host": "wccom",
"name": "Google Product Feed"
"name": "Google Product Feed",
"type": "extension"
},
"client": "qit_cli",
"event": "cli_development_extension_test",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php return '[
[
{
"run_id": 123456,
"test_type": "activation",
"wordpress_version": "6.0.0-normalized",
"woocommerce_version": "6.0.0-normalized",
"php_version": "8.2",
"max_php_version": "",
"min_php_version": "",
"additional_woo_plugins": [],
"additional_wp_plugins": [],
"test_log": "",
"status": "success",
"test_result_aws_url": "https:\\/\\/test-results-aws.com",
"test_result_aws_expiration": 1234567890,
"is_development": true,
"send_notifications": false,
"woo_extension": {
"id": 565154,
"host": "wporg",
"name": "Storefront",
"type": "theme"
},
"client": "qit_cli",
"event": "cli_development_extension_test",
"optional_features": {
"hpos": false,
"new_product_editor": false
},
"test_results_manager_url": "https:\\/\\/test-results-manager.com",
"test_results_manager_expiration": 1234567890,
"test_summary": "No errors detected.",
"debug_log": "",
"version": "Undefined",
"update_complete": true,
"ai_suggestion_status": "none",
"test_result_json_extracted": "{EXTRACTED}"
},
{
"test_result_json": []
}
]
]';
Loading