| @@ 19-33 (lines=15) @@ | ||
| 16 | /** |
|
| 17 | * Tests that the autoloader works properly in the standard case. |
|
| 18 | */ |
|
| 19 | public function test_autoloader_as_active_plugin() { |
|
| 20 | // Activate the current autoloader so it won't be unknown. |
|
| 21 | $this->activate_autoloader( Test_Plugin_Factory::CURRENT ); |
|
| 22 | ||
| 23 | // Load and shutdown the autoloader safely. |
|
| 24 | $this->load_plugin_autoloader( Test_Plugin_Factory::CURRENT ); |
|
| 25 | $this->trigger_shutdown( true ); |
|
| 26 | ||
| 27 | // Make sure the autoloader worked as expected. |
|
| 28 | $this->assertAutoloaderVersion( Test_Plugin_Factory::CURRENT ); |
|
| 29 | $this->assertAutoloaderResetCount( 0 ); |
|
| 30 | $this->assertAutoloaderNotFoundUnknown( Test_Plugin_Factory::CURRENT ); |
|
| 31 | $this->assertAutoloaderCacheEquals( Test_Plugin_Factory::CURRENT ); |
|
| 32 | $this->assertAutoloaderProvidesClass( \Automattic\Jetpack\AutoloaderTesting\Current\UniqueTestClass::class ); |
|
| 33 | } |
|
| 34 | ||
| 35 | /** |
|
| 36 | * Tests that the autoloader works properly as an mu-plugin. |
|
| @@ 38-59 (lines=22) @@ | ||
| 35 | /** |
|
| 36 | * Tests that the autoloader does not write the cache when the active plugins have not changed. |
|
| 37 | */ |
|
| 38 | public function test_autoloader_does_not_write_unchanged_cache() { |
|
| 39 | // Cache the plugin so that the cache is unchanged. |
|
| 40 | $this->cache_plugin( Test_Plugin_Factory::CURRENT ); |
|
| 41 | ||
| 42 | // Load the autoloader. |
|
| 43 | $this->load_plugin_autoloader( Test_Plugin_Factory::CURRENT ); |
|
| 44 | ||
| 45 | // We're going to erase the cache before we shut the autoloader down. |
|
| 46 | // Since the cache is only loaded when the autoloader is, we can |
|
| 47 | // do this to detect whether or not the cache is updated. |
|
| 48 | $this->erase_cache(); |
|
| 49 | ||
| 50 | // Trigger the shutdown now and it should NOT update the cache. |
|
| 51 | $this->trigger_shutdown( true ); |
|
| 52 | ||
| 53 | // Make sure the autoloader worked as expected. |
|
| 54 | $this->assertAutoloaderVersion( Test_Plugin_Factory::CURRENT ); |
|
| 55 | $this->assertAutoloaderResetCount( 0 ); |
|
| 56 | $this->assertAutoloaderFoundUnknown( Test_Plugin_Factory::CURRENT ); |
|
| 57 | $this->assertAutoloaderCacheEmpty(); |
|
| 58 | $this->assertAutoloaderProvidesClass( \Automattic\Jetpack\AutoloaderTesting\Current\UniqueTestClass::class ); |
|
| 59 | } |
|
| 60 | ||
| 61 | /** |
|
| 62 | * Tests that the autoloader does not reset when it encounters unknown plugins that are in the cache already. |
|