Skip to content

Commit

Permalink
Fix tests issues
Browse files Browse the repository at this point in the history
Fix array_map warnings
Exclude erroneous sniffs
Fix undefined constant
Fix functions signatures
Fix wp_styles not being initialized in some situations
  • Loading branch information
lithrel committed Dec 7, 2022
1 parent 88a725c commit 04d61d4
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion page.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
$context = Timber::get_context();
$post = new Post(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
$page_meta_data = get_post_meta( $post->ID );
$page_meta_data = array_map( 'reset', $page_meta_data );
reset( $page_meta_data );

// Ensure redirect is only performed if we're not already on a tag URL. Because tag.php includes this file.
if ( ! is_tag() && RedirectRedirectPages::is_active() ) {
Expand Down
7 changes: 7 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@
<exclude name="Generic.Arrays.DisallowShortArraySyntax"/>
</rule>

<!-- Disable erroneous and deprecated tests -->
<rule ref="WordPress.WP">
<exclude name="WordPress.WP.PostsPerPage.posts_per_page_numberposts"/>
<exclude name="WordPress.WP.PostsPerPage.posts_per_page_posts_per_page"/>
<exclude name="WordPress.WP.TimezoneChange"/>
</rule>

<!-- All files in src are classes so already have a required comment before the declaration. The rule also forced
to include an @package annotation, which is redundant if there is a namespace. -->
<rule ref="Squiz.Commenting.FileComment">
Expand Down
4 changes: 2 additions & 2 deletions single.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
// Articles block parameters to populate the articles block
// p4_take_action_page parameter to populate the take action boxout block
// Author override parameter. If this is set then the author profile section will not be displayed.
$page_meta_data = get_post_meta( $post->ID );
$page_meta_data = array_map( 'reset', $page_meta_data );
$page_meta_data = get_post_meta( $post->ID );
reset( $page_meta_data );
$page_terms_data = get_the_terms( $post, 'p4-page-type' );
$page_terms_data = is_array( $page_terms_data ) ? reset( $page_terms_data ) : null;
$context['background_image'] = $page_meta_data['p4_background_image_override'] ?? '';
Expand Down
4 changes: 2 additions & 2 deletions src/Settings/Features.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static function get_description(): string {
$description = 'Enable or disable specific Planet 4 features.';
$dev_flags = '<br>Options with the 👷 icon are only available in dev sites.';

$dev_site = in_array( WP_APP_ENV, [ 'local', 'development' ], true );
$dev_site = defined( 'WP_APP_ENV' ) && in_array( WP_APP_ENV, [ 'local', 'development' ], true );

return $dev_site
? $description . $dev_flags
Expand All @@ -78,7 +78,7 @@ public static function get_description(): string {
* @return array[] The fields for each feature.
*/
public static function get_fields(): array {
$include_all = in_array( WP_APP_ENV, [ 'local', 'development' ], true );
$include_all = defined( 'WP_APP_ENV' ) && in_array( WP_APP_ENV, [ 'local', 'development' ], true );

$features = $include_all
? self::all_features()
Expand Down
2 changes: 1 addition & 1 deletion src/Settings/InformationArchitecture.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static function get_description(): string {
$description = 'These options are related to the new <a href="https://jira.greenpeace.org/browse/PLANET-6467" target="_blank">Information architecture development</a>.';
$dev_flags = '<br>Options with the 👷 icon are only available in dev sites.';

$dev_site = in_array( WP_APP_ENV, [ 'local', 'development' ], true );
$dev_site = defined( 'WP_APP_ENV' ) && in_array( WP_APP_ENV, [ 'local', 'development' ], true );

return $dev_site
? $description . $dev_flags
Expand Down
2 changes: 1 addition & 1 deletion tests/p4-testcase.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class P4_TestCase extends WP_UnitTestCase {
/**
* Setup test
*/
public function setUp() {
public function setUp(): void {
parent::setUp();
$this->initialize_planet4_data();
require_once get_template_directory() . '/functions.php';
Expand Down
1 change: 1 addition & 0 deletions tests/test-category-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public function test_category_page_results() {
$this->assertFalse( is_404() );
$this->assertTrue( is_category() );

wp_styles();
$output = TimberHelper::ob_function(
function () {
include get_template_directory() . '/category.php';
Expand Down
2 changes: 2 additions & 0 deletions tests/test-open-graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function test_post_custom_open_graph_data( $post_data, $template ) {

\Timber\Timber::$context_cache = [];

wp_styles();
$output = TimberHelper::ob_function(
function () use ( $template ) {
include get_template_directory() . '/' . $template;
Expand Down Expand Up @@ -99,6 +100,7 @@ public function test_post_open_graph_data( $post_data, $template ) {

\Timber\Timber::$context_cache = [];

wp_styles();
$output = TimberHelper::ob_function(
function () use ( $template ) {
include get_template_directory() . '/' . $template;
Expand Down
4 changes: 2 additions & 2 deletions tests/test-p4-master-theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ class P4MasterThemeTest extends P4_TestCase {
/**
* Setup test
*/
public function setUp() { // phpcs:ignore
public function setUp(): void { // phpcs:ignore
parent::setUp();
}

/**
* Tear down
*/
public function tearDown() {
public function tearDown(): void {
switch_theme( 'planet4-master-theme' );
}

Expand Down

0 comments on commit 04d61d4

Please sign in to comment.