|
5 | 5 | use Codeception\Lib\Di;
|
6 | 6 | use Codeception\Lib\ModuleContainer;
|
7 | 7 | use Codeception\Test\Unit;
|
8 |
| -use lucatume\WPBrowser\Module\WPLoader; |
9 | 8 | use lucatume\WPBrowser\Tests\Traits\DatabaseAssertions;
|
10 | 9 | use lucatume\WPBrowser\Tests\Traits\LoopIsolation;
|
11 | 10 | use lucatume\WPBrowser\Tests\Traits\MainInstallationAccess;
|
@@ -56,6 +55,72 @@ private function module(array $moduleContainerConfig = [], ?array $moduleConfig
|
56 | 55 | return new WPLoader($this->mockModuleContainer, ($moduleConfig ?? $this->config));
|
57 | 56 | }
|
58 | 57 |
|
| 58 | + public function test_loads_plugins_from_default_location_correctly(): void |
| 59 | + { |
| 60 | + $projectDir = FS::tmpDir('wploader_'); |
| 61 | + $installation = Installation::scaffold($projectDir); |
| 62 | + $dbName = Random::dbName(); |
| 63 | + $dbHost = Env::get('WORDPRESS_DB_HOST'); |
| 64 | + $dbUser = Env::get('WORDPRESS_DB_USER'); |
| 65 | + $dbPassword = Env::get('WORDPRESS_DB_PASSWORD'); |
| 66 | + $installationDb = new MysqlDatabase($dbName, $dbUser, $dbPassword, $dbHost, 'wp_'); |
| 67 | + if (!mkdir($projectDir . '/wp-content/plugins/test-one', 0777, true)) { |
| 68 | + throw new \RuntimeException('Unable to create test directory for plugin test-one'); |
| 69 | + } |
| 70 | + if (!file_put_contents( |
| 71 | + $projectDir . '/wp-content/plugins/test-one/plugin.php', |
| 72 | + <<< PHP |
| 73 | +<?php |
| 74 | +/** |
| 75 | + * Plugin Name: Test One |
| 76 | + */ |
| 77 | + |
| 78 | + function test_one_loaded(){} |
| 79 | +PHP |
| 80 | + )) { |
| 81 | + throw new \RuntimeException('Unable to create test plugin file for plugin test-one'); |
| 82 | + } |
| 83 | + if (!mkdir($projectDir . '/wp-content/plugins/test-two', 0777, true)) { |
| 84 | + throw new \RuntimeException('Unable to create test directory for plugin test-two'); |
| 85 | + } |
| 86 | + if (!file_put_contents( |
| 87 | + $projectDir . '/wp-content/plugins/test-two/plugin.php', |
| 88 | + <<< PHP |
| 89 | +<?php |
| 90 | +/** |
| 91 | + * Plugin Name: Test Two |
| 92 | + */ |
| 93 | + |
| 94 | + function test_two_loaded(){} |
| 95 | +PHP |
| 96 | + )) { |
| 97 | + throw new \RuntimeException('Unable to create test plugin file for plugin test-two'); |
| 98 | + } |
| 99 | + |
| 100 | + $this->config = [ |
| 101 | + 'wpRootFolder' => $projectDir, |
| 102 | + 'dbUrl' => $installationDb->getDbUrl(), |
| 103 | + 'tablePrefix' => 'test_', |
| 104 | + 'plugins' => [ |
| 105 | + 'test-one/plugin.php', |
| 106 | + 'test-two/plugin.php', |
| 107 | + ] |
| 108 | + ]; |
| 109 | + $wpLoader = $this->module(); |
| 110 | + $projectDirname = basename($projectDir); |
| 111 | + |
| 112 | + $this->assertInIsolation( |
| 113 | + static function () use ($wpLoader, $projectDir) { |
| 114 | + chdir($projectDir); |
| 115 | + |
| 116 | + $wpLoader->_initialize(); |
| 117 | + |
| 118 | + Assert::assertTrue(function_exists('test_one_loaded')); |
| 119 | + Assert::assertTrue(function_exists('test_two_loaded')); |
| 120 | + } |
| 121 | + ); |
| 122 | + } |
| 123 | + |
59 | 124 | /**
|
60 | 125 | * It should allow loading a plugin from an arbitrary path
|
61 | 126 | *
|
|
0 commit comments