Skip to content

Commit

Permalink
Update plugins, update tests (#173)
Browse files Browse the repository at this point in the history
* Update plugins, update tests

* Update github workflow file to remove unmaintained workflow reference

* Update github actions checkout to latest version

* Update composer.json with latest format
  • Loading branch information
mchanDev authored Aug 18, 2023
1 parent 8e15d3b commit a471648
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 29 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/cs-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@ jobs:
uses: korelstar/xmllint-problem-matcher@v1

- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3

# Validate the composer.json file.
# @link https://getcomposer.org/doc/03-cli.md#validate
- name: Validate Composer installation
run: composer validate --no-check-all

# Install dependencies and handle caching in one go.
# @link https://github.com/marketplace/actions/install-composer-dependencies
- name: Install Composer dependencies
uses: ramsey/composer-install@v1

# @link https://github.com/marketplace/actions/install-php-dependencies-with-composer
- name: Install PHP Dependencies with Composer
uses: ramsey/[email protected]
# Lint PHP.

- name: Lint PHP against parse errors
run: composer lint-ci | cs2pr

Expand Down
4 changes: 2 additions & 2 deletions bin/install-wp-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ install_test_suite() {
# set up testing suite
mkdir -p $WP_TESTS_DIR
rm -rf $WP_TESTS_DIR/{includes,data}
svn export --quiet --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
svn export --quiet --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data
svn export --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
svn export --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data
fi

if [ ! -f wp-tests-config.php ]; then
Expand Down
12 changes: 9 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
},
"require-dev": {
"automattic/vipwpcs": "^2.2",
"dealerdirect/phpcodesniffer-composer-installer": "^0.4.1 || ^0.5 || ^0.6.2 || ^0.7",
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
"php-parallel-lint/php-parallel-lint": "^1.0",
"phpcompatibility/phpcompatibility-wp": "^2.1",
"phpunit/phpunit": "^4 || ^5 || ^6 || ^7",
"phpunit/phpunit": "^9",
"squizlabs/php_codesniffer": "^3.5",
"wp-coding-standards/wpcs": "^2.3.0",
"yoast/phpunit-polyfills": "^0.2.0"
"yoast/phpunit-polyfills": "^2.0"
},
"scripts": {
"coverage": [
Expand Down Expand Up @@ -57,5 +57,11 @@
"support": {
"issues": "https://github.com/Automattic/msm-sitemap/issues",
"source": "https://github.com/Automattic/msm-sitemap"
},
"config": {
"allow-plugins": {
"composer/installers": true,
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
6 changes: 3 additions & 3 deletions tests/test-sitemap--cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class WP_Test_Sitemap_Cron extends WP_UnitTestCase {
/**
* Generate posts and build the sitemap
*/
function setup() {
function setup(): void {
if ( ! class_exists( 'MSM_Sitemap_Builder_Cron' ) ) {
require dirname( dirname( __FILE__ ) ) . '/includes/msm-sitemap-builder-cron.php';
MSM_Sitemap_Builder_Cron::setup();
Expand All @@ -55,7 +55,7 @@ function setup() {
/**
* Remove the sample posts and the sitemap posts
*/
function teardown() {
function teardown(): void {
$this->test_base->posts = array();
$sitemaps = get_posts( array(
'post_type' => Metro_Sitemap::SITEMAP_CPT,
Expand Down Expand Up @@ -98,7 +98,7 @@ function test_cron_jobs_scheduling() {
$years_being_processed = (array) get_option( 'msm_years_to_process', array() );

// Validate Current Month is added to months_to_process.
$month = date( 'n', time() );
$month = (int) date( 'n', time() );
$this->assertContains( $month, $months_being_processed, 'Initial Year Processing should use Current Month if same year' );

// fake_cron.
Expand Down
6 changes: 3 additions & 3 deletions tests/test-sitemap-cpt.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class WP_Test_Sitemap_CPT extends WP_UnitTestCase {
/**
* Initialize Test CPT
*/
static function setupBeforeClass() {
static function setupBeforeClass(): void {
register_post_type(
self::TEST_CPT,
array(
Expand All @@ -55,7 +55,7 @@ static function setupBeforeClass() {
/**
* Initialize MSM_SiteMap_Test
*/
function setup() {
function setup(): void {

$this->test_base = new MSM_SiteMap_Test();

Expand Down Expand Up @@ -88,7 +88,7 @@ function setup() {
/**
* Remove the sample posts and the sitemap posts
*/
function teardown() {
function teardown(): void {
$this->test_base->posts = array();
$sitemaps = get_posts( array(
'post_type' => Metro_Sitemap::SITEMAP_CPT,
Expand Down
8 changes: 4 additions & 4 deletions tests/test-sitemap-creation.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class WP_Test_Sitemap_Creation extends WP_UnitTestCase {
/**
* Generate posts and build the sitemap
*/
function setup() {
function setup(): void {

$this->test_base = new MSM_SiteMap_Test();

Expand All @@ -52,7 +52,7 @@ function setup() {
/**
* Remove the sample posts and the sitemap posts
*/
function teardown() {
function teardown(): void {
$this->test_base->posts = array();
$sitemaps = get_posts( array(
'post_type' => Metro_Sitemap::SITEMAP_CPT,
Expand Down Expand Up @@ -81,15 +81,15 @@ function test_sitemap_posts_were_created() {
foreach ( $sitemaps as $i => $map_id ) {
$xml = get_post_meta( $map_id, 'msm_sitemap_xml', true );
$post_id = $this->test_base->posts[ $i ]['ID'];
$this->assertContains( 'p=' . $post_id, $xml );
$this->assertStringContainsString( 'p=' . $post_id, $xml );

$xml_struct = simplexml_load_string( $xml );
$this->assertNotEmpty( $xml_struct->url );
$this->assertNotEmpty( $xml_struct->url->loc );
$this->assertNotEmpty( $xml_struct->url->lastmod );
$this->assertNotEmpty( $xml_struct->url->changefreq );
$this->assertNotEmpty( $xml_struct->url->priority );
$this->assertContains( 'p=' . $post_id, (string) $xml_struct->url->loc );
$this->assertStringContainsString( 'p=' . $post_id, (string) $xml_struct->url->loc );

$post = get_post( $post_id );
setup_postdata( $post );
Expand Down
2 changes: 1 addition & 1 deletion tests/test-sitemap-filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function test_bypass_main_query() {
// Verify post_pre_query on sitemap queryvar returns empty array
set_query_var( 'sitemap', 'true' );
$posts = apply_filters_ref_array( 'posts_pre_query', array( null, $wp_query ) );
$this->assertInternalType('array', $posts);
$this->assertIsArray( $posts );
$this->assertEmpty( $posts );

}
Expand Down
8 changes: 4 additions & 4 deletions tests/test-sitemap-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ class WP_Test_Sitemap_Functions extends WP_UnitTestCase {
/**
* Initialize MSM_SiteMap_Test
*/
function setup() {
function setup(): void {
$this->test_base = new MSM_SiteMap_Test();

}

/**
* Remove the sample posts and the sitemap posts
*/
function teardown() {
function teardown(): void {
$this->test_base->posts = array();
$sitemaps = get_posts( array(
'post_type' => Metro_Sitemap::SITEMAP_CPT,
Expand Down Expand Up @@ -141,12 +141,12 @@ function test_check_year_has_posts() {
// Add a post for last year and 5 years ago.
$date = strtotime( '-1 year', time() );
$cur_day = date( 'Y', $date ) . '-' . date( 'm', $date ) . '-' . date( 'd', $date ) . ' 00:00:00';
$prev_year = date( 'Y', $date );
$prev_year = (int) date( 'Y', $date );
$this->test_base->create_dummy_post( $cur_day );

$date = strtotime( '-4 year', $date );
$cur_day = date( 'Y', $date ) . '-' . date( 'm', $date ) . '-' . date( 'd', $date ) . ' 00:00:00';
$prev5_year = date( 'Y', $date );
$prev5_year = (int) date( 'Y', $date );
$this->test_base->create_dummy_post( $cur_day );

// Verify only Years for Posts are returned.
Expand Down
4 changes: 2 additions & 2 deletions tests/test-sitemap-index.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class WP_Test_Sitemap_Index extends WP_UnitTestCase {
/**
* Generate posts and build initial sitemaps
*/
function setup() {
function setup(): void {
_delete_all_posts();

$this->test_base = new MSM_SiteMap_Test();
Expand All @@ -54,7 +54,7 @@ function setup() {
/**
* Remove created posts, sitemaps and options
*/
function teardown() {
function teardown(): void {
$this->test_base->posts = array();
$sitemaps = get_posts( array(
'post_type' => Metro_Sitemap::SITEMAP_CPT,
Expand Down
4 changes: 2 additions & 2 deletions tests/test-sitemap-stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class WP_Test_Sitemap_Stats extends WP_UnitTestCase {
/**
* Generate posts and build initial sitemaps
*/
function setup() {
function setup(): void {
_delete_all_posts();

$this->test_base = new MSM_SiteMap_Test();
Expand All @@ -55,7 +55,7 @@ function setup() {
/**
* Remove created posts, Sitemaps and options
*/
function teardown() {
function teardown(): void {
$this->test_base->posts = array();
$sitemaps = get_posts( array(
'post_type' => Metro_Sitemap::SITEMAP_CPT,
Expand Down

0 comments on commit a471648

Please sign in to comment.