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

Fix path in CLI output #615

Open
wants to merge 8 commits into
base: trunk
Choose a base branch
from
Open
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
14 changes: 11 additions & 3 deletions includes/Checker/Abstract_Check_Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,8 @@ private function get_check_exclude_slugs() {
* @since 1.0.0
*
* @return string The plugin basename to check.
*
* @throws Exception Thrown if an plugin basename could not be set.
*/
final public function get_plugin_basename() {
if ( null === $this->plugin_basename ) {
Expand All @@ -550,10 +552,16 @@ final public function get_plugin_basename() {
$this->plugin_basename = Plugin_Request_Utility::download_plugin( $plugin );

$this->delete_plugin_folder = true;
} elseif ( Plugin_Request_Utility::is_directory_valid_plugin( $plugin ) ) {
$this->plugin_basename = $plugin;
} else {
$this->plugin_basename = Plugin_Request_Utility::get_plugin_basename_from_input( $plugin );
try {
$this->plugin_basename = Plugin_Request_Utility::get_plugin_basename_from_input( $plugin );
} catch ( Exception $exception ) {
if ( Plugin_Request_Utility::is_directory_valid_plugin( $plugin ) ) {
$this->plugin_basename = $plugin;
} else {
throw $exception;
}
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions includes/Plugin_Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
}
}
}

$this->main_file = $this->main_file;
Comment on lines +70 to +71
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debugging leftover?

}

/**
Expand Down Expand Up @@ -101,9 +103,9 @@
*/
public function path( $relative_path = '/' ) {
if ( is_dir( $this->main_file ) ) {
return trailingslashit( $this->main_file ) . ltrim( $relative_path, '/' );
return realpath( trailingslashit( $this->main_file ) . ltrim( $relative_path, '/' ) ) . '/';

Check warning on line 106 in includes/Plugin_Context.php

View check run for this annotation

Codecov / codecov/patch

includes/Plugin_Context.php#L106

Added line #L106 was not covered by tests
} else {
return plugin_dir_path( $this->main_file ) . ltrim( $relative_path, '/' );
return realpath( plugin_dir_path( $this->main_file ) . ltrim( $relative_path, '/' ) ) . '/';
}
}

Expand Down
4 changes: 4 additions & 0 deletions tests/behat/features/plugin-check-remote.feature
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ Feature: Test that the WP-CLI plugin check command works with remote ZIP url.
Scenario: Test with valid ZIP
When I run the WP-CLI command `plugin check https://github.com/WordPress/plugin-check/raw/trunk/tests/behat/testdata/foo-bar-wp.zip --fields=code,type --format=csv`
Then STDOUT should contain:
"""
FILE: foo-bar-wp.php
"""
And STDOUT should contain:
"""
WordPress.WP.AlternativeFunctions.rand_mt_rand,ERROR
"""
Expand Down
4 changes: 4 additions & 0 deletions tests/behat/features/plugin-check-severity.feature
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ Feature: Test that the severity level in plugin check works.

When I run the WP-CLI command `plugin check foo-bar-wp --format=csv --fields=code,type,severity`
Then STDOUT should contain:
"""
FILE: foo-bar-wp.php
"""
And STDOUT should contain:
"""
allow_unfiltered_uploads_detected,ERROR,7
"""
Expand Down
16 changes: 16 additions & 0 deletions tests/phpunit/testdata/plugins/test-plugin/test-plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* Plugin Name: Test Plugin
* Plugin URI: https://github.com/WordPress/plugin-check
* Description: Some plugin description.
* Requires at least: 6.0
* Requires PHP: 5.6
* Version: 1.0.0
* Author: WordPress Performance Team
* Author URI: https://make.wordpress.org/performance/
* License: GPLv2 or later
* License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* Text Domain: test-plugin
*
* @package test-plugin
*/
4 changes: 2 additions & 2 deletions tests/phpunit/tests/Checker/Check_Context_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ public function test_path() {
}

public function test_path_with_parameter() {
$this->assertSame( WP_PLUGIN_DIR . '/' . $this->plugin_name . '/another/folder', $this->check_context->path( '/another/folder' ) );
$this->assertSame( WP_PLUGIN_DIR . '/' . $this->plugin_name . '/test-content/themes', $this->check_context->path( '/test-content/themes' ) );
}

public function test_url() {
$this->assertSame( WP_PLUGIN_URL . '/' . $this->plugin_name . '/', $this->check_context->url() );
}

public function test_url_with_parameter() {
$this->assertSame( WP_PLUGIN_URL . '/' . $this->plugin_name . '/folder/file.css', $this->check_context->url( '/folder/file.css' ) );
$this->assertSame( WP_PLUGIN_URL . '/' . $this->plugin_name . '/assets/js/plugin-check-admin.js', $this->check_context->url( '/assets/js/plugin-check-admin.js' ) );
}
}
12 changes: 6 additions & 6 deletions tests/phpunit/tests/Checker/Check_Result_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Check_Result_Tests extends WP_UnitTestCase {
public function set_up() {
parent::set_up();

$check_context = new Check_Context( 'test-plugin/test-plugin.php' );
$check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin/test-plugin.php' );

$this->check_result = new Check_Result( $check_context );
}
Expand All @@ -28,7 +28,7 @@ public function test_plugin() {
$this->assertInstanceOf( Check_Context::class, $this->check_result->plugin() );

// Check the Check_Context has the correct basename.
$this->assertSame( 'test-plugin/test-plugin.php', $this->check_result->plugin()->basename() );
$this->assertStringEndsWith( 'test-plugin/test-plugin.php', $this->check_result->plugin()->basename() );
}

public function test_add_message_with_warning() {
Expand All @@ -37,7 +37,7 @@ public function test_add_message_with_warning() {
'Warning message',
array(
'code' => 'test_warning',
'file' => 'test-plugin/test-plugin.php',
'file' => UNIT_TESTS_PLUGIN_DIR . 'test-plugin/test-plugin.php',
'line' => 12,
'column' => 40,
)
Expand Down Expand Up @@ -73,7 +73,7 @@ public function test_add_message_with_error() {
'Error message',
array(
'code' => 'test_error',
'file' => 'test-plugin/test-plugin.php',
'file' => UNIT_TESTS_PLUGIN_DIR . 'test-plugin/test-plugin.php',
'line' => 22,
'column' => 30,
)
Expand Down Expand Up @@ -113,7 +113,7 @@ public function test_get_errors_with_errors() {
'Error message',
array(
'code' => 'test_error',
'file' => 'test-plugin/test-plugin.php',
'file' => UNIT_TESTS_PLUGIN_DIR . 'test-plugin/test-plugin.php',
'line' => 22,
'column' => 30,
)
Expand Down Expand Up @@ -146,7 +146,7 @@ public function test_get_warnings_with_warnings() {
'Warning message',
array(
'code' => 'test_warning',
'file' => 'test-plugin/test-plugin.php',
'file' => UNIT_TESTS_PLUGIN_DIR . 'test-plugin/test-plugin.php',
'line' => 22,
'column' => 30,
)
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/tests/Plugin_Context_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ public function test_path() {
}

public function test_path_with_parameter() {
$this->assertSame( WP_PLUGIN_DIR . '/' . $this->plugin_name . '/another/folder', $this->plugin_context->path( '/another/folder' ) );
$this->assertSame( WP_PLUGIN_DIR . '/' . $this->plugin_name . '/test-content/themes', $this->plugin_context->path( '/test-content/themes' ) );
}

public function test_url() {
$this->assertSame( WP_PLUGIN_URL . '/' . $this->plugin_name . '/', $this->plugin_context->url() );
}

public function test_url_with_parameter() {
$this->assertSame( WP_PLUGIN_URL . '/' . $this->plugin_name . '/folder/file.css', $this->plugin_context->url( '/folder/file.css' ) );
$this->assertSame( WP_PLUGIN_URL . '/' . $this->plugin_name . '/assets/js/plugin-check-admin.js', $this->plugin_context->url( '/assets/js/plugin-check-admin.js' ) );
}

public function test_location() {
Expand Down
Loading