Skip to content

Commit

Permalink
Merge pull request #1029 from alleyinteractive/hotfix/testkit-fixes
Browse files Browse the repository at this point in the history
Fix: Get Unit tests passing for 2.4.1
  • Loading branch information
attackant authored Nov 15, 2023
2 parents 72a7739 + ed6869f commit d3fa1af
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 14 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/node-tests.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
name: Node Tests

on:
workflow_dispatch:
push:
branches:
- develop
- release/*
pull_request:
types: [ opened, synchronize, reopened, ready_for_review ]
branches:
- develop
- release/*

jobs:
node-tests:
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/phpcs.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
name: PHP Coding Standards

on:
workflow_dispatch:
push:
branches:
- develop
- release/*
pull_request:
types: [ opened, synchronize, reopened, ready_for_review ]
branches:
- develop
- release/*

jobs:
phpcs:
Expand Down
11 changes: 8 additions & 3 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
name: Testing Suite

on:
workflow_dispatch:
push:
branches:
- develop
- release/*
pull_request:
types: [ opened, synchronize, reopened, ready_for_review ]
branches:
- develop
- release/*

jobs:
php-tests:
strategy:
matrix:
multisite: [0, 1]
multisite: [true, false]
php: ['8.2', '8.1', '8.0']
wordpress: ["latest"]
if: github.event.pull_request.draft == false
uses: alleyinteractive/.github/.github/workflows/php-tests.yml@main
with:
command: "test"
command: "phpunit"
multisite: ${{ matrix.multisite }}
php: ${{ matrix.php }}
wordpress: ${{ matrix.wordpress }}
6 changes: 4 additions & 2 deletions admin/class-admin-apple-meta-boxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ public function do_publish( $post_id, $post ) {
return;
}

// Check the nonce.
check_admin_referer( self::PUBLISH_ACTION, 'apple_news_nonce' );
// Check the nonce if we're not in testing mode.
if ( ! defined( 'MANTLE_IS_TESTING' ) || ! MANTLE_IS_TESTING ) {
check_admin_referer( self::PUBLISH_ACTION, 'apple_news_nonce' );
}

// Save meta box fields.
self::save_post_meta( $post_id );
Expand Down
2 changes: 1 addition & 1 deletion includes/class-apple-news.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Apple_News {
* @var string
* @access public
*/
public static $version = '2.4.0';
public static $version = '2.4.1';

/**
* Link to support for the plugin on WordPress.org.
Expand Down
13 changes: 12 additions & 1 deletion tests/apple-push-api/test-class-mime-builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@
*/
class Apple_News_MIME_Builder_Test extends Apple_News_Testcase {

/**
* Sets up the test case.
*/
public function setUp(): void {
parent::setUp();

apple_news_require_file( dirname( __DIR__, 2 ) . '/includes/apple-push-api/request/class-request.php' );
}

/**
* Tests the behavior of adding JSON to the MIME builder.
*/
Expand Down Expand Up @@ -47,7 +56,9 @@ public function test_invalid_json() {
$filename = 'article.json';
$json = '';

$this->setExpectedException( 'Apple_Push_API\\Request\\Request_Exception', 'The attachment article.json could not be included in the request because it was empty.' );
$this->expectException( \Apple_Push_API\Request\Request_Exception::class );
$this->expectExceptionMessage( 'The attachment article.json could not be included in the request because it was empty.' );

$builder->add_json_string( $name, $filename, $json );
}
}
5 changes: 1 addition & 4 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

/* phpcs:disable WordPressVIPMinimum.Files.IncludingFile.UsingVariable */

const WP_TESTS_PHPUNIT_POLYFILLS_PATH = __DIR__ . '/../vendor/yoast/phpunit-polyfills'; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound

const WP_TESTS_MULTISITE = 1; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound
/**
* Includes a PHP file if it exists.
*
Expand Down Expand Up @@ -38,7 +35,7 @@ function apple_news_require_file( string $file ) {
function () {
// Disable VIP cache manager when testing against VIP Go integration.
if ( method_exists( 'WPCOM_VIP_Cache_Manager', 'instance' ) ) {
remove_action( 'init', [ WPCOM_VIP_Cache_Manager::instance(), 'init' ] );
remove_action( 'init', [ WPCOM_VIP_Cache_Manager::instance(), 'init' ] );
}

// Set the permalink structure and domain options.
Expand Down
4 changes: 3 additions & 1 deletion tests/class-apple-news-testcase.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,9 @@ protected function add_http_response(
'body' => $body,
'cookies' => $cookies,
'filename' => $filename,
'headers' => new Requests_Utility_CaseInsensitiveDictionary( $headers ),
'headers' => class_exists( \WpOrg\Requests\Utility\CaseInsensitiveDictionary::class )
? new \WpOrg\Requests\Utility\CaseInsensitiveDictionary( $headers )
: new Requests_Utility_CaseInsensitiveDictionary( $headers ),
'response' => $response,
] : null;
}
Expand Down

0 comments on commit d3fa1af

Please sign in to comment.