-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
4 changed files
with
80 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1873,4 +1873,59 @@ function plugin_2_canary() {} | |
Assert::assertEquals('theme-1', wp_get_theme()->get_stylesheet()); | ||
}); | ||
} | ||
|
||
public function differentDbNamesProvider(): array | ||
{ | ||
return [ | ||
'with dashes, underscores and dots' => ['test-db_db.db'], | ||
'only words and numbers' => ['testdb1234567890'], | ||
'all together' => ['test-db_db.db1234567890'], | ||
'mydatabase.dev' => ['mydatabase.dev'], | ||
'my_dbname_n8h96prxar4r' => ['my_dbname_n8h96prxar4r'], | ||
'!funny~db-name' => ['!funny~db-name'], | ||
]; | ||
} | ||
|
||
/** | ||
* It should correctly load with different database names | ||
* | ||
* @test | ||
* @dataProvider differentDbNamesProvider | ||
*/ | ||
public function should_correctly_load_with_different_database_names(string $dbName): void | ||
{ | ||
$wpRootDir = FS::tmpDir('wploader_'); | ||
$installation = Installation::scaffold($wpRootDir); | ||
$dbHost = Env::get('WORDPRESS_DB_HOST'); | ||
$dbUser = Env::get('WORDPRESS_DB_USER'); | ||
$dbPassword = Env::get('WORDPRESS_DB_PASSWORD'); | ||
$db = new MysqlDatabase($dbName, $dbUser, $dbPassword, $dbHost, 'test_'); | ||
$db->drop(); | ||
$installation->configure($db); | ||
$installation->install( | ||
'https://wp.local', | ||
'admin', | ||
'password', | ||
'[email protected]', | ||
'Test' | ||
); | ||
|
||
$this->config = [ | ||
'wpRootFolder' => $wpRootDir, | ||
'dbUrl' => $db->getDbUrl() | ||
]; | ||
$wpLoader = $this->module(); | ||
|
||
$this->assertEquals( | ||
$db->getDbName(), | ||
$this->assertInIsolation(static function () use ($wpLoader) { | ||
$wpLoader->_initialize(); | ||
|
||
Assert::assertTrue(function_exists('do_action')); | ||
Assert::assertInstanceOf(\WP_User::class, wp_get_current_user()); | ||
|
||
return $wpLoader->getInstallation()->getDb()->getDbName(); | ||
}) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,19 +24,6 @@ class MysqlDatabaseTest extends Unit | |
use UopzFunctions; | ||
use TmpFilesCleanup; | ||
|
||
/** | ||
* It should throw when building with invalid db name | ||
* | ||
* @test | ||
*/ | ||
public function should_throw_when_building_with_invalid_db_name(): void | ||
{ | ||
$this->expectException(DbException::class); | ||
$this->expectExceptionCode(DbException::INVALID_DB_NAME); | ||
|
||
new MysqlDatabase('!invalid~db-name', 'root', 'root', 'localhost'); | ||
} | ||
|
||
/** | ||
* It should allow getting the db credentials and DSN | ||
* | ||
|
@@ -52,8 +39,10 @@ public function should_allow_getting_the_db_credentials_and_dsn(): void | |
$this->assertEquals('192.1.2.3:4415', $db->getDbHost()); | ||
$this->assertEquals('test_', $db->getTablePrefix()); | ||
$this->assertEquals('mysql:host=192.1.2.3;port=4415;dbname=test', $db->getDsn()); | ||
$this->assertEquals('mysql://bob:[email protected]:4415/test', | ||
$db->getDbUrl()); | ||
$this->assertEquals( | ||
'mysql://bob:[email protected]:4415/test', | ||
$db->getDbUrl() | ||
); | ||
} | ||
|
||
/** | ||
|
@@ -77,8 +66,10 @@ public function should_build_correctly_from_wp_config_file(): void | |
$this->assertEquals('192.1.2.3:4415', $db->getDbHost()); | ||
$this->assertEquals('test_', $db->getTablePrefix()); | ||
$this->assertEquals('mysql:host=192.1.2.3;port=4415;dbname=test', $db->getDsn()); | ||
$this->assertEquals('mysql://bob:[email protected]:4415/test', | ||
$db->getDbUrl()); | ||
$this->assertEquals( | ||
'mysql://bob:[email protected]:4415/test', | ||
$db->getDbUrl() | ||
); | ||
} | ||
|
||
/** | ||
|
@@ -126,21 +117,24 @@ public function should_allow_options_operations(): void | |
'admin', | ||
'password', | ||
'[email protected]', | ||
'Test'); | ||
'Test' | ||
); | ||
|
||
new Single($wpRootDir, $wpRootDir . '/wp-config.php'); | ||
|
||
$this->assertEquals('lorem', $db->getOption('non-existent-option', 'lorem')); | ||
foreach ([ | ||
'foo' => 'bar', | ||
'bar' => 2389, | ||
'object' => (object)['foo' => 'bar'], | ||
'array' => ['foo' => 'bar'], | ||
'associative array' => ['foo' => 'bar', 'bar' => 'foo'], | ||
'null' => null, | ||
'true' => true, | ||
'false' => false, | ||
] as $name => $value) { | ||
foreach ( | ||
[ | ||
'foo' => 'bar', | ||
'bar' => 2389, | ||
'object' => (object)['foo' => 'bar'], | ||
'array' => ['foo' => 'bar'], | ||
'associative array' => ['foo' => 'bar', 'bar' => 'foo'], | ||
'null' => null, | ||
'true' => true, | ||
'false' => false, | ||
] as $name => $value | ||
) { | ||
$this->assertEquals(1, $db->updateOption($name, $value)); | ||
$this->assertEquals($value, $db->getOption($name)); | ||
} | ||
|