Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@
* @package WordPress
*/

namespace WordPress\Tests\Admin\PluginDependencies;

use WP_Plugin_Dependencies;
use WP_PluginDependencies_UnitTestCase;

require_once __DIR__ . '/base.php';

/**
* @group admin
* @group plugins
*
* @covers WP_Plugin_Dependencies::get_dependencies
* @covers \WP_Plugin_Dependencies::get_dependencies
*/
class Tests_Admin_WPPluginDependencies_GetDependencies extends WP_PluginDependencies_UnitTestCase {
class GetDependenciesTest extends WP_PluginDependencies_UnitTestCase {

/**
* Tests that a plugin with no dependencies will return an empty array.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@
* @package WordPress
*/

namespace WordPress\Tests\Admin\PluginDependencies;

use WP_Plugin_Dependencies;
use WP_PluginDependencies_UnitTestCase;

require_once __DIR__ . '/base.php';

/**
* @group admin
* @group plugins
*
* @covers WP_Plugin_Dependencies::get_dependency_data
* @covers WP_Plugin_Dependencies::get_dependency_api_data
* @covers \WP_Plugin_Dependencies::get_dependency_data
* @covers \WP_Plugin_Dependencies::get_dependency_api_data
*/
class Tests_Admin_WPPluginDependencies_GetDependencyData extends WP_PluginDependencies_UnitTestCase {
class GetDependencyDataTest extends WP_PluginDependencies_UnitTestCase {

/**
* Tests that dependency data is retrieved.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,22 @@
* @package WordPress
*/

namespace WordPress\Tests\Admin\PluginDependencies;

use WP_Plugin_Dependencies;
use WP_PluginDependencies_UnitTestCase;

require_once __DIR__ . '/base.php';

/**
* @group admin
* @group plugins
*
* @covers WP_Plugin_Dependencies::get_dependency_filepath
* @covers WP_Plugin_Dependencies::get_dependency_filepaths
* @covers WP_Plugin_Dependencies::get_plugin_dirnames
* @covers \WP_Plugin_Dependencies::get_dependency_filepath
* @covers \WP_Plugin_Dependencies::get_dependency_filepaths
* @covers \WP_Plugin_Dependencies::get_plugin_dirnames
*/
class Tests_Admin_WPPluginDependencies_GetDependencyFilepath extends WP_PluginDependencies_UnitTestCase {
class GetDependencyFilepathTest extends WP_PluginDependencies_UnitTestCase {

/**
* Tests that false is returned if Plugin Dependencies has not been initialized.
Expand Down Expand Up @@ -50,7 +55,7 @@ public function test_should_return_false_before_initialization() {
*
* @param string[] $dependency_slug The dependency slug.
* @param string[] $plugins An array of plugin paths.
* @param string|false $expected The expected result.
* @param string|false $expected The expected result.
*/
public function test_should_return_filepaths_for_installed_dependencies( $dependency_slug, $plugins, $expected ) {
$this->set_property_value( 'plugins', $plugins );
Expand Down Expand Up @@ -85,28 +90,28 @@ public function data_get_dependency_filepath() {
'expected' => false,
),
'a plugin that ends with slug/' => array(
'dependency_slugs' => 'dependency',
'plugins' => array(
'dependency_slug' => 'dependency',
'plugins' => array(
'addon-for-dependency/dependency.php' => array( 'RequiresPlugins' => '' ),
'dependent/dependent.php' => array( 'RequiresPlugins' => 'dependency' ),
),
'expected' => false,
'expected' => false,
),
'a plugin that does not exist' => array(
'dependency_slugs' => 'dependency2',
'plugins' => array(
'dependency_slug' => 'dependency2',
'plugins' => array(
'dependency/dependency.php' => array( 'RequiresPlugins' => '' ),
'dependent/dependent.php' => array( 'RequiresPlugins' => 'dependency2' ),
),
'expected' => false,
'expected' => false,
),
'a plugin that exists' => array(
'dependency_slugs' => 'dependency',
'plugins' => array(
'dependency_slug' => 'dependency',
'plugins' => array(
'dependency/dependency.php' => array( 'RequiresPlugins' => '' ),
'dependent/dependent.php' => array( 'RequiresPlugins' => 'dependency' ),
),
'expected' => 'dependency/dependency.php',
'expected' => 'dependency/dependency.php',
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,24 @@
* @package WordPress
*/

namespace WordPress\Tests\Admin\PluginDependencies;

use WP_Error;
use WP_Plugin_Dependencies;
use WP_PluginDependencies_UnitTestCase;

require_once __DIR__ . '/base.php';

/**
* @group admin
* @group plugins
*
* @covers WP_Plugin_Dependencies::get_dependency_names
* @covers WP_Plugin_Dependencies::get_dependency_api_data
* @covers WP_Plugin_Dependencies::get_dependencies
* @covers WP_Plugin_Dependencies::get_dependency_filepaths
* @covers \WP_Plugin_Dependencies::get_dependency_names
* @covers \WP_Plugin_Dependencies::get_dependency_api_data
* @covers \WP_Plugin_Dependencies::get_dependencies
* @covers \WP_Plugin_Dependencies::get_dependency_filepaths
*/
class Tests_Admin_WPPluginDependencies_GetDependencyNames extends WP_PluginDependencies_UnitTestCase {
class GetDependencyNamesTest extends WP_PluginDependencies_UnitTestCase {

/**
* Mocks an API response.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@
* @package WordPress
*/

namespace WordPress\Tests\Admin\PluginDependencies;

use WP_Plugin_Dependencies;
use WP_PluginDependencies_UnitTestCase;

require_once __DIR__ . '/base.php';

/**
* @group admin
* @group plugins
*
* @covers WP_Plugin_Dependencies::get_dependent_filepath
* @covers WP_Plugin_Dependencies::get_plugin_dirnames
* @covers \WP_Plugin_Dependencies::get_dependent_filepath
* @covers \WP_Plugin_Dependencies::get_plugin_dirnames
*/
class Tests_Admin_WPPluginDependencies_GetDependentFilepath extends WP_PluginDependencies_UnitTestCase {
class GetDependentFilepathTest extends WP_PluginDependencies_UnitTestCase {

/**
* Tests that the expected dependent filepath is retrieved.
Expand All @@ -24,7 +29,7 @@ class Tests_Admin_WPPluginDependencies_GetDependentFilepath extends WP_PluginDep
* @dataProvider data_get_dependent_filepath
*
* @param string $dependent_slug The dependent slug.
* @param string[] $plugins An array of plugin data.
* @param array $plugins An array of plugin data.
* @param string|false $expected The expected result.
*/
public function test_should_return_filepaths_for_installed_dependents( $dependent_slug, $plugins, $expected ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,23 @@
* @package WordPress
*/

namespace WordPress\Tests\Admin\PluginDependencies;

use WP_Plugin_Dependencies;
use WP_PluginDependencies_UnitTestCase;

require_once __DIR__ . '/base.php';

/**
* @group admin
* @group plugins
*
* @covers WP_Plugin_Dependencies::get_dependent_names
* @covers WP_Plugin_Dependencies::get_plugins
* @covers WP_Plugin_Dependencies::convert_to_slug
* @covers WP_Plugin_Dependencies::get_dependents
* @covers \WP_Plugin_Dependencies::get_dependent_names
* @covers \WP_Plugin_Dependencies::get_plugins
* @covers \WP_Plugin_Dependencies::convert_to_slug
* @covers \WP_Plugin_Dependencies::get_dependents
*/
class Tests_Admin_WPPluginDependencies_GetDependentNames extends WP_PluginDependencies_UnitTestCase {
class GetDependentNamesTest extends WP_PluginDependencies_UnitTestCase {

/**
* Tests that dependent names are retrieved.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@
* @package WordPress
*/

namespace WordPress\Tests\Admin\PluginDependencies;

use WP_Plugin_Dependencies;
use WP_PluginDependencies_UnitTestCase;

require_once __DIR__ . '/base.php';

/**
* @group admin
* @group plugins
*
* @covers WP_Plugin_Dependencies::get_dependents
* @covers \WP_Plugin_Dependencies::get_dependents
*/
class Tests_Admin_WPPluginDependencies_GetDependents extends WP_PluginDependencies_UnitTestCase {
class GetDependentsTest extends WP_PluginDependencies_UnitTestCase {

/**
* Tests that a plugin with no dependents will return an empty array.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?php
/**
* Tests for the WP_Plugin_Dependencies::has_active_dependents() method.
*
* @package WordPress
*/

namespace WordPress\Tests\Admin\PluginDependencies;

use WP_Plugin_Dependencies;
use WP_PluginDependencies_UnitTestCase;

require_once __DIR__ . '/base.php';

/**
* @group admin
* @group plugins
*
* @covers \WP_Plugin_Dependencies::has_active_dependents
*/
class HasActiveDependentsTest extends WP_PluginDependencies_UnitTestCase {

/**
* Tests whether a plugin has active dependents.
*
* @ticket 22316
*
* @dataProvider data_has_active_dependents
*
* @param array $dependencies An array of plugin dependencies.
* @param array $active_plugins An array of active plugins.
* @param string $plugin_to_check The plugin to check.
* @param bool $expected The expected result.
*/
public function test_has_active_dependents( $dependencies, $active_plugins, $plugin_to_check, $expected ) {
$this->set_property_value( 'dependencies', $dependencies );

if ( ! empty( $active_plugins ) ) {
update_option( 'active_plugins', $active_plugins );
}

$this->assertSame( $expected, self::$instance::has_active_dependents( $plugin_to_check ) );
}

/**
* Data provider for test_has_active_dependents.
*
* @return array[]
*/
public function data_has_active_dependents() {
return array(
'no dependents for plugin' => array(

Check warning on line 52 in tests/phpunit/tests/admin/plugin-dependencies/HasActiveDependentsTest.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Array double arrow not aligned correctly; expected 14 space(s) between "'no dependents for plugin'" and double arrow, but found 1.
'dependencies' => array( 'dependent/dependent.php' => array( 'dependency' ) ),
'active_plugins' => array( 'dependent/dependent.php' ),
'plugin_to_check' => 'dependency2/dependency2.php',
'expected' => false,
),
'active dependent exists' => array(

Check warning on line 58 in tests/phpunit/tests/admin/plugin-dependencies/HasActiveDependentsTest.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Array double arrow not aligned correctly; expected 15 space(s) between "'active dependent exists'" and double arrow, but found 1.
'dependencies' => array( 'dependent/dependent.php' => array( 'dependency' ) ),
'active_plugins' => array( 'dependent/dependent.php' ),
'plugin_to_check' => 'dependency/dependency.php',
'expected' => true,
),
'one inactive and one active dependent' => array(
'dependencies' => array(
'dependent2/dependent2.php' => array( 'dependency' ),
'dependent/dependent.php' => array( 'dependency' ),
),
'active_plugins' => array( 'dependent/dependent.php' ),
'plugin_to_check' => 'dependency/dependency.php',
'expected' => true,
),
'one active and one inactive dependent' => array(
'dependencies' => array(
'dependent/dependent.php' => array( 'dependency' ),
'dependent2/dependent2.php' => array( 'dependency' ),
),
'active_plugins' => array( 'dependent/dependent.php' ),
'plugin_to_check' => 'dependency/dependency.php',
'expected' => true,
),
'earlier plugin has active dependents, checking earlier plugin' => array(
'dependencies' => array(
'dependent/dependent.php' => array( 'dependency' ),
'dependent2/dependent2.php' => array( 'dependency2' ),
),
'active_plugins' => array( 'dependent/dependent.php' ),
'plugin_to_check' => 'dependency/dependency.php',
'expected' => true,
),
'later plugin has active dependents, checking later plugin' => array(
'dependencies' => array(
'dependent/dependent.php' => array( 'dependency' ),
'dependent2/dependent2.php' => array( 'dependency2' ),
),
'active_plugins' => array( 'dependent2/dependent2.php' ),
'plugin_to_check' => 'dependency2/dependency2.php',
'expected' => true,
),
'dependent is inactive' => array(

Check warning on line 100 in tests/phpunit/tests/admin/plugin-dependencies/HasActiveDependentsTest.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Array double arrow not aligned correctly; expected 17 space(s) between "'dependent is inactive'" and double arrow, but found 1.
'dependencies' => array( 'dependent/dependent.php' => array( 'dependency' ) ),
'active_plugins' => array(),
'plugin_to_check' => 'dependency/dependency.php',
'expected' => false,
),
'earlier plugin has no active dependents, checking earlier plugin' => array(
'dependencies' => array(
'dependent/dependent.php' => array( 'dependency' ),
'dependent2/dependent2.php' => array( 'dependency2' ),
),
'active_plugins' => array( 'dependent2/dependent2.php' ),
'plugin_to_check' => 'dependency/dependency.php',
'expected' => false,
),
'later plugin has no active dependents, checking later plugin' => array(
'dependencies' => array(
'dependent/dependent.php' => array( 'dependency' ),
'dependent2/dependent2.php' => array( 'dependency2' ),
),
'active_plugins' => array( 'dependent/dependent.php' ),
'plugin_to_check' => 'dependency2/dependency2.php',
'expected' => false,
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,22 @@
* @package WordPress
*/

namespace WordPress\Tests\Admin\PluginDependencies;

use WP_Plugin_Dependencies;
use WP_PluginDependencies_UnitTestCase;

require_once __DIR__ . '/base.php';

/**
* @group admin
* @group plugins
*
* @covers WP_Plugin_Dependencies::has_circular_dependency
* @covers WP_Plugin_Dependencies::get_circular_dependencies
* @covers WP_Plugin_Dependencies::check_for_circular_dependencies
* @covers \WP_Plugin_Dependencies::has_circular_dependency
* @covers \WP_Plugin_Dependencies::get_circular_dependencies
* @covers \WP_Plugin_Dependencies::check_for_circular_dependencies
*/
class Tests_Admin_WPPluginDependencies_HasCircularDependency extends WP_PluginDependencies_UnitTestCase {
class HasCircularDependencyTest extends WP_PluginDependencies_UnitTestCase {

/**
* Tests that false is returned if Plugin Dependencies has not been initialized.
Expand Down
Loading
Loading