Files
wordpress-develop/tests/phpunit/tests/admin/plugin-dependencies/hasUnmetDependencies.php
T
Colin Stewart 2b08a77f5c Upgrade/Install: Introduce Plugin Dependencies.
Introduces a new "Requires Plugins" plugin header so that plugin developers can list the slugs of the plugins theirs depends on.

This will inform users of the requirements, and provide links to the WordPress.org Plugins Repository that they can click to install and activate the dependencies first.

Plugins whose requirements are not met cannot be installed or activated, and they will be deactivated automatically if their requirements become unmet.
Plugins that others rely on cannot be deactivated or deleted until their dependent plugins are deactivated or deleted.

In memory of Alex Mills and Alex King.
WordPress Remembers.

Props ahoereth, afragen, alanfuller, alexkingorg, amykamala, anonymized_10690803, apeatling, ashfame, atimmer, audrasjb, aristath, azaozz, batmoo, beaulebens, blobaugh, bobbingwide, boonebgorges, brianhenryie, chanthaboune, chrisdavidmiles, coolmann, costdev, courane01, danielbachhuber, davidperez, dd32, Denis-de-Bernardy, dingo_d, DJPaul, dougal, DrewAPicture, ethitter, filosofo, georgestephanis, giuseppemazzapica-1, goldenapples, griffinjt, hellofromTonya, husobj, ideag, jarednova, jbobich, jbrinley, jltallon, joedolson, johnciacia, johnjamesjacoby, joppuyo, jsmoriss, karmatosed, kebbet, knutsp, kraftbj, kraftner, kurtpayne, lkraav, logikal16, luisherranz, man4toman, markjaquith, matt, mbijon, megphillips91, mikeschinkel, mordauk, morehawes, mrwweb, mte90, mukesh27, mzaweb, nacin, norcross, nvwd, nwjames, obliviousharmony, ocean90, oglekler, paaljoachim, pauldewouters, pbaylies, pbiron, peterwilsoncc, Philipp15b, poena, pogidude, retlehs, rmccue, ryan, sabreuse, sc0ttkclark, scribu, sereedmedia, SergeyBiryukov, ShaneF, shidouhikari, soean, spacedmonkey, stephenh1988, swissspidy, taylorde, tazotodua, threadi, TimothyBlynJacobs, TJNowell, tollmanz, toscho, tropicalista, Viper007Bond, westi, whiteshadow, williamsba1, wpsmith, ZaneMatthew.
Fixes #22316.

git-svn-id: https://develop.svn.wordpress.org/trunk@57545 602fd350-edb4-49c9-b593-d223f7449a82
2024-02-06 23:44:09 +00:00

147 lines
4.3 KiB
PHP

<?php
/**
* Tests for the WP_Plugin_Dependencies::has_unmet_dependencies() method.
*
* @package WordPress
*/
require_once __DIR__ . '/base.php';
/**
* @group admin
* @group plugins
*
* @covers WP_Plugin_Dependencies::has_unmet_dependencies
*/
class Tests_Admin_WPPluginDependencies_HasUnmetDependencies extends WP_PluginDependencies_UnitTestCase {
/**
* Tests that a plugin with no dependencies will return false.
*
* @ticket 22316
*/
public function test_should_return_false_when_a_plugin_has_no_dependencies() {
$this->set_property_value( 'dependencies', array( 'dependent/dependent.php' => array( 'dependency' ) ) );
$this->assertFalse( self::$instance::has_unmet_dependencies( 'dependent2/dependent2.php' ) );
}
/**
* Tests that a plugin whose dependencies are installed and active will return false.
*
* @ticket 22316
*/
public function test_should_return_false_when_a_plugin_has_no_unmet_dependencies() {
$this->set_property_value(
'dependencies',
array( 'dependent/dependent.php' => array( 'dependency' ) )
);
$this->set_property_value(
'dependency_filepaths',
array( 'dependency' => 'dependency/dependency.php' )
);
update_option( 'active_plugins', array( 'dependency/dependency.php' ) );
$this->assertFalse( self::$instance::has_unmet_dependencies( 'dependent/dependent.php' ) );
}
/**
* Tests that a plugin with a dependency that is not installed will return true.
*
* @ticket 22316
*/
public function test_should_return_true_when_a_plugin_has_a_dependency_that_is_not_installed() {
self::$instance::initialize();
$this->set_property_value(
'dependencies',
array( 'dependent/dependent.php' => array( 'dependency' ) )
);
$this->assertTrue( self::$instance::has_unmet_dependencies( 'dependent/dependent.php' ) );
}
/**
* Tests that a plugin with a dependency that is inactive will return true.
*
* @ticket 22316
*/
public function test_should_return_true_when_a_plugin_has_a_dependency_that_is_inactive() {
$this->set_property_value(
'dependencies',
array( 'dependent/dependent.php' => array( 'dependency' ) )
);
$this->set_property_value(
'dependency_filepaths',
array( 'dependency' => 'dependency/dependency.php' )
);
$this->assertTrue( self::$instance::has_unmet_dependencies( 'dependent/dependent.php' ) );
}
/**
* Tests that a plugin with one dependency that is active and one dependency that is inactive will return true.
*
* @ticket 22316
*/
public function test_should_return_true_when_a_plugin_has_one_active_dependency_and_one_inactive_dependency() {
$this->set_property_value(
'dependencies',
array( 'dependent/dependent.php' => array( 'dependency', 'dependency2' ) )
);
$this->set_property_value(
'dependency_filepaths',
array(
'dependency' => 'dependency/dependency.php',
'dependency2' => 'dependency2/dependency2.php',
)
);
update_option( 'active_plugins', array( 'dependency/dependency.php' ) );
$this->assertTrue( self::$instance::has_unmet_dependencies( 'dependent/dependent.php' ) );
}
/**
* Tests that a plugin with one dependency that is active and one dependency that is not installed will return true.
*
* @ticket 22316
*/
public function test_should_return_true_when_a_plugin_has_one_active_dependency_and_one_that_is_not_installed() {
$this->set_property_value(
'dependencies',
array( 'dependent/dependent.php' => array( 'dependency', 'dependency2' ) )
);
$this->set_property_value(
'dependency_filepaths',
array( 'dependency' => 'dependency/dependency.php' )
);
update_option( 'active_plugins', array( 'dependency/dependency.php' ) );
$this->assertTrue( self::$instance::has_unmet_dependencies( 'dependent/dependent.php' ) );
}
/**
* Tests that a plugin with one dependency that is inactive and one dependency that is not installed will return true.
*
* @ticket 22316
*/
public function test_should_return_true_when_a_plugin_has_one_inactive_dependency_and_one_that_is_not_installed() {
$this->set_property_value(
'dependencies',
array( 'dependent/dependent.php' => array( 'dependency', 'dependency2' ) )
);
$this->set_property_value(
'dependency_filepaths',
array( 'dependency' => 'dependency/dependency.php' )
);
$this->assertTrue( self::$instance::has_unmet_dependencies( 'dependent/dependent.php' ) );
}
}