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); }
private static function staticInitialization() { self::$testConfig = TestConfig::createDefaultConfig(); self::$wpAutomation = new WpAutomation(self::$testConfig->testSite, self::$testConfig->wpCliVersion); $yamlDir = self::$wpAutomation->getPluginsDir() . '/versionpress/.versionpress'; $schemaFile = $yamlDir . '/schema.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); $rawTaxonomies = self::$wpAutomation->runWpCliCommand('taxonomy', 'list', ['format' => 'json', 'fields' => 'name']); $taxonomies = array_column(json_decode($rawTaxonomies, true), 'name'); $dbHost = self::$testConfig->testSite->dbHost; $dbUser = self::$testConfig->testSite->dbUser; $dbPassword = self::$testConfig->testSite->dbPassword; $dbName = self::$testConfig->testSite->dbName; $dbPrefix = self::$testConfig->testSite->dbTablePrefix; self::$database = new \mysqli($dbHost, $dbUser, $dbPassword, $dbName); self::$wpdb = new \wpdb($dbUser, $dbPassword, $dbName, $dbHost); self::$wpdb->set_prefix($dbPrefix); self::$vp_database = new Database(self::$wpdb); $shortcodesInfo = new ShortcodesInfo([$shortcodeFile]); self::$vpidRepository = new VpidRepository(self::$vp_database, self::$schemaInfo); self::$shortcodesReplacer = new ShortcodesReplacer($shortcodesInfo, self::$vpidRepository); $vpdbPath = self::$wpAutomation->getVpdbDir(); $tableSchemaRepository = new TableSchemaStorage(self::$vp_database, $vpdbPath . '/.schema'); self::$storageFactory = new StorageFactory($vpdbPath, self::$schemaInfo, self::$vp_database, $taxonomies, null, $tableSchemaRepository); require self::$wpAutomation->getPluginsDir() . '/versionpress/.versionpress/hooks.php'; self::defineGlobalVariables(); }
/** * @test */ public function vpdbDoesntAllowDirectAccess() { $vpdbDir = self::$wpAutomation->getVpdbDir(); $relativePathToVpdb = PathUtils::getRelativePath(self::$wpAutomation->getWebRoot(), $vpdbDir); $url = self::$testConfig->testSite->url . '/' . $relativePathToVpdb . "/web.config"; $statusCode = HttpStatusCodeUtil::getStatusCode($url); $this->assertTrue($statusCode === 403 || $statusCode === 404, "Wrong HTTP status code ({$statusCode})"); }
public function __construct($name = null, array $data = [], $dataName = '') { parent::__construct($name, $data, $dataName); $this->staticInitialization(); $this->gitRepository = new GitRepository(self::$testConfig->testSite->path); self::$wpAutomation = new WpAutomation(self::$testConfig->testSite, self::$testConfig->wpCliVersion); $vpdbDir = self::$wpAutomation->getVpdbDir(); $relativePathToVpdb = PathUtils::getRelativePath(self::$testConfig->testSite->path, $vpdbDir); $uploadsDir = self::$wpAutomation->getUploadsDir(); $relativePathToUploads = PathUtils::getRelativePath(self::$testConfig->testSite->path, $uploadsDir); $dbSchema = new DbSchemaInfo([self::$wpAutomation->getPluginsDir() . '/versionpress/.versionpress/schema.yml'], self::$testConfig->testSite->dbTablePrefix, PHP_INT_MAX); $actionsInfoProvider = new ActionsInfoProvider([self::$wpAutomation->getPluginsDir() . '/versionpress/.versionpress/actions.yml']); $this->commitAsserter = new CommitAsserter($this->gitRepository, $dbSchema, $actionsInfoProvider, ['vpdb' => $relativePathToVpdb, 'uploads' => $relativePathToUploads]); }