|
From: <gem...@li...> - 2012-10-02 08:49:16
|
Revision: 968
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=968&view=rev
Author: mennodekker
Date: 2012-10-02 08:49:09 +0000 (Tue, 02 Oct 2012)
Log Message:
-----------
Separated test helpers from tests so projects can use helpers in their own test setups without having to run all Gems / MUtil tests too
Modified Paths:
--------------
trunk/test/bootstrap.php
Added Paths:
-----------
trunk/test/library/
trunk/test/library/ControllerTestAbstract.php
trunk/test/library/Gems/
trunk/test/library/Gems/Test/
trunk/test/library/Gems/Test/DbTestAbstract.php
trunk/test/library/Gems/Test/TestAbstract.php
trunk/test/library/IndexControllerTest.php
trunk/test/library/Zend/
trunk/test/library/Zend/Test/
trunk/test/library/Zend/Test/PHPUnit/
trunk/test/library/Zend/Test/PHPUnit/Constraint/
trunk/test/library/Zend/Test/PHPUnit/Constraint/Redirect.php
trunk/test/library/Zend/Test/PHPUnit/Db/
trunk/test/library/Zend/Test/PHPUnit/Db/Metadata/
trunk/test/library/Zend/Test/PHPUnit/Db/Metadata/Generic.php
Removed Paths:
-------------
trunk/test/classes/ControllerTestAbstract.php
trunk/test/classes/Gems/Test/
trunk/test/classes/IndexControllerTest.php
trunk/test/classes/Zend/
Modified: trunk/test/bootstrap.php
===================================================================
--- trunk/test/bootstrap.php 2012-10-02 07:47:36 UTC (rev 967)
+++ trunk/test/bootstrap.php 2012-10-02 08:49:09 UTC (rev 968)
@@ -63,6 +63,7 @@
$path . '/library/classes' . PATH_SEPARATOR .
GEMS_ROOT_DIR . '/application/classes' . PATH_SEPARATOR .
GEMS_WEB_DIR . '/classes' . PATH_SEPARATOR .
+ GEMS_WEB_DIR . '/library' . PATH_SEPARATOR .
get_include_path());
// Set up autoload.
Deleted: trunk/test/classes/ControllerTestAbstract.php
===================================================================
--- trunk/test/classes/ControllerTestAbstract.php 2012-10-02 07:47:36 UTC (rev 967)
+++ trunk/test/classes/ControllerTestAbstract.php 2012-10-02 08:49:09 UTC (rev 968)
@@ -1,29 +0,0 @@
-<?php
-class ControllerTestAbstract extends Zend_Test_PHPUnit_ControllerTestCase
-{
- public function setUp()
- {
- // Zend_Application: loads the autoloader
- require_once 'Zend/Application.php';
-
- // Create application, bootstrap, and run
- $application = new Zend_Application(
- APPLICATION_ENV,
- APPLICATION_PATH . '/configs/application.ini'
- );
-
- $this->bootstrap = $application;
-
- parent::setUp();
- }
-
- /**
- * Here we fix the intentional errors that are in de default setup
- *
- * At the moment we only set a salt in the project resource
- */
- protected function _fixSetup() {
- $project = $this->bootstrap->getBootstrap()->getResource('project');
- $project->salt = 'TESTCASE';
- }
-}
Deleted: trunk/test/classes/IndexControllerTest.php
===================================================================
--- trunk/test/classes/IndexControllerTest.php 2012-10-02 07:47:36 UTC (rev 967)
+++ trunk/test/classes/IndexControllerTest.php 2012-10-02 08:49:09 UTC (rev 968)
@@ -1,59 +0,0 @@
-<?php
-require_once 'ControllerTestAbstract.php';
-class IndexControllerTest extends ControllerTestAbstract
-{
- public function testSaltRequired()
- {
- $this->dispatch('/');
- $reponse = $this->getFrontController()->getResponse();
- $exception = $reponse->getExceptionByMessage("Missing required project setting: 'salt'.");
- $this->assertTrue(count($exception) == 1);
- }
-
- public function testHomeRedirectsToLogin()
- {
- $this->_fixSetup();
- $this->dispatch('/');
- $this->assertRedirectTo('/index/login');
- }
-
- public function testLoginPage()
- {
- $this->_fixSetup();
- $this->dispatch('/index/login');
- $this->assertController('index');
- $this->assertAction('login');
- }
-
- public function testValidProjectLogin()
- {
- $this->_fixSetup();
- $postVars = array(
- 'organization'=>'',
- 'userlogin'=>'superadmin', //Valid login, this comes from project.ini in newproject
- 'password'=>'superadmin',
- 'button'=>'Login' //Submit button / label come from Gems_User_Form_LoginForm
- );
- $this->getRequest()->setMethod('POST')->setPost($postVars);
-
- $this->dispatch('/index/login');
- $response = $this->getResponse();
- $this->assertRedirect('Valid project login not accepted');
- }
-
- public function testInvalidProjectLogin()
- {
- $this->_fixSetup();
- $postVars = array(
- 'organization'=>'',
- 'userlogin'=>'superadmin',
- 'password'=>'superpassword', //This is wrong
- 'submit'=>'Login'
- );
- $this->getRequest()->setMethod('POST')->setPost($postVars);
-
- $this->dispatch('/index/login');
- $response = $this->getResponse();
- $this->assertNotRedirect('Invalid project login accepted');
- }
-}
Copied: trunk/test/library/ControllerTestAbstract.php (from rev 966, trunk/test/classes/ControllerTestAbstract.php)
===================================================================
--- trunk/test/library/ControllerTestAbstract.php (rev 0)
+++ trunk/test/library/ControllerTestAbstract.php 2012-10-02 08:49:09 UTC (rev 968)
@@ -0,0 +1,29 @@
+<?php
+class ControllerTestAbstract extends Zend_Test_PHPUnit_ControllerTestCase
+{
+ public function setUp()
+ {
+ // Zend_Application: loads the autoloader
+ require_once 'Zend/Application.php';
+
+ // Create application, bootstrap, and run
+ $application = new Zend_Application(
+ APPLICATION_ENV,
+ APPLICATION_PATH . '/configs/application.ini'
+ );
+
+ $this->bootstrap = $application;
+
+ parent::setUp();
+ }
+
+ /**
+ * Here we fix the intentional errors that are in de default setup
+ *
+ * At the moment we only set a salt in the project resource
+ */
+ protected function _fixSetup() {
+ $project = $this->bootstrap->getBootstrap()->getResource('project');
+ $project->salt = 'TESTCASE';
+ }
+}
Copied: trunk/test/library/Gems/Test/DbTestAbstract.php (from rev 966, trunk/test/classes/Gems/Test/DbTestAbstract.php)
===================================================================
--- trunk/test/library/Gems/Test/DbTestAbstract.php (rev 0)
+++ trunk/test/library/Gems/Test/DbTestAbstract.php 2012-10-02 08:49:09 UTC (rev 968)
@@ -0,0 +1,122 @@
+<?php
+
+/**
+ * Copyright (c) 2011, Erasmus MC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of Erasmus MC nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *
+ * Base test class for Gems object test cases
+ *
+ * @package Gems
+ * @subpackage Test
+ * @copyright Copyright (c) 2012 Erasmus MC
+ * @license New BSD License
+ * @version $Id: TestAbstract.php 925 2012-09-05 09:59:13Z mennodekker $
+ */
+
+/**
+ * Base test class for Gems object test cases that involve a database test
+ *
+ * @package Gems
+ * @subpackage Test
+ * @copyright Copyright (c) 2012 Erasmus MC
+ * @license New BSD License
+ * @version $Id: TestAbstract.php 925 2012-09-05 09:59:13Z mennodekker $
+ */
+abstract class Gems_Test_DbTestAbstract extends Zend_Test_PHPUnit_DatabaseTestCase
+{
+ /**
+ * @var Gems_Loader
+ */
+ protected $loader = null;
+
+ /**
+ * @var Zend_Db
+ */
+ protected $db = null;
+
+ /**
+ *
+ * @var PHPUnit_Extensions_Database_DB_IDatabaseConnection
+ */
+ protected $_connectionMock;
+
+ /**
+ * Sets up the fixture, for example, opens a network connection.
+ * This method is called before a test is executed.
+ */
+ protected function setUp()
+ {
+ parent::setUp();
+
+ global $GEMS_DIRS;
+
+ $this->db = $this->getConnection()->getConnection();
+
+ Zend_Registry::set('db', $this->db);
+
+ $this->loader = new Gems_Loader(Zend_Registry::getInstance(), $GEMS_DIRS);
+
+ Zend_Registry::set('loader', $this->loader);
+ }
+
+ /**
+ * Returns the test database connection.
+ *
+ * @return PHPUnit_Extensions_Database_DB_IDatabaseConnection
+ */
+ protected function getConnection()
+ {
+ if($this->_connectionMock == null) {
+ $connection = Zend_Db::factory('Pdo_Sqlite', array('dbname' => ':memory:', 'username' => 'test'));
+
+ if ($sqlFiles = $this->getInitSql()) {
+ foreach ($sqlFiles as $file) {
+ $sql = file_get_contents($file);
+ $statements = explode(';', $sql);
+ foreach($statements as $sql) {
+ if (!strpos(strtoupper($sql), 'INSERT INTO') && !strpos(strtoupper($sql), 'INSERT IGNORE')) {
+ $stmt = $connection->query($sql);
+ }
+ }
+ }
+ }
+ $this->_connectionMock = $this->createZendDbConnection(
+ $connection, 'zfunittests'
+ );
+ Zend_Db_Table_Abstract::setDefaultAdapter($connection);
+ }
+
+ return $this->_connectionMock;
+ }
+
+ protected function getInitSql()
+ {
+ $path = GEMS_WEB_DIR . '/data/';
+
+ // For successful testing of the complete tokens class, we need more tables
+ return array($path . 'sqllite/create-lite.sql');
+ }
+}
\ No newline at end of file
Copied: trunk/test/library/Gems/Test/TestAbstract.php (from rev 966, trunk/test/classes/Gems/Test/TestAbstract.php)
===================================================================
--- trunk/test/library/Gems/Test/TestAbstract.php (rev 0)
+++ trunk/test/library/Gems/Test/TestAbstract.php 2012-10-02 08:49:09 UTC (rev 968)
@@ -0,0 +1,87 @@
+<?php
+
+/**
+ * Copyright (c) 2011, Erasmus MC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of Erasmus MC nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *
+ * Base test class for Gems object test cases
+ *
+ * @package Gems
+ * @subpackage Test
+ * @author Michiel Rook <mi...@to...>
+ * @copyright Copyright (c) 2012 Erasmus MC
+ * @license New BSD License
+ * @version $Id$
+ */
+
+/**
+ * Base test class for Gems object test cases
+ *
+ * @package Gems
+ * @subpackage Test
+ * @author Michiel Rook <mi...@to...>
+ * @copyright Copyright (c) 2012 Erasmus MC
+ * @license New BSD License
+ * @version $Id$
+ */
+abstract class Gems_Test_TestAbstract extends PHPUnit_Framework_TestCase
+{
+ /**
+ * @var Gems_Loader
+ */
+ protected $loader = null;
+
+ /**
+ * @var Zend_Db
+ */
+ protected $db = null;
+
+ /**
+ * @var Gems_Tracker
+ */
+ protected $tracker = null;
+
+ /**
+ * Sets up the fixture, for example, opens a network connection.
+ * This method is called before a test is executed.
+ */
+ protected function setUp()
+ {
+ global $GEMS_DIRS;
+
+ $this->db = Zend_Db::factory('pdo_sqlite', array('dbname'=>':memory:'));
+
+ Zend_Registry::set('db', $this->db);
+
+ $this->loader = new Gems_Loader(Zend_Registry::getInstance(), $GEMS_DIRS);
+
+ Zend_Registry::set('loader', $this->loader);
+
+ $this->tracker = $this->loader->getTracker();
+
+ Zend_Registry::set('tracker', $this->tracker);
+ }
+}
Copied: trunk/test/library/IndexControllerTest.php (from rev 966, trunk/test/classes/IndexControllerTest.php)
===================================================================
--- trunk/test/library/IndexControllerTest.php (rev 0)
+++ trunk/test/library/IndexControllerTest.php 2012-10-02 08:49:09 UTC (rev 968)
@@ -0,0 +1,59 @@
+<?php
+require_once 'ControllerTestAbstract.php';
+class IndexControllerTest extends ControllerTestAbstract
+{
+ public function testSaltRequired()
+ {
+ $this->dispatch('/');
+ $reponse = $this->getFrontController()->getResponse();
+ $exception = $reponse->getExceptionByMessage("Missing required project setting: 'salt'.");
+ $this->assertTrue(count($exception) == 1);
+ }
+
+ public function testHomeRedirectsToLogin()
+ {
+ $this->_fixSetup();
+ $this->dispatch('/');
+ $this->assertRedirectTo('/index/login');
+ }
+
+ public function testLoginPage()
+ {
+ $this->_fixSetup();
+ $this->dispatch('/index/login');
+ $this->assertController('index');
+ $this->assertAction('login');
+ }
+
+ public function testValidProjectLogin()
+ {
+ $this->_fixSetup();
+ $postVars = array(
+ 'organization'=>'',
+ 'userlogin'=>'superadmin', //Valid login, this comes from project.ini in newproject
+ 'password'=>'superadmin',
+ 'button'=>'Login' //Submit button / label come from Gems_User_Form_LoginForm
+ );
+ $this->getRequest()->setMethod('POST')->setPost($postVars);
+
+ $this->dispatch('/index/login');
+ $response = $this->getResponse();
+ $this->assertRedirect('Valid project login not accepted');
+ }
+
+ public function testInvalidProjectLogin()
+ {
+ $this->_fixSetup();
+ $postVars = array(
+ 'organization'=>'',
+ 'userlogin'=>'superadmin',
+ 'password'=>'superpassword', //This is wrong
+ 'submit'=>'Login'
+ );
+ $this->getRequest()->setMethod('POST')->setPost($postVars);
+
+ $this->dispatch('/index/login');
+ $response = $this->getResponse();
+ $this->assertNotRedirect('Invalid project login accepted');
+ }
+}
Copied: trunk/test/library/Zend/Test/PHPUnit/Constraint/Redirect.php (from rev 966, trunk/test/classes/Zend/Test/PHPUnit/Constraint/Redirect.php)
===================================================================
--- trunk/test/library/Zend/Test/PHPUnit/Constraint/Redirect.php (rev 0)
+++ trunk/test/library/Zend/Test/PHPUnit/Constraint/Redirect.php 2012-10-02 08:49:09 UTC (rev 968)
@@ -0,0 +1,282 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to li...@ze... so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Test
+ * @subpackage PHPUnit
+ * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id$
+ */
+
+/** @see PHPUnit_Framework_Constraint */
+require_once 'PHPUnit/Framework/Constraint.php';
+
+/**
+ * Redirection constraints
+ *
+ * @uses PHPUnit_Framework_Constraint
+ * @category Zend
+ * @package Zend_Test
+ * @subpackage PHPUnit
+ * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+class Zend_Test_PHPUnit_Constraint_Redirect extends PHPUnit_Framework_Constraint
+{
+ /**#@+
+ * Assertion type constants
+ */
+ const ASSERT_REDIRECT = 'assertRedirect';
+ const ASSERT_REDIRECT_TO = 'assertRedirectTo';
+ const ASSERT_REDIRECT_REGEX = 'assertRedirectRegex';
+ /**#@-*/
+
+ /**
+ * Current assertion type
+ * @var string
+ */
+ protected $_assertType = null;
+
+ /**
+ * Available assertion types
+ * @var array
+ */
+ protected $_assertTypes = array(
+ self::ASSERT_REDIRECT,
+ self::ASSERT_REDIRECT_TO,
+ self::ASSERT_REDIRECT_REGEX,
+ );
+
+ /**
+ * Pattern to match against
+ * @var string
+ */
+ protected $_match = null;
+
+ /**
+ * Whether or not assertion is negated
+ * @var bool
+ */
+ protected $_negate = false;
+
+ /**
+ * Constructor; setup constraint state
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ }
+
+ /**
+ * Indicate negative match
+ *
+ * @param bool $flag
+ * @return void
+ */
+ public function setNegate($flag = true)
+ {
+ $this->_negate = $flag;
+ }
+
+ /**
+ * Evaluate an object to see if it fits the constraints
+ *
+ * @param string $other String to examine
+ * @param null|string Assertion type
+ * @return bool
+ */
+ public function evaluate($other, $assertType = null, $returnResult = FALSE)
+ {
+ if (!$other instanceof Zend_Controller_Response_Abstract) {
+ require_once 'Zend/Test/PHPUnit/Constraint/Exception.php';
+ throw new Zend_Test_PHPUnit_Constraint_Exception('Redirect constraint assertions require a response object');
+ }
+
+ if (strstr($assertType, 'Not')) {
+ $this->setNegate(true);
+ $assertType = str_replace('Not', '', $assertType);
+ }
+
+ if (!in_array($assertType, $this->_assertTypes)) {
+ require_once 'Zend/Test/PHPUnit/Constraint/Exception.php';
+ throw new Zend_Test_PHPUnit_Constraint_Exception(sprintf('Invalid assertion type "%s" provided to %s constraint', $assertType, __CLASS__));
+ }
+
+ $this->_assertType = $assertType;
+
+ $response = $other;
+ $argv = func_get_args();
+ $argc = func_num_args();
+
+ switch ($assertType) {
+ case self::ASSERT_REDIRECT_TO:
+ if (3 > $argc) {
+ require_once 'Zend/Test/PHPUnit/Constraint/Exception.php';
+ throw new Zend_Test_PHPUnit_Constraint_Exception('No redirect URL provided against which to match');
+ }
+ $this->_match = $match = $argv[2];
+ return ($this->_negate)
+ ? $this->_notMatch($response, $match)
+ : $this->_match($response, $match);
+ case self::ASSERT_REDIRECT_REGEX:
+ if (3 > $argc) {
+ require_once 'Zend/Test/PHPUnit/Constraint/Exception.php';
+ throw new Zend_Test_PHPUnit_Constraint_Exception('No pattern provided against which to match redirect');
+ }
+ $this->_match = $match = $argv[2];
+ return ($this->_negate)
+ ? $this->_notRegex($response, $match)
+ : $this->_regex($response, $match);
+ case self::ASSERT_REDIRECT:
+ default:
+ return ($this->_negate) ? !$response->isRedirect() : $response->isRedirect();
+ }
+ }
+
+ /**
+ * Report Failure
+ *
+ * @see PHPUnit_Framework_Constraint for implementation details
+ * @param mixed $other
+ * @param string $description Additional message to display
+ * @param bool $not
+ * @return void
+ * @throws PHPUnit_Framework_ExpectationFailedException
+ */
+ public function fail($other, $description, PHPUnit_Framework_ComparisonFailure $comparisonFailure = NULL)
+ {
+ require_once 'Zend/Test/PHPUnit/Constraint/Exception.php';
+ switch ($this->_assertType) {
+ case self::ASSERT_REDIRECT_TO:
+ $failure = 'Failed asserting response redirects to "%s"';
+ if ($this->_negate) {
+ $failure = 'Failed asserting response DOES NOT redirect to "%s"';
+ }
+ $failure = sprintf($failure, $this->_match);
+ break;
+ case self::ASSERT_REDIRECT_REGEX:
+ $failure = 'Failed asserting response redirects to URL MATCHING "%s"';
+ if ($this->_negate) {
+ $failure = 'Failed asserting response DOES NOT redirect to URL MATCHING "%s"';
+ }
+ $failure = sprintf($failure, $this->_match);
+ break;
+ case self::ASSERT_REDIRECT:
+ default:
+ $failure = 'Failed asserting response is a redirect';
+ if ($this->_negate) {
+ $failure = 'Failed asserting response is NOT a redirect';
+ }
+ break;
+ }
+
+ if (!empty($description)) {
+ $failure = $description . "\n" . $failure;
+ }
+
+ throw new Zend_Test_PHPUnit_Constraint_Exception($failure);
+ }
+
+ /**
+ * Complete implementation
+ *
+ * @return string
+ */
+ public function toString()
+ {
+ return '';
+ }
+
+ /**
+ * Check to see if content is matched in selected nodes
+ *
+ * @param Zend_Controller_Response_HttpTestCase $response
+ * @param string $match Content to match
+ * @return bool
+ */
+ protected function _match($response, $match)
+ {
+ if (!$response->isRedirect()) {
+ return false;
+ }
+
+ $headers = $response->sendHeaders();
+ $redirect = $headers['location'];
+ $redirect = str_replace('Location: ', '', $redirect);
+
+ return ($redirect == $match);
+ }
+
+ /**
+ * Check to see if content is NOT matched in selected nodes
+ *
+ * @param Zend_Controller_Response_HttpTestCase $response
+ * @param string $match
+ * @return bool
+ */
+ protected function _notMatch($response, $match)
+ {
+ if (!$response->isRedirect()) {
+ return true;
+ }
+
+ $headers = $response->sendHeaders();
+ $redirect = $headers['location'];
+ $redirect = str_replace('Location: ', '', $redirect);
+
+ return ($redirect != $match);
+ }
+
+ /**
+ * Check to see if content is matched by regex in selected nodes
+ *
+ * @param Zend_Controller_Response_HttpTestCase $response
+ * @param string $pattern
+ * @return bool
+ */
+ protected function _regex($response, $pattern)
+ {
+ if (!$response->isRedirect()) {
+ return false;
+ }
+
+ $headers = $response->sendHeaders();
+ $redirect = $headers['location'];
+ $redirect = str_replace('Location: ', '', $redirect);
+
+ return preg_match($pattern, $redirect);
+ }
+
+ /**
+ * Check to see if content is NOT matched by regex in selected nodes
+ *
+ * @param Zend_Controller_Response_HttpTestCase $response
+ * @param string $pattern
+ * @return bool
+ */
+ protected function _notRegex($response, $pattern)
+ {
+ if (!$response->isRedirect()) {
+ return true;
+ }
+
+ $headers = $response->sendHeaders();
+ $redirect = $headers['location'];
+ $redirect = str_replace('Location: ', '', $redirect);
+
+ return !preg_match($pattern, $redirect);
+ }
+}
Copied: trunk/test/library/Zend/Test/PHPUnit/Db/Metadata/Generic.php (from rev 966, trunk/test/classes/Zend/Test/PHPUnit/Db/Metadata/Generic.php)
===================================================================
--- trunk/test/library/Zend/Test/PHPUnit/Db/Metadata/Generic.php (rev 0)
+++ trunk/test/library/Zend/Test/PHPUnit/Db/Metadata/Generic.php 2012-10-02 08:49:09 UTC (rev 968)
@@ -0,0 +1,175 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to li...@ze... so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Test
+ * @subpackage PHPUnit
+ * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id$
+ */
+
+/**
+ * @see Zend_Db_Adapter_Abstract
+ */
+require_once "Zend/Db/Adapter/Abstract.php";
+
+/**
+ * @see PHPUnit_Extensions_Database_DB_IMetaData
+ */
+require_once "PHPUnit/Extensions/Database/DB/IMetaData.php";
+
+/**
+ * Generic Metadata accessor for the Zend_Db adapters
+ *
+ * @uses PHPUnit_Extensions_Database_DB_IMetaData
+ * @category Zend
+ * @package Zend_Test
+ * @subpackage PHPUnit
+ * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+class Zend_Test_PHPUnit_Db_Metadata_Generic implements PHPUnit_Extensions_Database_DB_IMetaData
+{
+ /**
+ * Zend_Db Connection
+ *
+ * @var Zend_Db_Adapter_Abstract
+ */
+ protected $_connection;
+
+ /**
+ * Schemaname
+ *
+ * @var string
+ */
+ protected $_schema;
+
+ /**
+ * Cached Table metadata
+ *
+ * @var array
+ */
+ protected $_tableMetadata = array();
+
+ /**
+ * Creates a new database meta data object using the given pdo connection
+ * and schema name.
+ *
+ * @param PDO $pdo
+ * @param string $schema
+ */
+ public final function __construct(Zend_Db_Adapter_Abstract $db, $schema)
+ {
+ $this->_connection = $db;
+ $this->_schema = $schema;
+ }
+
+ /**
+ * List Tables
+ *
+ * @return array
+ */
+ public function getTableNames()
+ {
+ return $this->_connection->listTables();
+ }
+
+ /**
+ * Get Table information
+ *
+ * @param string $tableName
+ * @return array
+ */
+ protected function getTableDescription($tableName)
+ {
+ if(!isset($this->_tableMetadata[$tableName])) {
+ $this->_tableMetadata[$tableName] = $this->_connection->describeTable($tableName);
+ }
+ return $this->_tableMetadata[$tableName];
+ }
+
+ /**
+ * Returns an array containing the names of all the columns in the
+ * $tableName table,
+ *
+ * @param string $tableName
+ * @return array
+ */
+ public function getTableColumns($tableName)
+ {
+ $tableMeta = $this->getTableDescription($tableName);
+ $columns = array_keys($tableMeta);
+ return $columns;
+ }
+
+ /**
+ * Returns an array containing the names of all the primary key columns in
+ * the $tableName table.
+ *
+ * @param string $tableName
+ * @return array
+ */
+ public function getTablePrimaryKeys($tableName)
+ {
+ $tableMeta = $this->getTableDescription($tableName);
+
+ $primaryColumnNames = array();
+ foreach($tableMeta AS $column) {
+ if($column['PRIMARY'] == true) {
+ $primaryColumnNames[] = $column['COLUMN_NAME'];
+ }
+ }
+ return $primaryColumnNames;
+ }
+
+ /**
+ * Returns the name of the default schema.
+ *
+ * @return string
+ */
+ public function getSchema()
+ {
+ return $this->_schema;
+ }
+
+ /**
+ * Returns a quoted schema object. (table name, column name, etc)
+ *
+ * @param string $object
+ * @return string
+ */
+ public function quoteSchemaObject($object)
+ {
+ return $this->_connection->quoteIdentifier($object);
+ }
+
+ /**
+ * Returns true if the rdbms allows cascading
+ *
+ * @return bool
+ */
+ public function allowsCascading()
+ {
+ return false;
+ }
+
+ public function disablePrimaryKeys($tableName)
+ {
+ }
+
+ public function enablePrimaryKeys($tableName)
+ {
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|