This repository was archived by the owner on Mar 17, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 28
Add a Joomla Database Helper #108
Merged
yvesh
merged 3 commits into
joomla-projects:staging
from
dneukirchen:feature/add-joomla-database-helpers
Dec 11, 2016
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
{ | ||
$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; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice override ^_^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good or bad? 😄