diff --git a/tests/codeception/_support/Helper/JoomlaDb.php b/tests/codeception/_support/Helper/JoomlaDb.php new file mode 100644 index 0000000000..90a5336884 --- /dev/null +++ b/tests/codeception/_support/Helper/JoomlaDb.php @@ -0,0 +1,134 @@ +prefix = (isset($this->config['prefix'])) ? $this->config['prefix'] : ''; + + return parent::_initialize(); + } + + /** + * Inserts an SQL record into a database. This record will be erased after the test. + * + * @param string $table + * @param array $data + * + * @return integer $id The last insert id + */ + public function haveInDatabase($table, array $data) + { + $table = $this->addPrefix($table); + + return parent::haveInDatabase($table, $data); + } + + /** + * See an entry in the database + * + * @param string $table + * @param array $criteria + */ + public function seeInDatabase($table, $criteria = []) + { + $table = $this->addPrefix($table); + + parent::seeInDatabase($table, $criteria); + } + + /** + * @param string $table + * @param array $criteria + */ + public function dontSeeInDatabase($table, $criteria = []) + { + $table = $this->addPrefix($table); + + parent::dontSeeInDatabase($table, $criteria); + } + + /** + * Grab an entry from the database + * + * @param $table + * @param $column + * @param null $criteria + * + * @return mixed + */ + public function grabFromDatabase($table, $column, $criteria = null) + { + $table = $this->addPrefix($table); + + return parent::grabFromDatabase($table, $column, $criteria); + } + + /** + * Asserts that the given number of records were found in the database. + * + * @param int $expectedNumber Expected number + * @param string $table Table name + * @param array $criteria Search criteria [Optional] + */ + public function seeNumRecords($expectedNumber, $table, array $criteria = []) + { + $table = $this->addPrefix($table); + + parent::seeNumRecords($expectedNumber, $table, $criteria); + } + + /** + * Returns the number of rows in a database + * + * @param string $table Table name + * @param array $criteria Search criteria [Optional] + * + * @return int + */ + public function grabNumRecords($table, array $criteria = []) + { + $table = $this->addPrefix($table); + + return parent::grabNumRecords($table, $criteria); + } + + /** + * Add the table prefix + * + * @param $table string + * + * @return string + */ + protected function addPrefix($table) + { + return $this->prefix . $table; + } +} diff --git a/tests/codeception/acceptance.suite.dist.yml b/tests/codeception/acceptance.suite.dist.yml index d13c965f4c..ad358bad5c 100644 --- a/tests/codeception/acceptance.suite.dist.yml +++ b/tests/codeception/acceptance.suite.dist.yml @@ -10,7 +10,7 @@ modules: - JoomlaBrowser - AcceptanceHelper - Asserts - - Db + - \Helper\JoomlaDb config: JoomlaBrowser: url: 'http://localhost/tests/codeception/joomla-cms3' # the url that points to the joomla installation at /tests/system/joomla-cms @@ -33,11 +33,11 @@ modules: AcceptanceHelper: url: 'http://localhost/tests/codeception/joomla-cms3' # the url that points to the joomla installation at /tests/system/joomla-cms - we need it twice here MicrosoftEdgeInsiders: false # set this to true, if you are on Windows Insiders - Db: # http://codeception.com/docs/modules/Db + \Helper\JoomlaDb: # http://codeception.com/docs/modules/Db dsn: 'mysql:host=localhost;dbname=test_joomla' # PDO DSN user: 'root' # MySQL Server user password: '' # MySQL Server password - + prefix: 'jos_' # Table Prefix for tables error_level: "E_ALL & ~E_STRICT & ~E_DEPRECATED" gherkin: