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

Start using WordPressCS 3.1 #171

Merged
merged 8 commits into from
Oct 1, 2024
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
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
"php": ">=5.6"
},
"require-dev": {
"wp-coding-standards/wpcs": "^2.3",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7",
"wp-coding-standards/wpcs": "^3.1",
"phpcompatibility/phpcompatibility-wp": "^2.1",
"yoast/phpunit-polyfills": "^1.0.1",
"phpunit/phpunit": "^5.7.21 || ^6.5 || ^7.5"
Expand Down
3 changes: 2 additions & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@
-->

<rule ref="WordPress-Core">
<exclude name="WordPress.PHP.StrictComparisons"/>
<exclude name="Universal.Operators.StrictComparisons"/>
<exclude name="WordPress.WP.I18n"/>
<exclude name="Modernize.FunctionCalls.Dirname.Nested"/><!-- Needs PHP 7.0 minimum. -->
</rule>
<rule ref="WordPress.Files.FileName">
<exclude-pattern>*/phpunit/tests/*\.php$</exclude-pattern>
Expand Down
4 changes: 2 additions & 2 deletions phpunit/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

define( 'WP_LOAD_IMPORTERS', true );

define( 'DIR_TESTDATA_WP_IMPORTER', dirname( __FILE__ ) . '/data' );
define( 'DIR_TESTDATA_WP_IMPORTER', __DIR__ . '/data' );

// Give access to tests_add_filter() function.
require_once $_tests_dir . '/includes/functions.php';
Expand All @@ -34,7 +34,7 @@
*/
function _manually_load_importer() {
if ( ! class_exists( 'WP_Import' ) ) {
require dirname( dirname( __FILE__ ) ) . '/src/wordpress-importer.php';
require dirname( __DIR__ ) . '/src/wordpress-importer.php';
}
}
tests_add_filter( 'plugins_loaded', '_manually_load_importer' );
Expand Down
2 changes: 1 addition & 1 deletion phpunit/tests/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected function _import_wp( $filename, $users = array(), $fetch_files = true
$new[ $i ] = $map;
}

$i++;
++$i;
}

