1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Automattic\Jetpack\Autoloader as Autoloader; |
4
|
|
|
use PHPUnit\Framework\TestCase; |
5
|
|
|
|
6
|
|
|
class WP_Test_File_Loader extends TestCase { |
7
|
|
|
static $jetpack_packages_files; |
8
|
|
|
function setup() { |
9
|
|
|
parent::setup(); |
10
|
|
|
global $jetpack_packages_files; |
11
|
|
|
self::$jetpack_packages_files = $jetpack_packages_files; |
12
|
|
|
$jetpack_packages_files = array(); |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
function tearDown() { |
16
|
|
|
parent::tearDown(); |
17
|
|
|
// re-apply the global |
18
|
|
|
global $jetpack_packages_files; |
19
|
|
|
$jetpack_packages_files = self::$jetpack_packages_files; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
View Code Duplication |
function test_enqueueing_adds_to_the_global_array() { |
23
|
|
|
Autoloader\enqueue_package_file( 'file_id_10', '1', 'path_to_file.php' ); |
24
|
|
|
|
25
|
|
|
global $jetpack_packages_files; |
26
|
|
|
$this->assertTrue( isset( $jetpack_packages_files['file_id_10'] ) ); |
27
|
|
|
$this->assertEquals( $jetpack_packages_files['file_id_10']['version'], '1' ); |
28
|
|
|
$this->assertEquals( $jetpack_packages_files['file_id_10']['path'], 'path_to_file.php' ); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
View Code Duplication |
function test_enqueueing_adds_the_latest_version_to_the_global_array() { |
32
|
|
|
Autoloader\enqueue_package_file( 'file_id', '1', 'path_to_file' ); |
33
|
|
|
Autoloader\enqueue_package_file( 'file_id', '2', 'path_to_file_v2' ); |
34
|
|
|
|
35
|
|
|
global $jetpack_packages_files; |
36
|
|
|
$this->assertTrue( isset( $jetpack_packages_files['file_id'] ) ); |
37
|
|
|
$this->assertEquals( $jetpack_packages_files['file_id']['version'], '2' ); |
38
|
|
|
$this->assertEquals( $jetpack_packages_files['file_id']['path'], 'path_to_file_v2' ); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
View Code Duplication |
function test_enqueueing_always_adds_the_dev_version_to_the_global_array() { |
42
|
|
|
|
43
|
|
|
Autoloader\enqueue_package_file( 'file_id', '1', 'path_to_file' ); |
44
|
|
|
Autoloader\enqueue_package_file( 'file_id', 'dev-howdy', 'path_to_file_dev' ); |
45
|
|
|
Autoloader\enqueue_package_file( 'file_id', '2', 'path_to_file_v2' ); |
46
|
|
|
|
47
|
|
|
global $jetpack_packages_files; |
48
|
|
|
$this->assertTrue( isset( $jetpack_packages_files['file_id'] ) ); |
49
|
|
|
$this->assertEquals( $jetpack_packages_files['file_id']['version'], 'dev-howdy' ); |
50
|
|
|
$this->assertEquals( $jetpack_packages_files['file_id']['path'], 'path_to_file_dev' ); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
function test_enqueued_file_is_actually_loaded() { |
54
|
|
|
|
55
|
|
|
Autoloader\enqueue_package_file( 'file_id', '1', __DIR__ . '/path_to_file.php' ); |
56
|
|
|
|
57
|
|
|
Autoloader\file_loader(); |
58
|
|
|
$this->assertTrue( function_exists( 'if_i_exist_then_this_test_passed' ) ); |
59
|
|
|
$this->assertTrue( if_i_exist_then_this_test_passed() ); |
60
|
|
|
|
61
|
|
|
Autoloader\enqueue_package_file( 'file_id', '2', __DIR__ . '/bogus_path_to_file.php' ); |
62
|
|
|
|
63
|
|
|
Autoloader\file_loader(); // file_loader should not include same file twice. |
64
|
|
|
|
65
|
|
|
$this->assertTrue( if_i_exist_then_this_test_passed() ); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|