* Introduce plugin test suite. */ echo "\n"; echo "[0;32m CleverReach Extension Test Suite [0m" . "\n"; echo "[0;32m Version: 0.3.0 [0m" . "\n"; echo "\n"; /** * Define base directory. */ $baseDir = dirname(__DIR__); /** * Require composer dependencies. */ $autoloadFile = $baseDir . '/vendor/autoload.php'; if (file_exists($autoloadFile)) { require_once $autoloadFile; } /** * Setup test environment using WP Tests Starter. * * @link https://github.com/inpsyde/WP-Tests-Starter */ $starter = new WpTestsStarter($baseDir . '/vendor/inpsyde/wordpress-dev'); $starter->defineDbName(DB_NAME); $starter->defineDbUser(DB_USER); $starter->defineDbPassword(DB_PASSWORD); $starter->defineDbHost(DB_HOST); $starter->defineDbCharset(DB_CHARSET); $starter->defineDbCollate(DB_COLLATE); $starter->setTablePrefix(DB_TABLE_PREFIX); $starter->bootstrap();
/** * @runInSeparateProcess */ public function testBoostrapWithDefaultConstants() { #$this->markTestIncomplete(); $baseDir = dirname(dirname(__DIR__)) . '/vendor/inpsyde/wordpress-dev'; $testee = new WpTestsStarter($baseDir); // defined in phpunit-integration.xml $testee->defineDbName(Db\NAME); $testee->defineDbUser(Db\USER); $testee->defineDbPassword(Db\PASSWORD); $testee->defineDbHost(Db\HOST); $testee->defineDbCharset(Db\CHARSET); $testee->defineDbCollate(Db\COLLATE); $testee->setTablePrefix(Db\TABLE_PREFIX); $testee->bootstrap(); $this->assertFileExists($testee->getConfigFile()); $config_data = file_get_contents($testee->getConfigFile()); $this->assertRegExp('~define\\(\\s\'ABSPATH\',\\s\'[^\']+\'~', $config_data); }
/** * @see WpTestsStarter::createDummyConfigFile() */ public function testCreateDummyConfigFile() { $baseDir = dirname(__DIR__) . '/tmp'; $configFile = $baseDir . '/wp-tests-config.php'; $testee = new WpTestsStarter($baseDir); $const = strtoupper(__FUNCTION__); $testee->defineConst($const, 'FOO'); $testee->defineConst($const . '_1', 'FOO'); $testee->defineConst($const . '_2', 'FOO'); if (file_exists($configFile)) { unlink($configFile); } $this->assertFileNotExists($configFile, "Remove the temporary config file before running this test."); $testee->createDummyConfigFile(); $this->assertFileExists($configFile); $fileContent = file_get_contents($configFile); # count the number of definitions in the file $replaceCount = 0; str_replace('define(', 'define(', $fileContent, $replaceCount); $this->assertEquals(3, $replaceCount); unlink($configFile); }