| 1 |  |  | <?php // phpcs:ignore WordPress.Files.FileName | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * Integration test suite for the loader population. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @package automattic/jetpack-autoloader | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | // We live in the namespace of the test autoloader to avoid many use statements. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | namespace Automattic\Jetpack\Autoloader\jpCurrent; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Automattic\Jetpack\AutoloaderTesting\Current\UniqueTestClass; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use \Classmap_Test_Class; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use PHPUnit\Framework\TestCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Test_Plugin_Factory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * Test suite class for verifying that parsed manifests can be put into the loader and used. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | class VersionLoadingFromManifestTest extends TestCase { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | 	 * A manifest handler. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | 	 * @var Manifest_Reader | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 	private $manifest_handler; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 	 * Setup runs before each test. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 	 * @before | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 32 |  |  | 	 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  | 	public function set_up() { | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  | 		$this->manifest_handler = new Manifest_Reader( new Version_Selector() ); | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 	 * Tests that the classmap manifest from a single plugin can be handled correctly. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 40 |  | View Code Duplication | 	public function test_classmap() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 		$path_map = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 		$this->manifest_handler->read_manifests( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 			array( TEST_PLUGIN_DIR ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 			'vendor/composer/jetpack_autoload_classmap.php', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 			$path_map | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 		$loader = new Version_Loader( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 			new Version_Selector(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 			$path_map, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 			null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 			null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 		$file = $loader->find_class_file( Classmap_Test_Class::class ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 		$this->assertEquals( TEST_PLUGIN_DIR . '/includes/class-classmap-test-class.php', $file ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 	 * Tests that the PSR-4 manifest from a single plugin can be handled correctly. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 63 |  | View Code Duplication | 	public function test_psr4() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 		$path_map = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 		$this->manifest_handler->read_manifests( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 			array( TEST_PLUGIN_DIR ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 			'vendor/composer/jetpack_autoload_psr4.php', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 			$path_map | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 		$loader = new Version_Loader( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 			new Version_Selector(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 			null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 			$path_map, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 			null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 		$file = $loader->find_class_file( UniqueTestClass::class ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 		$this->assertEquals( TEST_PLUGIN_DIR . '/src/Current/UniqueTestClass.php', $file ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 	 * Tests that the filemap manifest from a single plugin can be handled correctly. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 	 * @preserveGlobalState disabled | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 	 * @runInSeparateProcess | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 89 |  | View Code Duplication | 	public function test_filemap() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 		$path_map = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 		$this->manifest_handler->read_manifests( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 			array( TEST_PLUGIN_DIR ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 			'vendor/composer/jetpack_autoload_filemap.php', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 			$path_map | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  | 		$loader = new Version_Loader( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 			new Version_Selector(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  | 			null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  | 			null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  | 			$path_map | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | 		$loader->load_filemap(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  | 		global $jetpack_autoloader_testing_loaded_files; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  | 		$this->assertContains( Test_Plugin_Factory::VERSION_CURRENT, $jetpack_autoloader_testing_loaded_files ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 109 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 110 |  |  |  |