Completed
Push — try/find_latest_autoloader ( 807460...bfd3d2 )
by
unknown
12:05 queued 05:57
created

WP_Test_File_Loader::setup()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php // phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowerCase
2
/**
3
 * File loader test suite.
4
 *
5
 * @package automattic/jetpack-autoloader
6
 */
7
8
use PHPUnit\Framework\TestCase;
9
10
/**
11
 * Test suite class for the Autoloader part that handles file loading.
12
 */
13
class WP_Test_File_Loader extends TestCase {
14
15
	/**
16
	 * Tests whether enqueueing adds a file to the global array.
17
	 */
18 View Code Duplication
	public function test_enqueueing_adds_to_the_global_array() {
19
		enqueue_package_file( 'file_id_10', '1', 'path_to_file.php' );
20
21
		global $jetpack_packages_filemap;
22
		$this->assertTrue( isset( $jetpack_packages_filemap['file_id_10'] ) );
23
		$this->assertEquals( $jetpack_packages_filemap['file_id_10']['version'], '1' );
24
		$this->assertEquals( $jetpack_packages_filemap['file_id_10']['path'], 'path_to_file.php' );
25
	}
26
27
	/**
28
	 * Tests whether enqueueing adds the latest file version to the global array.
29
	 */
30 View Code Duplication
	public function test_enqueueing_adds_the_latest_version_to_the_global_array() {
31
		enqueue_package_file( 'file_id', '1', 'path_to_file' );
32
		enqueue_package_file( 'file_id', '2', 'path_to_file_v2' );
33
34
		global $jetpack_packages_filemap;
35
		$this->assertTrue( isset( $jetpack_packages_filemap['file_id'] ) );
36
		$this->assertEquals( $jetpack_packages_filemap['file_id']['version'], '2' );
37
		$this->assertEquals( $jetpack_packages_filemap['file_id']['path'], 'path_to_file_v2' );
38
	}
39
40
	/**
41
	 * Tests whether enqueueing prioritizes the dev version of the file.
42
	 */
43 View Code Duplication
	public function test_enqueueing_always_adds_the_dev_version_to_the_global_array() {
44
45
		enqueue_package_file( 'file_id', '1', 'path_to_file' );
46
		enqueue_package_file( 'file_id', 'dev-howdy', 'path_to_file_dev' );
47
		enqueue_package_file( 'file_id', '2', 'path_to_file_v2' );
48
49
		global $jetpack_packages_filemap;
50
		$this->assertTrue( isset( $jetpack_packages_filemap['file_id'] ) );
51
		$this->assertEquals( $jetpack_packages_filemap['file_id']['version'], 'dev-howdy' );
52
		$this->assertEquals( $jetpack_packages_filemap['file_id']['path'], 'path_to_file_dev' );
53
	}
54
55
	/**
56
	 * Tests whether enqueueing works with autoloading.
57
	 */
58
	public function test_enqueued_file_is_actually_loaded() {
59
60
		enqueue_package_file( 'file_id', '1', __DIR__ . '/path_to_file.php' );
61
62
		file_loader();
63
		$this->assertTrue( function_exists( 'if_i_exist_then_this_test_passed' ) );
64
		$this->assertTrue( if_i_exist_then_this_test_passed() );
65
66
		enqueue_package_file( 'file_id', '2', __DIR__ . '/bogus_path_to_file.php' );
67
68
		file_loader(); // file_loader should not include same file twice.
69
70
		$this->assertTrue( if_i_exist_then_this_test_passed() );
71
	}
72
}
73