Skip to content

Commit

Permalink
Merge pull request #568 from lucatume/fix-567
Browse files Browse the repository at this point in the history
Fix DROP tables query in WPLoader
  • Loading branch information
lucatume authored Mar 16, 2022
2 parents ae919f0 + a2ce498 commit d797924
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 11 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [unreleased] Unreleased

## [3.1.5] 2022-03-16;

## Fixed

- Fixed query to `DROP` tables generated by the `WPLoader` module when setting `installationTableHandling` to `drop`.

## [3.1.4] 2022-03-02;

## Changed
Expand Down Expand Up @@ -1785,4 +1791,5 @@ Read the [migration guide here](https://wpbrowser.wptestkit.dev/migration/from-v
[3.1.2]: https://github.com/lucatume/wp-browser/compare/3.1.1...3.1.2
[3.1.3]: https://github.com/lucatume/wp-browser/compare/3.1.2...3.1.3
[3.1.4]: https://github.com/lucatume/wp-browser/compare/3.1.3...3.1.4
[unreleased]: https://github.com/lucatume/wp-browser/compare/3.1.4...HEAD
[3.1.5]: https://github.com/lucatume/wp-browser/compare/3.1.4...3.1.5
[unreleased]: https://github.com/lucatume/wp-browser/compare/3.1.5...HEAD
2 changes: 1 addition & 1 deletion src/Codeception/Module/WPLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ public function getContentFolder($path = '')
}

/**
* Returns the WordPress installation configuration as created from the currrent module configuration.
* Returns the WordPress installation configuration as created from the current module configuration.
*
* @return Configuration The WordPress installation configuration, as created from the module configuration.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/tad/WPBrowser/wp.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function dropWpTables(\wpdb $wpdb, array $tables = null)
$droppedTables = [];

foreach ($tablesList as $table => $prefixedTable) {
$dropped = $wpdb->query("DROP TABLE {$prefixedTable} IF EXISTS");
$dropped = $wpdb->query("DROP TABLE IF EXISTS {$prefixedTable}");

if ($dropped !== true) {
throw new \RuntimeException("Could not DROP table {$prefixedTable}: " . $wpdb->last_error);
Expand Down
2 changes: 1 addition & 1 deletion tests/_support/_generated/UnitTesterActions.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php //[STAMP] a0ddce95731c8d704d4329c3b445cf27
<?php //[STAMP] 5fd24ad5b7e739fafb6359435ac6054b
namespace _generated;

// This class was automatically generated by build task
Expand Down
4 changes: 2 additions & 2 deletions tests/_support/_generated/WploaderTesterActions.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php //[STAMP] 27c2e8152cac6ec9b98209202445038b
<?php //[STAMP] 791549d85a0270e81bd7a173f03d9f58
namespace _generated;

// This class was automatically generated by build task
Expand Down Expand Up @@ -123,7 +123,7 @@ public function getContentFolder($path = "") {
* @return void
* @see \Codeception\Module\WPLoader::startWpFiltersDebug()
*/
public function startWpFiltersDebug(?callable $format = NULL) {
public function startWpFiltersDebug($format = NULL) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('startWpFiltersDebug', func_get_args()));
}

Expand Down
12 changes: 7 additions & 5 deletions tests/unit/tad/WPBrowser/wpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

use tad\WPBrowser\Traits\WithStubProphecy;

use function tad\WPBrowser\Tests\Support\testEnvFile;

require_once codecept_root_dir('tests/_support/lib/wpdb.php');

class wpTest extends \Codeception\Test\Unit
Expand All @@ -26,9 +28,9 @@ public function test_drop_wp_tables_will_drop_all_tables_if_whitelist_not_specif
$dropped = dropWpTables($wpdb);

$this->assertEquals([
'DROP TABLE wp_options IF EXISTS',
'DROP TABLE wp_posts IF EXISTS',
'DROP TABLE wp_users IF EXISTS'
'DROP TABLE IF EXISTS wp_options',
'DROP TABLE IF EXISTS wp_posts',
'DROP TABLE IF EXISTS wp_users'
], $queries);
$this->assertEquals(['wp_options', 'wp_posts', 'wp_users'], $dropped);
}
Expand All @@ -51,8 +53,8 @@ public function test_drop_wp_tables_will_drop_only_tables_in_whitelist()
$dropped = dropWpTables($wpdb, ['wp_posts', 'wp_users', 'foo_bar']);

$this->assertEquals([
'DROP TABLE wp_posts IF EXISTS',
'DROP TABLE wp_users IF EXISTS',
'DROP TABLE IF EXISTS wp_posts',
'DROP TABLE IF EXISTS wp_users',
], $queries);
$this->assertEquals(['wp_posts', 'wp_users'], $dropped);
}
Expand Down
1 change: 1 addition & 0 deletions tests/wploadersuite.suite.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ modules:
theme: dummy
plugins: ['mu-plugin-1/plugin.php']
activatePlugins: ['mu-plugin-1/plugin.php']
installationTableHandling: drop
booststrapActions: []

0 comments on commit d797924

Please sign in to comment.