$_POST = array(
Expand Down
6 changes: 3 additions & 3 deletions phpunit/tests/comment-meta.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

require_once dirname( __FILE__ ) . '/base.php';
require_once __DIR__ . '/base.php';

/**
* @group import
* @group comment-meta
*/
class Tests_Import_Comment_Meta extends WP_Import_UnitTestCase {
function set_up() {
public function set_up() {
parent::set_up();

if ( ! defined( 'WP_IMPORTING' ) ) {
Expand All @@ -19,7 +19,7 @@ function set_up() {
}
}

function test_serialized_comment_meta() {
public function test_serialized_comment_meta() {
$this->_import_wp( DIR_TESTDATA_WP_IMPORTER . '/test-serialized-comment-meta.xml', array( 'admin' => 'admin' ) );

$expected_string = '¯\_(ツ)_/¯';
Expand Down
10 changes: 5 additions & 5 deletions phpunit/tests/import.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

require_once dirname( __FILE__ ) . '/base.php';
require_once __DIR__ . '/base.php';

/**
* @group import
*/
class Tests_Import_Import extends WP_Import_UnitTestCase {
function set_up() {
public function set_up() {
parent::set_up();

if ( ! defined( 'WP_IMPORTING' ) ) {
Expand All @@ -27,13 +27,13 @@ function set_up() {
}
}

function tear_down() {
public function tear_down() {
remove_filter( 'import_allow_create_users', '__return_true' );

parent::tear_down();
}

function test_small_import() {
public function test_small_import() {
global $wpdb;

$authors = array(
Expand Down Expand Up @@ -201,7 +201,7 @@ function test_small_import() {
$this->assertCount( 1, $cats );
}

function test_double_import() {
public function test_double_import() {
$authors = array(
'admin' => false,
'editor' => false,
Expand Down
45 changes: 22 additions & 23 deletions phpunit/tests/parser.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

require_once dirname( __FILE__ ) . '/base.php';
require_once __DIR__ . '/base.php';

/**
* @group import
*/
class Tests_Import_Parser extends WP_Import_UnitTestCase {
function set_up() {
public function set_up() {
parent::set_up();

if ( ! defined( 'WP_IMPORTING' ) ) {
Expand All @@ -16,41 +16,40 @@ function set_up() {
if ( ! defined( 'WP_LOAD_IMPORTERS' ) ) {
define( 'WP_LOAD_IMPORTERS', true );
}

}

function test_malformed_wxr() {
public function test_malformed_wxr() {
$file = DIR_TESTDATA_WP_IMPORTER . '/malformed.xml';

// Regex based parser cannot detect malformed XML.
foreach ( array( 'WXR_Parser_SimpleXML', 'WXR_Parser_XML' ) as $p ) {
$parser = new $p;
$parser = new $p();
$result = $parser->parse( $file );
$this->assertWPError( $result );
$this->assertSame( 'There was an error when reading this WXR file', $result->get_error_message() );
}
}

function test_invalid_wxr() {
public function test_invalid_wxr() {
$f1 = DIR_TESTDATA_WP_IMPORTER . '/missing-version-tag.xml';
$f2 = DIR_TESTDATA_WP_IMPORTER . '/invalid-version-tag.xml';

foreach ( array( 'WXR_Parser_SimpleXML', 'WXR_Parser_XML', 'WXR_Parser_Regex' ) as $p ) {
foreach ( array( $f1, $f2 ) as $file ) {
$parser = new $p;
$parser = new $p();
$result = $parser->parse( $file );
$this->assertWPError( $result );
$this->assertSame( 'This does not appear to be a WXR file, missing/invalid WXR version number', $result->get_error_message() );
}
}
}

function test_wxr_version_1_1() {
public function test_wxr_version_1_1() {
$file = DIR_TESTDATA_WP_IMPORTER . '/valid-wxr-1.1.xml';

foreach ( array( 'WXR_Parser_SimpleXML', 'WXR_Parser_XML', 'WXR_Parser_Regex' ) as $p ) {
$message = $p . ' failed';
$parser = new $p;
$parser = new $p();
$result = $parser->parse( $file );

$this->assertIsArray( $result, $message );
Expand Down Expand Up @@ -138,12 +137,12 @@ function test_wxr_version_1_1() {
}
}

function test_wxr_version_1_0() {
public function test_wxr_version_1_0() {
$file = DIR_TESTDATA_WP_IMPORTER . '/valid-wxr-1.0.xml';

foreach ( array( 'WXR_Parser_SimpleXML', 'WXR_Parser_XML', 'WXR_Parser_Regex' ) as $p ) {
$message = $p . ' failed';
$parser = new $p;
$parser = new $p();
$result = $parser->parse( $file );

$this->assertIsArray( $result, $message );
Expand Down Expand Up @@ -227,12 +226,12 @@ function test_wxr_version_1_0() {
}

// Test that all parsers preserve blank lines in content
function test_blank_lines_in_content() {
public function test_blank_lines_in_content() {
$file = DIR_TESTDATA_WP_IMPORTER . '/post-content-blank-lines.xml';

foreach ( array( 'WXR_Parser_SimpleXML', 'WXR_Parser_XML', 'WXR_Parser_Regex' ) as $p ) {
$message = $p . ' failed and is missing blank lines';
$parser = new $p;
$parser = new $p();
$result = $parser->parse( $file );

// Check the number of new lines characters
Expand All @@ -241,12 +240,12 @@ function test_blank_lines_in_content() {
}

// Tests that each parser detects the same number of terms.
function test_varied_taxonomy_term_spacing() {
public function test_varied_taxonomy_term_spacing() {
$file = DIR_TESTDATA_WP_IMPORTER . '/term-formats.xml';

foreach ( array( 'WXR_Parser_SimpleXML', 'WXR_Parser_XML', 'WXR_Parser_Regex' ) as $p ) {
$message = $p . ' failed';
$parser = new $p;
$parser = new $p();
$result = $parser->parse( $file );

$this->assertIsArray( $result, $message );
Expand All @@ -269,12 +268,12 @@ function test_varied_taxonomy_term_spacing() {
*
* @link https://core.trac.wordpress.org/ticket/15203
*/
function test_escaped_cdata_closing_sequence() {
public function test_escaped_cdata_closing_sequence() {
$file = DIR_TESTDATA_WP_IMPORTER . '/crazy-cdata-escaped.xml';

foreach ( array( 'WXR_Parser_SimpleXML', 'WXR_Parser_XML', 'WXR_Parser_Regex' ) as $p ) {
$message = 'Parser ' . $p;
$parser = new $p;
$parser = new $p();
$result = $parser->parse( $file );

$post = $result['posts'][0];
Expand Down Expand Up @@ -302,10 +301,10 @@ function test_escaped_cdata_closing_sequence() {
* Ensure that the regex parser can still parse invalid CDATA blocks (i.e. those
* with "]]>" unescaped within a CDATA section).
*/
function test_unescaped_cdata_closing_sequence() {
public function test_unescaped_cdata_closing_sequence() {
$file = DIR_TESTDATA_WP_IMPORTER . '/crazy-cdata.xml';

$parser = new WXR_Parser_Regex;
$parser = new WXR_Parser_Regex();
$result = $parser->parse( $file );

$post = $result['posts'][0];
Expand All @@ -331,7 +330,7 @@ function test_unescaped_cdata_closing_sequence() {
/**
* @group term-meta
*/
function test_term_meta_parsing() {
public function test_term_meta_parsing() {
$file = DIR_TESTDATA_WP_IMPORTER . '/test-serialized-term-meta.xml';

$expected_meta = array(
Expand All @@ -347,7 +346,7 @@ function test_term_meta_parsing() {

foreach ( array( 'WXR_Parser_SimpleXML', 'WXR_Parser_XML', 'WXR_Parser_Regex' ) as $p ) {
$message = 'Parser ' . $p;
$parser = new $p;
$parser = new $p();
$result = $parser->parse( $file );

$this->assertCount( 1, $result['categories'], $message );
Expand All @@ -374,7 +373,7 @@ function test_term_meta_parsing() {
/**
* @group comment-meta
*/
function test_comment_meta_parsing() {
public function test_comment_meta_parsing() {
$file = DIR_TESTDATA_WP_IMPORTER . '/test-serialized-comment-meta.xml';

$expected_meta = array(
Expand All @@ -390,7 +389,7 @@ function test_comment_meta_parsing() {

foreach ( array( 'WXR_Parser_SimpleXML', 'WXR_Parser_XML', 'WXR_Parser_Regex' ) as $p ) {
$message = 'Parser ' . $p;
$parser = new $p;
$parser = new $p();
$result = $parser->parse( $file );

$this->assertCount( 1, $result['posts'], $message );
Expand Down
15 changes: 7 additions & 8 deletions phpunit/tests/postmeta.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

require_once dirname( __FILE__ ) . '/base.php';
require_once __DIR__ . '/base.php';

/**
* @group import
* @group post-meta
*/
class Tests_Import_Postmeta extends WP_Import_UnitTestCase {
function set_up() {
public function set_up() {
parent::set_up();

if ( ! defined( 'WP_IMPORTING' ) ) {
Expand All @@ -17,17 +17,16 @@ function set_up() {
if ( ! defined( 'WP_LOAD_IMPORTERS' ) ) {
define( 'WP_LOAD_IMPORTERS', true );
}

}

function test_serialized_postmeta_no_cdata() {
public function test_serialized_postmeta_no_cdata() {
$this->_import_wp( DIR_TESTDATA_WP_IMPORTER . '/test-serialized-postmeta-no-cdata.xml', array( 'johncoswell' => 'john' ) );
$expected['special_post_title'] = 'A special title';
$expected['is_calendar'] = '';
$this->assertSame( $expected, get_post_meta( 122, 'post-options', true ) );
}

function test_utw_postmeta() {
public function test_utw_postmeta() {
$this->_import_wp( DIR_TESTDATA_WP_IMPORTER . '/test-utw-post-meta-import.xml', array( 'johncoswell' => 'john' ) );

$classy = new StdClass();
Expand Down Expand Up @@ -76,7 +75,7 @@ function test_utw_postmeta() {
/**
* @ticket 9633
*/
function test_serialized_postmeta_with_cdata() {
public function test_serialized_postmeta_with_cdata() {
$this->_import_wp( DIR_TESTDATA_WP_IMPORTER . '/test-serialized-postmeta-with-cdata.xml', array( 'johncoswell' => 'johncoswell' ) );

// HTML in the CDATA should work with old WordPress version.
Expand All @@ -90,7 +89,7 @@ function test_serialized_postmeta_with_cdata() {
/**
* @ticket 11574
*/
function test_serialized_postmeta_with_evil_stuff_in_cdata() {
public function test_serialized_postmeta_with_evil_stuff_in_cdata() {
$this->_import_wp( DIR_TESTDATA_WP_IMPORTER . '/test-serialized-postmeta-with-cdata.xml', array( 'johncoswell' => 'johncoswell' ) );
// Evil content in the CDATA.
$this->assertSame( '<wp:meta_value>evil</wp:meta_value>', get_post_meta( 10, 'evil', true ) );
Expand All @@ -99,7 +98,7 @@ function test_serialized_postmeta_with_evil_stuff_in_cdata() {
/**
* @ticket 11574
*/
function test_serialized_postmeta_with_slashes() {
public function test_serialized_postmeta_with_slashes() {
$this->_import_wp( DIR_TESTDATA_WP_IMPORTER . '/test-serialized-postmeta-with-cdata.xml', array( 'johncoswell' => 'johncoswell' ) );

$expected_integer = '1';
Expand Down
6 changes: 3 additions & 3 deletions phpunit/tests/term-meta.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

require_once dirname( __FILE__ ) . '/base.php';
require_once __DIR__ . '/base.php';

/**
* @group import
* @group term-meta
*/
class Tests_Import_Term_Meta extends WP_Import_UnitTestCase {
function set_up() {
public function set_up() {
parent::set_up();

if ( ! defined( 'WP_IMPORTING' ) ) {
Expand All @@ -19,7 +19,7 @@ function set_up() {
}
}

function test_serialized_term_meta() {
public function test_serialized_term_meta() {
register_taxonomy( 'custom_taxonomy', array( 'post' ) );

$this->_import_wp( DIR_TESTDATA_WP_IMPORTER . '/test-serialized-term-meta.xml', array( 'admin' => 'admin' ) );
Expand Down
Loading