Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Oracle test format and improve connect test #160

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
81 changes: 70 additions & 11 deletions cake/tests/cases/libs/model/datasources/dbo/dbo_oracle.test.php
Expand Up @@ -17,11 +17,9 @@
* @since CakePHP(tm) v 1.2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
define('CAKEPHP_UNIT_TEST_EXECUTION', 1);
}
require_once LIBS . 'model' . DS . 'datasources' . DS . 'dbo_source.php';
require_once LIBS . 'model' . DS . 'datasources' . DS . 'dbo' . DS . 'dbo_oracle.php';

App::import('Core', array('DataSource', 'DboSource', 'DboOracle'));
Mock::generatePartial('DboOracle', 'QueryMockDboOracle', array('query', 'execute'));

/**
* DboOracleTest class
Expand All @@ -36,26 +34,88 @@ class DboOracleTest extends CakeTestCase {
*/
var $fixtures = array('core.oracle_user');

/**
* Actual DB connection used in testing
*
* @var DboSource
* @access public
*/
var $db = null;

/**
* Set up test suite database connection
*
* @access public
*/
function startTest() {
$this->_initDb();
}

/**
* setup method
*
* @access public
* @return void
*/
function setUp() {
$this->_initDb();
Configure::write('Cache.disable', true);
$this->startTest();
$this->db =& ConnectionManager::getDataSource('test_suite');
}

/**
* Tears down the Dbo class instance
*
* @access public
*/
function tearDown() {
Configure::write('Cache.disable', false);
unset($this->db);
ClassRegistry::flush();
}

/**
* skip method
*
* @access public
* @return void
*/
function skip() {
$this->_initDb();
$this->skipUnless($this->db->config['driver'] == 'oracle', '%s Oracle connection not available');
}
function skip() {
$this->_initDb();
$this->skipUnless($this->db->config['driver'] == 'oracle', '%s Oracle connection not available');
}

/**
* testConnect method
*
* @access public
* @return void
*/
function testConnect() {
$result = $this->db->connect();
$this->assertTrue($result);

$mockDbo =& new QueryMockDboOracle($this);
$mockDbo->config = $this->db->config;

// Test NLS_SORT setting
$mockDbo->config['nls_sort'] = 'BINARY';
$mockDbo->setReturnValue('execute', true);
$mockDbo->expectAt(0, 'execute', array("ALTER SESSION SET NLS_SORT=BINARY"));

// The NLS_DATE_FORMAT will always be set, so test that in the same connect() run
$mockDbo->expectAt(1, 'execute', array("ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'"));

$mockDbo->connect();

unset($mockDbo->config['nls_sort']);

// Test NLS_COMP setting
$mockDbo->config['nls_comp'] = 'BINARY';
$mockDbo->expectAt(2, 'execute', array("ALTER SESSION SET NLS_COMP=BINARY"));

$mockDbo->connect();
}

/**
* testLastErrorStatement method
Expand Down Expand Up @@ -105,7 +165,6 @@ function testLastErrorConnect() {
*/
function testName() {
$Db = $this->db;
#$Db =& new DboOracle($config = null, $autoConnect = false);

$r = $Db->name($Db->name($Db->name('foo.last_update_date')));
$e = 'foo.last_update_date';
Expand Down