public static function setUpBeforeClass() { parent::setUpBeforeClass(); self::$testConfig = TestConfig::createDefaultConfig(); self::$wpAutomation = new WpAutomation(self::$testConfig->testSite, self::$testConfig->wpCliVersion); self::setUpSite(); DBAsserter::assertFilesEqualDatabase(); $yamlDir = self::$wpAutomation->getPluginsDir() . '/versionpress/.versionpress'; $schemaFile = $yamlDir . '/schema.yml'; $actionsFile = $yamlDir . '/actions.yml'; $shortcodeFile = $yamlDir . '/shortcodes.yml'; /** @var $wp_db_version */ require self::$wpAutomation->getAbspath() . '/wp-includes/version.php'; if (!function_exists('get_shortcode_regex')) { require_once self::$wpAutomation->getAbspath() . '/wp-includes/shortcodes.php'; } self::$schemaInfo = new DbSchemaInfo([$schemaFile], self::$testConfig->testSite->dbTablePrefix, $wp_db_version); $actionsInfoProvider = new ActionsInfoProvider([$actionsFile]); $changeInfoFactory = new ChangeInfoFactory(self::$schemaInfo, $actionsInfoProvider); $dbHost = self::$testConfig->testSite->dbHost; $dbUser = self::$testConfig->testSite->dbUser; $dbPassword = self::$testConfig->testSite->dbPassword; $dbName = self::$testConfig->testSite->dbName; $wpdb = new wpdb($dbUser, $dbPassword, $dbName, $dbHost); $wpdb->set_prefix(self::$testConfig->testSite->dbTablePrefix); self::$database = new Database($wpdb); $shortcodesInfo = new ShortcodesInfo([$shortcodeFile]); self::$vpidRepository = new VpidRepository(self::$database, self::$schemaInfo); self::$shortcodesReplacer = new ShortcodesReplacer($shortcodesInfo, self::$vpidRepository); $vpdbPath = self::$wpAutomation->getVpdbDir(); self::$tableSchemaRepository = new TableSchemaStorage(self::$database, $vpdbPath . '/.schema'); self::$storageFactory = new StorageFactory($vpdbPath, self::$schemaInfo, self::$database, [], $changeInfoFactory, self::$tableSchemaRepository); self::$urlReplacer = new AbsoluteUrlReplacer(self::$testConfig->testSite->url); }
/** * @test * @testdox Changing more option creates bulk 'option/edit' action */ public function changingMoreOptionsCreatesOptionEditAction() { self::$worker->prepare_changeTwoOptions(); $this->commitAsserter->reset(); self::$worker->changeTwoOptions(); $this->commitAsserter->assertNumCommits(1); $this->commitAsserter->assertBulkAction('option/edit', 2); $this->commitAsserter->assertCommitPath('M', '%vpdb%/options/%VPID%.ini'); $this->commitAsserter->assertCleanWorkingDirectory(); DBAsserter::assertFilesEqualDatabase(); }
/** * @test * @testdox Switching language creates 'translation/activate' action */ public function switchingLanguageCreatesLanguageActivateAction() { self::$worker->prepare_switchLanguage(); $this->commitAsserter->reset(); self::$worker->switchLanguage(); $this->commitAsserter->assertNumCommits(1); $this->commitAsserter->assertCommitAction('translation/activate'); $this->commitAsserter->assertCommitPath(['A', 'M'], '%vpdb%/options/*'); $this->commitAsserter->assertCleanWorkingDirectory(); DBAsserter::assertFilesEqualDatabase(); }
/** * @test * @depends uploadingFileCreatesPostCreateAction */ public function editationOfFileCreatesCommit() { self::$worker->prepare_editFile(); $this->commitAsserter->reset(); self::$worker->editFile(); $this->commitAsserter->assertNumCommits(1); $this->commitAsserter->assertCommitAction("post/edit"); $this->commitAsserter->assertCommitTag("VP-Post-Type", "attachment"); $this->commitAsserter->assertCommitPath("A", "%uploads%/*"); $this->commitAsserter->assertCleanWorkingDirectory(); DBAsserter::assertFilesEqualDatabase(); }
public function runPublishingMultiplePostsCreatesBulkAction() { self::$worker->prepare_publishTwoPosts(); $this->commitAsserter->reset(); self::$worker->publishTwoPosts(); $this->commitAsserter->assertNumCommits(1); $this->commitAsserter->assertBulkAction('post/publish', 2); $this->commitAsserter->assertCleanWorkingDirectory(); DBAsserter::assertFilesEqualDatabase(); }
/** * @test * @testdox Deleting commentmeta of comment creates 'commentmeta/delete' action * @depends addingCommentmetaCreatesCommentmetaCreateAction */ public function deleteCommentmetaCreatesCommentmetaDeleteAction() { self::$worker->prepare_commentmetaDelete(); $this->commitAsserter->reset(); self::$worker->commentmetaDelete(); $this->commitAsserter->assertNumCommits(1); $this->commitAsserter->assertCommitAction("commentmeta/delete", 0, true); $this->commitAsserter->assertCleanWorkingDirectory(); DBAsserter::assertFilesEqualDatabase(); }
/** * @test * @testdox Non-DB change doesn't break the database */ public function undoOfNonDbChangeDoesntBreakDatabase() { $changes = self::$worker->prepare_undoNonDbChange(); $this->commitAsserter->reset(); self::$worker->undoNonDbChange(); $this->commitAsserter->assertNumCommits(1); $this->commitAsserter->assertCommitAction('versionpress/undo'); $this->commitAsserter->assertCountOfAffectedFiles(count($changes)); $this->commitAsserter->assertCommitPaths($changes); $this->commitAsserter->assertCleanWorkingDirectory(); DBAsserter::assertFilesEqualDatabase(); }
/** * @test * @depends successfulActivationRedirectsToMainVersionPressTableAndAltersWpdbClass */ public function afterActivationTheFilesystemMatchDatabase() { DBAsserter::assertFilesEqualDatabase(); }
/** * @test * @testdox Deleting widget creates 'option/edit' action */ public function deletingWidgetCreatesOptionEditAction() { self::$worker->prepare_deleteWidget(); $this->commitAsserter->reset(); self::$worker->deleteWidget(); $this->commitAsserter->assertNumCommits(1); $this->commitAsserter->assertCommitAction('option/edit'); $this->commitAsserter->assertCountOfAffectedFiles(2); $this->commitAsserter->assertCommitPath('M', '%vpdb%/options/%VPID%.ini'); $this->commitAsserter->assertCleanWorkingDirectory(); DBAsserter::assertFilesEqualDatabase(); }
/** * @test * @testdox Uninstalling two plugins creates a bulk action */ public function uninstallingTwoPluginsCreatesBulkAction() { self::$worker->prepare_uninstallTwoPlugins(); $this->commitAsserter->reset(); self::$worker->uninstallTwoPlugins(); $this->commitAsserter->assertNumCommits(1); $this->commitAsserter->assertBulkAction('plugin/delete', 2); $this->commitAsserter->assertCommitPath("D", "wp-content/plugins/" . self::$pluginInfo['affected-path']); $this->commitAsserter->assertCommitPath("D", "wp-content/plugins/" . self::$secondPluginInfo['affected-path']); $this->commitAsserter->assertCleanWorkingDirectory(); DBAsserter::assertFilesEqualDatabase(); }
/** * @test * @testdox Deleting post meta creates 'postmeta/delete' action */ public function deletingOfPostmetaCreatesPostmetaDeleteAction() { self::$worker->prepare_deletePostmeta(); $this->commitAsserter->reset(); self::$worker->deletePostmeta(); $this->commitAsserter->assertNumCommits(1); $this->commitAsserter->assertCommitAction('postmeta/delete'); $this->commitAsserter->assertCleanWorkingDirectory(); DBAsserter::assertFilesEqualDatabase(); }
/** * @test * @testdox Deleting usermeta creates multiple usermeta creates 'usermeta/delete' action */ public function deletingUsermetaCreatesUsermetaDeleteAction() { self::$worker->prepare_deleteUsermeta(); $this->commitAsserter->reset(); self::$worker->deleteUsermeta(); $this->commitAsserter->assertNumCommits(1); $this->commitAsserter->assertCommitAction("usermeta/delete"); $this->commitAsserter->assertCommitTag("VP-User-Login", self::$testUser['login']); $this->commitAsserter->assertCommitPath("M", "%vpdb%/users/%VPID(VP-User-Id)%.ini"); $this->commitAsserter->assertCleanWorkingDirectory(); DBAsserter::assertFilesEqualDatabase(); }
/** * @test * @testdox Deleting menu creates 'term/delete' action * @depends removingMenuItemCreatesPostDeleteAction */ public function deletingMenuCreatesTermDeleteAction() { self::$worker->prepare_deleteMenu(); $this->commitAsserter->reset(); self::$worker->deleteMenu(); $this->commitAsserter->assertNumCommits(1); $this->commitAsserter->assertCommitAction("term/delete"); $this->commitAsserter->assertCommitPath('D', "%vpdb%/terms/%VPID%.ini"); $this->commitAsserter->assertCleanWorkingDirectory(); DBAsserter::assertFilesEqualDatabase(); }
/** * @test */ public function runDBAsserter() { DBAsserter::assertFilesEqualDatabase(); }
/** * @test * @testdox Deleting two themes creates a bulk action */ public function deletingTwoThemesCreatesBulkAction() { self::$worker->prepare_deleteTwoThemes(); $this->commitAsserter->reset(); self::$worker->deleteTwoThemes(); $this->commitAsserter->assertNumCommits(1); $this->commitAsserter->assertBulkAction('theme/delete', 2); $this->commitAsserter->assertCommitPath("D", "wp-content/themes/" . self::$themeInfo['affected-path']); $this->commitAsserter->assertCommitPath("D", "wp-content/themes/" . self::$secondThemeInfo['affected-path']); $this->commitAsserter->assertCleanWorkingDirectory(); DBAsserter::assertFilesEqualDatabase(); }
/** * @test * @testdox Synchronizer replaces value references */ public function synchronizerReplacesValueReferences() { $post = EntityUtils::preparePost(); $optionToSynchronize = [['vp_id' => 'site_icon', 'parent' => null]]; $postToSynchronize = [['vp_id' => $post['vp_id'], 'parent' => null]]; $previousSiteIcon = $this->storage->exists('site_icon') ? $this->storage->loadEntity('site_icon') : ''; $this->postStorage->save($post); $option = EntityUtils::prepareOption('site_icon', $post['vp_id']); $this->storage->save($option); $this->postsSynchronizer->synchronize(Synchronizer::SYNCHRONIZE_EVERYTHING, $postToSynchronize); $this->synchronizer->synchronize(Synchronizer::SYNCHRONIZE_EVERYTHING, $optionToSynchronize); DBAsserter::assertFilesEqualDatabase(); // cleanup if ($previousSiteIcon) { if (!isset($previousSiteIcon['option_value'])) { $previousSiteIcon['option_value'] = false; } $this->storage->save($previousSiteIcon); } else { $this->storage->delete($option); } $this->postStorage->delete($post); $this->synchronizer->reset(); $this->postsSynchronizer->reset(); $this->synchronizer->synchronize(Synchronizer::SYNCHRONIZE_EVERYTHING, $optionToSynchronize); $this->postsSynchronizer->synchronize(Synchronizer::SYNCHRONIZE_EVERYTHING, $postToSynchronize); }
/** * @test * @testdox Synchronizer removes deleted term from the database (selective synchronization) */ public function synchronizerRemovesDeletedTermFromDatabase_selective() { $entitiesToSynchronize = $this->deleteTerm(); $this->synchronizer->synchronize(Synchronizer::SYNCHRONIZE_EVERYTHING, $entitiesToSynchronize); DBAsserter::assertFilesEqualDatabase(); }
/** * @test * @testdox Synchronizer restores shortcodes */ public function synchronizerRestoresShortcodes() { $this->createPostWithShortcode(); $this->usersSynchronizer->synchronize(Synchronizer::SYNCHRONIZE_EVERYTHING); $synchronizationTasks = [Synchronizer::SYNCHRONIZE_EVERYTHING]; while (count($synchronizationTasks)) { $task = array_shift($synchronizationTasks); $remainingTasks = $this->synchronizer->synchronize($task); $synchronizationTasks = array_merge($synchronizationTasks, $remainingTasks); } DBAsserter::assertFilesEqualDatabase(); $this->deletePost(); $this->synchronizer->reset(); $this->usersSynchronizer->reset(); $this->synchronizer->synchronize(Synchronizer::SYNCHRONIZE_EVERYTHING); $this->usersSynchronizer->synchronize(Synchronizer::SYNCHRONIZE_EVERYTHING); DBAsserter::assertFilesEqualDatabase(); }