Skip to content
This repository was archived by the owner on Mar 17, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 134 additions & 0 deletions tests/codeception/_support/Helper/JoomlaDb.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?php
/**
* @package Joomla.Test
* @subpackage Helper
*
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace Helper;

use Codeception\Module\Db;

/**
* JoomlaDb Helper class for Acceptance.
*
* You can create DB Helper methods here
*
* @package Codeception\Module
*
* @since __DEPLOY_VERSION__
*/
class JoomlaDb extends Db
{
/**
* @var string The table prefix
*/
protected $prefix;

/**
* Codeception Hook: called after configuration is loaded
*/
public function _initialize()
{
$this->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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice override ^_^

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good or bad? 😄

{
$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;
}
}
6 changes: 3 additions & 3 deletions tests/codeception/acceptance.suite.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down