1
|
|
|
<?php // phpcs:ignore WordPress.Files.FileName |
2
|
|
|
/** |
3
|
|
|
* Autoloader handler test suite. |
4
|
|
|
* |
5
|
|
|
* @package automattic/jetpack-autoloader |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Test suite class for the Autoloader handler. |
12
|
|
|
*/ |
13
|
|
|
class WP_Test_Autoloader_Handler extends TestCase { |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Tests that the latest autoloader can be recognized as the current. |
17
|
|
|
* |
18
|
|
|
* @runInSeparateProcess |
19
|
|
|
* @preserveGlobalState disabled |
20
|
|
|
*/ |
21
|
|
|
public function test_is_latest_autoloader_does_nothing_if_this_is_it() { |
22
|
|
|
$autoloader_handler = new Autoloader_Handler( |
23
|
|
|
TEST_DATA_PATH . '/plugins/plugin_current', |
24
|
|
|
array( TEST_DATA_PATH . '/plugins/plugin_current' ), |
25
|
|
|
new Autoloader_Locator( new Version_Selector() ), |
26
|
|
|
new Version_Selector() |
27
|
|
|
); |
28
|
|
|
|
29
|
|
|
$this->assertTrue( $autoloader_handler->is_latest_autoloader() ); |
30
|
|
|
|
31
|
|
|
global $jetpack_autoloader_latest_version; |
32
|
|
|
$this->assertEquals( '2.0.0.0', $jetpack_autoloader_latest_version ); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Tests that the latest autoloader will be required if not this. |
37
|
|
|
* |
38
|
|
|
* @runInSeparateProcess |
39
|
|
|
* @preserveGlobalState disabled |
40
|
|
|
*/ |
41
|
|
|
public function test_is_latest_autoloader_requires_latest_if_this_is_not_it() { |
42
|
|
|
$autoloader_handler = new Autoloader_Handler( |
43
|
|
|
TEST_DATA_PATH . '/plugins/plugin_current', |
44
|
|
|
array( |
45
|
|
|
TEST_DATA_PATH . '/plugins/plugin_current', |
46
|
|
|
TEST_DATA_PATH . '/plugins/plugin_newer', |
47
|
|
|
), |
48
|
|
|
new Autoloader_Locator( new Version_Selector() ), |
49
|
|
|
new Version_Selector() |
50
|
|
|
); |
51
|
|
|
|
52
|
|
|
$this->assertFalse( $autoloader_handler->is_latest_autoloader() ); |
53
|
|
|
|
54
|
|
|
global $jetpack_autoloader_latest_version; |
55
|
|
|
$this->assertEquals( '2.2.0.0', $jetpack_autoloader_latest_version ); |
56
|
|
|
$this->assertContains( TEST_DATA_PATH . '/plugins/plugin_newer/vendor/autoload_packages.php', get_included_files() ); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Tests should_autoloader_reset() with an already active plugin. |
61
|
|
|
*/ |
62
|
|
View Code Duplication |
public function test_should_autoloader_reset_known_plugin() { |
63
|
|
|
global $jetpack_autoloader_activating_plugins_paths; |
64
|
|
|
|
65
|
|
|
$autoloader_handler = new Autoloader_Handler( |
66
|
|
|
TEST_DATA_PATH . '/plugins/plugin_current', |
67
|
|
|
array( TEST_DATA_PATH . '/plugins/plugin_current' ), |
68
|
|
|
new Autoloader_Locator( new Version_Selector() ), |
69
|
|
|
new Version_Selector() |
70
|
|
|
); |
71
|
|
|
|
72
|
|
|
$this->assertFalse( $autoloader_handler->should_autoloader_reset() ); |
73
|
|
|
$this->assertEmpty( $jetpack_autoloader_activating_plugins_paths ); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Tests should_autoloader_reset() with an activating, unknown plugin. |
78
|
|
|
*/ |
79
|
|
View Code Duplication |
public function test_should_autoloader_reset_unknown_plugin() { |
80
|
|
|
global $jetpack_autoloader_activating_plugins_paths; |
81
|
|
|
|
82
|
|
|
$autoloader_handler = new Autoloader_Handler( |
83
|
|
|
TEST_DATA_PATH . '/plugins/plugin_current', |
84
|
|
|
array(), |
85
|
|
|
new Autoloader_Locator( new Version_Selector() ), |
86
|
|
|
new Version_Selector() |
87
|
|
|
); |
88
|
|
|
|
89
|
|
|
$this->assertTrue( $autoloader_handler->should_autoloader_reset() ); |
90
|
|
|
$this->assertCount( 1, $jetpack_autoloader_activating_plugins_paths ); |
91
|
|
|
$this->assertEquals( TEST_DATA_PATH . '/plugins/plugin_current', $jetpack_autoloader_activating_plugins_paths[0] ); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Tests that the handler is able to build a loader. |
96
|
|
|
*/ |
97
|
|
|
public function test_builds_autoloader() { |
98
|
|
|
$autoloader_handler = new Autoloader_Handler( |
99
|
|
|
TEST_DATA_PATH . '/plugins/plugin_current', |
100
|
|
|
array( TEST_DATA_PATH . '/plugins/plugin_current' ), |
101
|
|
|
new Autoloader_Locator( new Version_Selector() ), |
102
|
|
|
new Version_Selector() |
103
|
|
|
); |
104
|
|
|
|
105
|
|
|
$loader = $autoloader_handler->build_autoloader(); |
106
|
|
|
|
107
|
|
|
$file = $loader->find_class_file( \Automattic\Jetpack\Autoloader\AutoloadGenerator::class ); |
108
|
|
|
|
109
|
|
|
$this->assertFileExists( $file ); |
110
|
|
|
$this->assertContains( 'AutoloadGenerator.php', $file ); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|