mirror of
https://github.com/brmlab/brmsklad.git
synced 2025-08-03 22:53:58 +02:00
Upgrade CakePHP from 2.2.5 to 2.9.5
This commit is contained in:
parent
5a580df460
commit
235a541597
793 changed files with 60746 additions and 23753 deletions
|
@ -2,37 +2,46 @@
|
|||
/**
|
||||
* SessionTest file
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
||||
* @package Cake.Test.Case.Model.Datasource
|
||||
* @since CakePHP(tm) v 1.2.0.4206
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('CakeSession', 'Model/Datasource');
|
||||
App::uses('DatabaseSession', 'Model/Datasource/Session');
|
||||
App::uses('CacheSession', 'Model/Datasource/Session');
|
||||
|
||||
/**
|
||||
* TestCakeSession
|
||||
*
|
||||
* @package Cake.Test.Case.Model.Datasource
|
||||
*/
|
||||
class TestCakeSession extends CakeSession {
|
||||
|
||||
public static function setUserAgent($value) {
|
||||
self::$_userAgent = $value;
|
||||
static::$_userAgent = $value;
|
||||
}
|
||||
|
||||
public static function setHost($host) {
|
||||
self::_setHost($host);
|
||||
static::_setHost($host);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* TestCacheSession
|
||||
*
|
||||
* @package Cake.Test.Case.Model.Datasource
|
||||
*/
|
||||
class TestCacheSession extends CacheSession {
|
||||
|
||||
protected function _writeSession() {
|
||||
|
@ -41,6 +50,11 @@ class TestCacheSession extends CacheSession {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* TestDatabaseSession
|
||||
*
|
||||
* @package Cake.Test.Case.Model.Datasource
|
||||
*/
|
||||
class TestDatabaseSession extends DatabaseSession {
|
||||
|
||||
protected function _writeSession() {
|
||||
|
@ -72,7 +86,7 @@ class CakeSessionTest extends CakeTestCase {
|
|||
*/
|
||||
public static function setupBeforeClass() {
|
||||
// Make sure garbage colector will be called
|
||||
self::$_gcDivisor = ini_get('session.gc_divisor');
|
||||
static::$_gcDivisor = ini_get('session.gc_divisor');
|
||||
ini_set('session.gc_divisor', '1');
|
||||
}
|
||||
|
||||
|
@ -83,7 +97,7 @@ class CakeSessionTest extends CakeTestCase {
|
|||
*/
|
||||
public static function teardownAfterClass() {
|
||||
// Revert to the default setting
|
||||
ini_set('session.gc_divisor', self::$_gcDivisor);
|
||||
ini_set('session.gc_divisor', static::$_gcDivisor);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -100,7 +114,6 @@ class CakeSessionTest extends CakeTestCase {
|
|||
'cookieTimeout' => 120,
|
||||
'ini' => array(),
|
||||
));
|
||||
TestCakeSession::init();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -108,12 +121,12 @@ class CakeSessionTest extends CakeTestCase {
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function teardown() {
|
||||
public function tearDown() {
|
||||
if (TestCakeSession::started()) {
|
||||
session_write_close();
|
||||
}
|
||||
unset($_SESSION);
|
||||
parent::teardown();
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -231,7 +244,7 @@ class CakeSessionTest extends CakeTestCase {
|
|||
TestCakeSession::write('SessionTestCase', 'value');
|
||||
$this->assertTrue(TestCakeSession::check('SessionTestCase'));
|
||||
|
||||
$this->assertFalse(TestCakeSession::check('NotExistingSessionTestCase'), false);
|
||||
$this->assertFalse(TestCakeSession::check('NotExistingSessionTestCase'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -244,7 +257,7 @@ class CakeSessionTest extends CakeTestCase {
|
|||
$result = TestCakeSession::read('testing');
|
||||
$this->assertEquals('1,2,3', $result);
|
||||
|
||||
TestCakeSession::write('testing', array('1' => 'one', '2' => 'two','3' => 'three'));
|
||||
TestCakeSession::write('testing', array('1' => 'one', '2' => 'two', '3' => 'three'));
|
||||
$result = TestCakeSession::read('testing.1');
|
||||
$this->assertEquals('one', $result);
|
||||
|
||||
|
@ -267,7 +280,7 @@ class CakeSessionTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testReadyEmpty() {
|
||||
$this->assertFalse(TestCakeSession::read(''));
|
||||
$this->assertNull(TestCakeSession::read(''));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -294,9 +307,9 @@ class CakeSessionTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testWriteEmptyKey() {
|
||||
$this->assertFalse(TestCakeSession::write('', 'graham'));
|
||||
$this->assertFalse(TestCakeSession::write('', ''));
|
||||
$this->assertFalse(TestCakeSession::write(''));
|
||||
$this->assertTrue(TestCakeSession::write('', 'graham'));
|
||||
$this->assertTrue(TestCakeSession::write('', ''));
|
||||
$this->assertTrue(TestCakeSession::write(''));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -315,6 +328,28 @@ class CakeSessionTest extends CakeTestCase {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test consuming session data.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConsume() {
|
||||
TestCakeSession::write('Some.string', 'value');
|
||||
TestCakeSession::write('Some.array', array('key1' => 'value1', 'key2' => 'value2'));
|
||||
$this->assertEquals('value', TestCakeSession::read('Some.string'));
|
||||
$value = TestCakeSession::consume('Some.string');
|
||||
$this->assertEquals('value', $value);
|
||||
$this->assertFalse(TestCakeSession::check('Some.string'));
|
||||
$value = TestCakeSession::consume('');
|
||||
$this->assertNull($value);
|
||||
$value = TestCakeSession::consume(null);
|
||||
$this->assertNull($value);
|
||||
$value = TestCakeSession::consume('Some.array');
|
||||
$expected = array('key1' => 'value1', 'key2' => 'value2');
|
||||
$this->assertEquals($expected, $value);
|
||||
$this->assertFalse(TestCakeSession::check('Some.array'));
|
||||
}
|
||||
|
||||
/**
|
||||
* testId method
|
||||
*
|
||||
|
@ -346,21 +381,6 @@ class CakeSessionTest extends CakeTestCase {
|
|||
$this->assertTrue(TestCakeSession::started());
|
||||
}
|
||||
|
||||
/**
|
||||
* testError method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testError() {
|
||||
TestCakeSession::read('Does.not.exist');
|
||||
$result = TestCakeSession::error();
|
||||
$this->assertEquals("Does.not.exist doesn't exist", $result);
|
||||
|
||||
TestCakeSession::delete('Failing.delete');
|
||||
$result = TestCakeSession::error();
|
||||
$this->assertEquals("Failing.delete doesn't exist", $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testDel method
|
||||
*
|
||||
|
@ -373,11 +393,47 @@ class CakeSessionTest extends CakeTestCase {
|
|||
$this->assertTrue(TestCakeSession::check('Delete'));
|
||||
|
||||
$this->assertTrue(TestCakeSession::write('Clearing.sale', 'everything must go'));
|
||||
$this->assertFalse(TestCakeSession::delete(''));
|
||||
$this->assertTrue(TestCakeSession::check('Clearing.sale'));
|
||||
$this->assertFalse(TestCakeSession::delete(null));
|
||||
$this->assertTrue(TestCakeSession::check('Clearing.sale'));
|
||||
|
||||
$this->assertTrue(TestCakeSession::delete('Clearing'));
|
||||
$this->assertFalse(TestCakeSession::check('Clearing.sale'));
|
||||
$this->assertFalse(TestCakeSession::check('Clearing'));
|
||||
}
|
||||
|
||||
/**
|
||||
* test delete
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDeleteEmptyString() {
|
||||
TestCakeSession::write('', 'empty string');
|
||||
$this->assertTrue(TestCakeSession::delete(''));
|
||||
$this->assertFalse(TestCakeSession::check(''));
|
||||
}
|
||||
|
||||
/**
|
||||
* testClear method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testClear() {
|
||||
$this->assertTrue(TestCakeSession::write('Delete.me', 'Clearing out'));
|
||||
TestCakeSession::clear(false);
|
||||
$this->assertFalse(TestCakeSession::check('Delete.me'));
|
||||
$this->assertFalse(TestCakeSession::check('Delete'));
|
||||
|
||||
TestCakeSession::write('Some.string', 'value');
|
||||
TestCakeSession::clear(false);
|
||||
$this->assertNull(TestCakeSession::read('Some'));
|
||||
|
||||
TestCakeSession::write('Some.string.array', array('values'));
|
||||
TestCakeSession::clear(false);
|
||||
$this->assertFalse(TestCakeSession::read());
|
||||
}
|
||||
|
||||
/**
|
||||
* testDestroy method
|
||||
*
|
||||
|
@ -431,7 +487,8 @@ class CakeSessionTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testCheckEmpty() {
|
||||
$this->assertFalse(TestCakeSession::check());
|
||||
$this->assertFalse(TestCakeSession::check(''));
|
||||
$this->assertFalse(TestCakeSession::check(null));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -442,10 +499,10 @@ class CakeSessionTest extends CakeTestCase {
|
|||
public function testKeyExploit() {
|
||||
$key = "a'] = 1; phpinfo(); \$_SESSION['a";
|
||||
$result = TestCakeSession::write($key, 'haxored');
|
||||
$this->assertTrue($result);
|
||||
$this->assertFalse($result);
|
||||
|
||||
$result = TestCakeSession::read($key);
|
||||
$this->assertEquals('haxored', $result);
|
||||
$this->assertNull($result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -454,6 +511,10 @@ class CakeSessionTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testReadingSavedEmpty() {
|
||||
TestCakeSession::write('', 'empty string');
|
||||
$this->assertTrue(TestCakeSession::check(''));
|
||||
$this->assertEquals('empty string', TestCakeSession::read(''));
|
||||
|
||||
TestCakeSession::write('SessionTestCase', 0);
|
||||
$this->assertEquals(0, TestCakeSession::read('SessionTestCase'));
|
||||
|
||||
|
@ -465,7 +526,23 @@ class CakeSessionTest extends CakeTestCase {
|
|||
$this->assertFalse(TestCakeSession::read('SessionTestCase'));
|
||||
|
||||
TestCakeSession::write('SessionTestCase', null);
|
||||
$this->assertEquals(null, TestCakeSession::read('SessionTestCase'));
|
||||
$this->assertNull(TestCakeSession::read('SessionTestCase'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test te cacheLimiter settings.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCacheLimiter() {
|
||||
Configure::write('Session.cacheLimiter', 'public');
|
||||
TestCakeSession::start();
|
||||
$this->assertSame('public', session_cache_limiter());
|
||||
|
||||
Configure::write('Session.cacheLimiter', 'private');
|
||||
TestCakeSession::destroy();
|
||||
TestCakeSession::start();
|
||||
$this->assertSame('private', session_cache_limiter());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -547,9 +624,13 @@ class CakeSessionTest extends CakeTestCase {
|
|||
'engine' => 'TestAppLibSession'
|
||||
)
|
||||
));
|
||||
TestCakeSession::destroy();
|
||||
|
||||
TestCakeSession::start();
|
||||
$this->assertTrue(TestCakeSession::started());
|
||||
|
||||
TestCakeSession::destroy();
|
||||
$this->assertFalse(TestCakeSession::started());
|
||||
|
||||
App::build();
|
||||
}
|
||||
|
||||
|
@ -571,9 +652,12 @@ class CakeSessionTest extends CakeTestCase {
|
|||
)
|
||||
));
|
||||
|
||||
TestCakeSession::destroy();
|
||||
TestCakeSession::start();
|
||||
$this->assertTrue(TestCakeSession::started());
|
||||
|
||||
TestCakeSession::destroy();
|
||||
$this->assertFalse(TestCakeSession::started());
|
||||
|
||||
App::build();
|
||||
}
|
||||
|
||||
|
@ -658,7 +742,7 @@ class CakeSessionTest extends CakeTestCase {
|
|||
$this->assertEquals($expected, TestCakeSession::id());
|
||||
|
||||
TestCakeSession::renew();
|
||||
$this->assertFalse($expected == TestCakeSession::id());
|
||||
$this->assertFalse($expected === TestCakeSession::id());
|
||||
|
||||
$expected = session_id();
|
||||
$this->assertEquals($expected, TestCakeSession::id());
|
||||
|
@ -751,4 +835,31 @@ class CakeSessionTest extends CakeTestCase {
|
|||
$this->assertEquals(400, Configure::read('Session.timeout'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Proves that invalid sessions will be destroyed and re-created
|
||||
* if invalid
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testInvalidSessionRenew() {
|
||||
TestCakeSession::start();
|
||||
$this->assertNotEmpty($_SESSION['Config']);
|
||||
$data = $_SESSION;
|
||||
|
||||
session_write_close();
|
||||
$_SESSION = null;
|
||||
|
||||
TestCakeSession::start();
|
||||
$this->assertEquals($data, $_SESSION);
|
||||
TestCakeSession::write('Foo', 'Bar');
|
||||
|
||||
session_write_close();
|
||||
$_SESSION = null;
|
||||
|
||||
TestCakeSession::userAgent('bogus!');
|
||||
TestCakeSession::start();
|
||||
$this->assertNotEquals($data, $_SESSION);
|
||||
$this->assertEquals('bogus!', $_SESSION['Config']['userAgent']);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,19 +2,18 @@
|
|||
/**
|
||||
* DataSourceTest file
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The Open Group Test Suite License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
||||
* @package Cake.Test.Case.Model.Datasource
|
||||
* @since CakePHP(tm) v 1.2.0.4206
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('Model', 'Model');
|
||||
|
@ -58,7 +57,7 @@ class TestSource extends DataSource {
|
|||
/**
|
||||
* listSources
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function listSources() {
|
||||
return null;
|
||||
|
@ -67,7 +66,7 @@ class TestSource extends DataSource {
|
|||
/**
|
||||
* Returns the schema for the datasource to enable create/update
|
||||
*
|
||||
* @param object $Model
|
||||
* @param Model $Model
|
||||
* @return array
|
||||
*/
|
||||
public function describe(Model $Model) {
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -2,19 +2,17 @@
|
|||
/**
|
||||
* DboPostgresTest file
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.Test.Case.Model.Datasource.Database
|
||||
* @since CakePHP(tm) v 1.2.0
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('Model', 'Model');
|
||||
|
@ -66,17 +64,10 @@ class DboPostgresTestDb extends Postgres {
|
|||
*/
|
||||
class PostgresTestModel extends Model {
|
||||
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'PostgresTestModel'
|
||||
*/
|
||||
public $name = 'PostgresTestModel';
|
||||
|
||||
/**
|
||||
* useTable property
|
||||
*
|
||||
* @var bool false
|
||||
* @var bool
|
||||
*/
|
||||
public $useTable = false;
|
||||
|
||||
|
@ -141,7 +132,8 @@ class PostgresTestModel extends Model {
|
|||
'comments' => array('type' => 'text', 'null' => '1', 'default' => '', 'length' => ''),
|
||||
'last_login' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => ''),
|
||||
'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
|
||||
'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
|
||||
'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null),
|
||||
'some_uuid' => array('type' => 'uuid', 'null' => '1', 'default' => null),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -154,17 +146,10 @@ class PostgresTestModel extends Model {
|
|||
*/
|
||||
class PostgresClientTestModel extends Model {
|
||||
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'PostgresClientTestModel'
|
||||
*/
|
||||
public $name = 'PostgresClientTestModel';
|
||||
|
||||
/**
|
||||
* useTable property
|
||||
*
|
||||
* @var bool false
|
||||
* @var bool
|
||||
*/
|
||||
public $useTable = false;
|
||||
|
||||
|
@ -178,8 +163,8 @@ class PostgresClientTestModel extends Model {
|
|||
'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8', 'key' => 'primary'),
|
||||
'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
|
||||
'email' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
|
||||
'created' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => ''),
|
||||
'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
|
||||
'created' => array('type' => 'datetime', 'null' => true, 'default' => null, 'length' => ''),
|
||||
'updated' => array('type' => 'datetime', 'null' => true, 'default' => null, 'length' => null)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -196,7 +181,7 @@ class PostgresTest extends CakeTestCase {
|
|||
* Do not automatically load fixtures for each test, they will be loaded manually
|
||||
* using CakeTestCase::loadFixtures
|
||||
*
|
||||
* @var boolean
|
||||
* @var bool
|
||||
*/
|
||||
public $autoFixtures = false;
|
||||
|
||||
|
@ -227,8 +212,10 @@ class PostgresTest extends CakeTestCase {
|
|||
/**
|
||||
* Sets up a Dbo class instance for testing
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
Configure::write('Cache.disable', true);
|
||||
$this->Dbo = ConnectionManager::getDataSource('test');
|
||||
$this->skipIf(!($this->Dbo instanceof Postgres));
|
||||
|
@ -239,8 +226,10 @@ class PostgresTest extends CakeTestCase {
|
|||
/**
|
||||
* Sets up a Dbo class instance for testing
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown() {
|
||||
parent::tearDown();
|
||||
Configure::write('Cache.disable', false);
|
||||
unset($this->Dbo2);
|
||||
}
|
||||
|
@ -248,6 +237,7 @@ class PostgresTest extends CakeTestCase {
|
|||
/**
|
||||
* Test field quoting method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFieldQuoting() {
|
||||
$fields = array(
|
||||
|
@ -268,7 +258,8 @@ class PostgresTest extends CakeTestCase {
|
|||
'"PostgresTestModel"."comments" AS "PostgresTestModel__comments"',
|
||||
'"PostgresTestModel"."last_login" AS "PostgresTestModel__last_login"',
|
||||
'"PostgresTestModel"."created" AS "PostgresTestModel__created"',
|
||||
'"PostgresTestModel"."updated" AS "PostgresTestModel__updated"'
|
||||
'"PostgresTestModel"."updated" AS "PostgresTestModel__updated"',
|
||||
'"PostgresTestModel"."some_uuid" AS "PostgresTestModel__some_uuid"'
|
||||
);
|
||||
|
||||
$result = $this->Dbo->fields($this->model);
|
||||
|
@ -307,6 +298,15 @@ class PostgresTest extends CakeTestCase {
|
|||
$this->assertEquals('string', $this->Dbo2->column('character varying'));
|
||||
$this->assertEquals('time', $this->Dbo2->column('time without time zone'));
|
||||
$this->assertEquals('datetime', $this->Dbo2->column('timestamp without time zone'));
|
||||
$this->assertEquals('decimal', $this->Dbo2->column('decimal'));
|
||||
$this->assertEquals('decimal', $this->Dbo2->column('numeric'));
|
||||
$this->assertEquals('float', $this->Dbo2->column('float'));
|
||||
$this->assertEquals('float', $this->Dbo2->column('double precision'));
|
||||
$this->assertEquals('uuid', $this->Dbo2->column('uuid'));
|
||||
|
||||
$result = $this->Dbo2->column('bigint');
|
||||
$expected = 'biginteger';
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -321,8 +321,8 @@ class PostgresTest extends CakeTestCase {
|
|||
$this->assertEquals("0", $this->Dbo->value('0', 'integer'));
|
||||
$this->assertEquals('NULL', $this->Dbo->value('', 'integer'));
|
||||
$this->assertEquals('NULL', $this->Dbo->value('', 'float'));
|
||||
$this->assertEquals("NULL", $this->Dbo->value('', 'integer', false));
|
||||
$this->assertEquals("NULL", $this->Dbo->value('', 'float', false));
|
||||
$this->assertEquals('""', $this->Dbo->value('', 'integer', false));
|
||||
$this->assertEquals('""', $this->Dbo->value('', 'float', false));
|
||||
$this->assertEquals("'0.0'", $this->Dbo->value('0.0', 'float'));
|
||||
|
||||
$this->assertEquals("'TRUE'", $this->Dbo->value('t', 'boolean'));
|
||||
|
@ -339,6 +339,8 @@ class PostgresTest extends CakeTestCase {
|
|||
$this->assertEquals("'TRUE'", $this->Dbo->value('1', 'boolean'));
|
||||
$this->assertEquals("NULL", $this->Dbo->value(null, 'boolean'));
|
||||
$this->assertEquals("NULL", $this->Dbo->value(array()));
|
||||
$this->assertEquals("'550e8400-e29b-41d4-a716-446655440000'", $this->Dbo->value('550e8400-e29b-41d4-a716-446655440000', 'uuid'));
|
||||
$this->assertEquals("NULL", $this->Dbo->value(null, 'uuid'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -348,7 +350,8 @@ class PostgresTest extends CakeTestCase {
|
|||
*/
|
||||
public function testLocalizedFloats() {
|
||||
$restore = setlocale(LC_NUMERIC, 0);
|
||||
setlocale(LC_NUMERIC, 'de_DE');
|
||||
|
||||
$this->skipIf(setlocale(LC_NUMERIC, 'de_DE') === false, "The German locale isn't available.");
|
||||
|
||||
$result = $this->db->value(3.141593, 'float');
|
||||
$this->assertEquals("3.141593", $result);
|
||||
|
@ -482,6 +485,22 @@ class PostgresTest extends CakeTestCase {
|
|||
$this->assertEquals($data, $result['BinaryTest']['data']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests passing PostgreSQL regular expression operators when building queries
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testRegexpOperatorConditionsParsing() {
|
||||
$this->assertSame(' WHERE "name" ~ \'[a-z_]+\'', $this->Dbo->conditions(array('name ~' => '[a-z_]+')));
|
||||
$this->assertSame(' WHERE "name" ~* \'[a-z_]+\'', $this->Dbo->conditions(array('name ~*' => '[a-z_]+')));
|
||||
$this->assertSame(' WHERE "name" !~ \'[a-z_]+\'', $this->Dbo->conditions(array('name !~' => '[a-z_]+')));
|
||||
$this->assertSame(' WHERE "name" !~* \'[a-z_]+\'', $this->Dbo->conditions(array('name !~*' => '[a-z_]+')));
|
||||
$this->assertSame(
|
||||
' WHERE EXTRACT( \'YEAR\' FROM "User"."birthday" ) = 2015',
|
||||
$this->Dbo->conditions(array('EXTRACT( \'YEAR\' FROM User.birthday )' => 2015))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the syntax of generated schema indexes
|
||||
*
|
||||
|
@ -530,23 +549,27 @@ class PostgresTest extends CakeTestCase {
|
|||
id serial NOT NULL,
|
||||
"varchar" character varying(40) NOT NULL,
|
||||
"full_length" character varying NOT NULL,
|
||||
"huge_int" bigint NOT NULL,
|
||||
"timestamp" timestamp without time zone,
|
||||
"date" date,
|
||||
CONSTRAINT test_data_types_pkey PRIMARY KEY (id)
|
||||
)');
|
||||
|
||||
$model = new Model(array('name' => 'DatatypeTest', 'ds' => 'test'));
|
||||
$schema = new CakeSchema(array('connection' => 'test'));
|
||||
$result = $schema->read(array(
|
||||
'connection' => 'test',
|
||||
'models' => array('DatatypeTest')
|
||||
));
|
||||
$schema->tables = array('datatype_tests' => $result['tables']['missing']['datatype_tests']);
|
||||
|
||||
$schema->tables = array(
|
||||
'datatype_tests' => $result['tables']['missing']['datatype_tests']
|
||||
);
|
||||
$result = $db1->createSchema($schema, 'datatype_tests');
|
||||
|
||||
$this->assertNotRegExp('/timestamp DEFAULT/', $result);
|
||||
$this->assertRegExp('/\"full_length\"\s*text\s.*,/', $result);
|
||||
$this->assertRegExp('/timestamp\s*,/', $result);
|
||||
$this->assertContains('timestamp ,', $result);
|
||||
$this->assertContains('"huge_int" bigint NOT NULL,', $result);
|
||||
|
||||
$db1->query('DROP TABLE ' . $db1->fullTableName('datatype_tests'));
|
||||
|
||||
|
@ -562,6 +585,38 @@ class PostgresTest extends CakeTestCase {
|
|||
$db1->query('DROP TABLE ' . $db1->fullTableName('datatype_tests'));
|
||||
}
|
||||
|
||||
/**
|
||||
* testCakeSchemaBegserial method
|
||||
*
|
||||
* Test that schema generated postgresql queries are valid.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCakeSchemaBigserial() {
|
||||
$db1 = ConnectionManager::getDataSource('test');
|
||||
$db1->cacheSources = false;
|
||||
|
||||
$db1->rawQuery('CREATE TABLE ' . $db1->fullTableName('bigserial_tests') . ' (
|
||||
"id" bigserial NOT NULL,
|
||||
"varchar" character varying(40) NOT NULL,
|
||||
PRIMARY KEY ("id")
|
||||
)');
|
||||
|
||||
$schema = new CakeSchema(array('connection' => 'test'));
|
||||
$result = $schema->read(array(
|
||||
'connection' => 'test',
|
||||
'models' => array('BigserialTest')
|
||||
));
|
||||
$schema->tables = array(
|
||||
'bigserial_tests' => $result['tables']['missing']['bigserial_tests']
|
||||
);
|
||||
$result = $db1->createSchema($schema, 'bigserial_tests');
|
||||
|
||||
$this->assertContains('"id" bigserial NOT NULL,', $result);
|
||||
|
||||
$db1->query('DROP TABLE ' . $db1->fullTableName('bigserial_tests'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test index generation from table info.
|
||||
*
|
||||
|
@ -657,6 +712,70 @@ class PostgresTest extends CakeTestCase {
|
|||
$this->assertNotRegExp('/varchar\(36\) NOT NULL/i', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the alterSchema changing boolean to integer
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAlterSchemaBooleanToIntegerField() {
|
||||
$default = array(
|
||||
'connection' => 'test',
|
||||
'name' => 'BoolField',
|
||||
'bool_fields' => array(
|
||||
'id' => array('type' => 'integer', 'key' => 'primary'),
|
||||
'name' => array('type' => 'string', 'length' => 50),
|
||||
'active' => array('type' => 'boolean', 'null' => false),
|
||||
)
|
||||
);
|
||||
$Old = new CakeSchema($default);
|
||||
$result = $this->Dbo->query($this->Dbo->createSchema($Old));
|
||||
$this->assertTrue($result);
|
||||
|
||||
$modified = $default;
|
||||
$modified['bool_fields']['active'] = array('type' => 'integer', 'null' => true);
|
||||
|
||||
$New = new CakeSchema($modified);
|
||||
$query = $this->Dbo->alterSchema($New->compare($Old));
|
||||
$result = $this->Dbo->query($query);
|
||||
$this->Dbo->query($this->Dbo->dropSchema($Old));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the alterSchema changing text to integer
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAlterSchemaTextToIntegerField() {
|
||||
$default = array(
|
||||
'connection' => 'test',
|
||||
'name' => 'TextField',
|
||||
'text_fields' => array(
|
||||
'id' => array('type' => 'integer', 'key' => 'primary'),
|
||||
'name' => array('type' => 'string', 'length' => 50),
|
||||
'active' => array('type' => 'text', 'null' => false),
|
||||
)
|
||||
);
|
||||
$Old = new CakeSchema($default);
|
||||
$result = $this->Dbo->query($this->Dbo->createSchema($Old));
|
||||
$this->assertTrue($result);
|
||||
|
||||
$modified = $default;
|
||||
$modified['text_fields']['active'] = array('type' => 'integer', 'null' => true);
|
||||
|
||||
$New = new CakeSchema($modified);
|
||||
$this->Dbo->query($this->Dbo->alterSchema($New->compare($Old)));
|
||||
$result = $this->Dbo->describe('text_fields');
|
||||
|
||||
$this->Dbo->query($this->Dbo->dropSchema($Old));
|
||||
$expected = array(
|
||||
'type' => 'integer',
|
||||
'null' => true,
|
||||
'default' => null,
|
||||
'length' => null,
|
||||
);
|
||||
$this->assertEquals($expected, $result['active']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the alter index capabilities of postgres
|
||||
*
|
||||
|
@ -732,6 +851,25 @@ class PostgresTest extends CakeTestCase {
|
|||
$this->Dbo->query($this->Dbo->dropSchema($schema1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the alterSchema RENAME statements
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAlterSchemaRenameTo() {
|
||||
$query = $this->Dbo->alterSchema(array(
|
||||
'posts' => array(
|
||||
'change' => array(
|
||||
'title' => array('name' => 'subject', 'type' => 'string', 'null' => false)
|
||||
)
|
||||
)
|
||||
));
|
||||
$this->assertContains('RENAME "title" TO "subject";', $query);
|
||||
$this->assertContains('ALTER COLUMN "subject" TYPE', $query);
|
||||
$this->assertNotContains(";\n\tALTER COLUMN \"subject\" TYPE", $query);
|
||||
$this->assertNotContains('ALTER COLUMN "title" TYPE "subject"', $query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test it is possible to use virtual field with postgresql
|
||||
*
|
||||
|
@ -915,6 +1053,7 @@ class PostgresTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testNestedTransaction() {
|
||||
$this->Dbo->useNestedTransactions = true;
|
||||
$this->skipIf($this->Dbo->nestedTransactionSupported() === false, 'The Postgres server do not support nested transaction');
|
||||
|
||||
$this->loadFixtures('Article');
|
||||
|
@ -942,4 +1081,141 @@ class PostgresTest extends CakeTestCase {
|
|||
$this->assertNotEmpty($model->read(null, 1));
|
||||
}
|
||||
|
||||
public function testResetSequence() {
|
||||
$model = new Article();
|
||||
|
||||
$table = $this->Dbo->fullTableName($model, false);
|
||||
$fields = array(
|
||||
'id', 'user_id', 'title', 'body', 'published',
|
||||
);
|
||||
$values = array(
|
||||
array(1, 1, 'test', 'first post', false),
|
||||
array(2, 1, 'test 2', 'second post post', false),
|
||||
);
|
||||
$this->Dbo->insertMulti($table, $fields, $values);
|
||||
$sequence = $this->Dbo->getSequence($table);
|
||||
$result = $this->Dbo->rawQuery("SELECT nextval('$sequence')");
|
||||
$original = $result->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
$this->assertTrue($this->Dbo->resetSequence($table, 'id'));
|
||||
$result = $this->Dbo->rawQuery("SELECT currval('$sequence')");
|
||||
$new = $result->fetch(PDO::FETCH_ASSOC);
|
||||
$this->assertTrue($new['currval'] > $original['nextval'], 'Sequence did not update');
|
||||
}
|
||||
|
||||
public function testSettings() {
|
||||
Configure::write('Cache.disable', true);
|
||||
$this->Dbo = ConnectionManager::getDataSource('test');
|
||||
$this->skipIf(!($this->Dbo instanceof Postgres));
|
||||
|
||||
$config2 = $this->Dbo->config;
|
||||
$config2['settings']['datestyle'] = 'sql, dmy';
|
||||
ConnectionManager::create('test2', $config2);
|
||||
$dbo2 = new Postgres($config2, true);
|
||||
$expected = array(array('r' => date('d/m/Y')));
|
||||
$r = $dbo2->fetchRow('SELECT now()::date AS "r"');
|
||||
$this->assertEquals($expected, $r);
|
||||
$dbo2->execute('SET DATESTYLE TO ISO');
|
||||
$dbo2->disconnect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the limit function.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testLimit() {
|
||||
$db = $this->Dbo;
|
||||
|
||||
$result = $db->limit('0');
|
||||
$this->assertNull($result);
|
||||
|
||||
$result = $db->limit('10');
|
||||
$this->assertEquals(' LIMIT 10', $result);
|
||||
|
||||
$result = $db->limit('FARTS', 'BOOGERS');
|
||||
$this->assertEquals(' LIMIT 0 OFFSET 0', $result);
|
||||
|
||||
$result = $db->limit(20, 10);
|
||||
$this->assertEquals(' LIMIT 20 OFFSET 10', $result);
|
||||
|
||||
$result = $db->limit(10, 300000000000000000000000000000);
|
||||
$scientificNotation = sprintf('%.1E', 300000000000000000000000000000);
|
||||
$this->assertNotContains($scientificNotation, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that postgres describes UUID columns correctly.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDescribeUuid() {
|
||||
$db = $this->Dbo;
|
||||
$db->execute('CREATE TABLE test_uuid_describe (id UUID PRIMARY KEY, name VARCHAR(255))');
|
||||
$data = $db->describe('test_uuid_describe');
|
||||
|
||||
$expected = array(
|
||||
'type' => 'uuid',
|
||||
'null' => false,
|
||||
'default' => null,
|
||||
'length' => 36,
|
||||
);
|
||||
$this->assertSame($expected, $data['id']);
|
||||
$db->execute('DROP TABLE test_uuid_describe');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test describe() behavior for timestamp columns.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDescribeTimestamp() {
|
||||
$this->loadFixtures('User');
|
||||
$model = ClassRegistry::init('User');
|
||||
$result = $this->Dbo->describe($model);
|
||||
$expected = array(
|
||||
'id' => array(
|
||||
'type' => 'integer',
|
||||
'null' => false,
|
||||
'default' => null,
|
||||
'length' => 11,
|
||||
'key' => 'primary'
|
||||
),
|
||||
'user' => array(
|
||||
'type' => 'string',
|
||||
'null' => true,
|
||||
'default' => null,
|
||||
'length' => 255
|
||||
),
|
||||
'password' => array(
|
||||
'type' => 'string',
|
||||
'null' => true,
|
||||
'default' => null,
|
||||
'length' => 255
|
||||
),
|
||||
'created' => array(
|
||||
'type' => 'datetime',
|
||||
'null' => true,
|
||||
'default' => null,
|
||||
'length' => null
|
||||
),
|
||||
'updated' => array(
|
||||
'type' => 'datetime',
|
||||
'null' => true,
|
||||
'default' => null,
|
||||
'length' => null
|
||||
)
|
||||
);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test build column working for new uuid types
|
||||
*/
|
||||
public function testBuildColumnUuid() {
|
||||
$column = array('name' => 'col1', 'type' => 'uuid');
|
||||
$result = $this->Dbo2->buildColumn($column);
|
||||
|
||||
$this->assertEquals('"col1" uuid', $result);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,20 +2,20 @@
|
|||
/**
|
||||
* DboSqliteTest file
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.Test.Case.Model.Datasource.Database
|
||||
* @since CakePHP(tm) v 1.2.0
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('Model', 'Model');
|
||||
App::uses('AppModel', 'Model');
|
||||
App::uses('Sqlite', 'Model/Datasource/Database');
|
||||
|
@ -68,7 +68,7 @@ class SqliteTest extends CakeTestCase {
|
|||
/**
|
||||
* Do not automatically load fixtures for each test, they will be loaded manually using CakeTestCase::loadFixtures
|
||||
*
|
||||
* @var boolean
|
||||
* @var bool
|
||||
*/
|
||||
public $autoFixtures = false;
|
||||
|
||||
|
@ -77,7 +77,7 @@ class SqliteTest extends CakeTestCase {
|
|||
*
|
||||
* @var object
|
||||
*/
|
||||
public $fixtures = array('core.user', 'core.uuid');
|
||||
public $fixtures = array('core.user', 'core.uuid', 'core.datatype');
|
||||
|
||||
/**
|
||||
* Actual DB connection used in testing
|
||||
|
@ -89,6 +89,7 @@ class SqliteTest extends CakeTestCase {
|
|||
/**
|
||||
* Sets up a Dbo class instance for testing
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
@ -102,6 +103,7 @@ class SqliteTest extends CakeTestCase {
|
|||
/**
|
||||
* Sets up a Dbo class instance for testing
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown() {
|
||||
parent::tearDown();
|
||||
|
@ -111,6 +113,7 @@ class SqliteTest extends CakeTestCase {
|
|||
/**
|
||||
* Tests that SELECT queries from DboSqlite::listSources() are not cached
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testTableListCacheDisabling() {
|
||||
$this->assertFalse(in_array('foo_test', $this->Dbo->listSources()));
|
||||
|
@ -157,6 +160,7 @@ class SqliteTest extends CakeTestCase {
|
|||
/**
|
||||
* Tests that cached table descriptions are saved under the sanitized key name
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCacheKeyName() {
|
||||
Configure::write('Cache.disable', false);
|
||||
|
@ -164,8 +168,13 @@ class SqliteTest extends CakeTestCase {
|
|||
$dbName = 'db' . rand() . '$(*%&).db';
|
||||
$this->assertFalse(file_exists(TMP . $dbName));
|
||||
|
||||
$config = $this->Dbo->config;
|
||||
$db = new Sqlite(array_merge($this->Dbo->config, array('database' => TMP . $dbName)));
|
||||
try {
|
||||
$db = new Sqlite(array_merge($this->Dbo->config, array('database' => TMP . $dbName)));
|
||||
} catch (MissingConnectionException $e) {
|
||||
// This might be caused by NTFS file systems, where '*' is a forbidden character. Repeat without this character.
|
||||
$dbName = str_replace('*', '', $dbName);
|
||||
$db = new Sqlite(array_merge($this->Dbo->config, array('database' => TMP . $dbName)));
|
||||
}
|
||||
$this->assertTrue(file_exists(TMP . $dbName));
|
||||
|
||||
$db->execute("CREATE TABLE test_list (id VARCHAR(255));");
|
||||
|
@ -253,6 +262,27 @@ class SqliteTest extends CakeTestCase {
|
|||
$result = $this->Dbo->buildColumn($data);
|
||||
$expected = '"testName" integer(10) DEFAULT 10 NOT NULL';
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$data = array(
|
||||
'name' => 'huge',
|
||||
'type' => 'biginteger',
|
||||
'length' => 20,
|
||||
'null' => false,
|
||||
);
|
||||
$result = $this->Dbo->buildColumn($data);
|
||||
$expected = '"huge" bigint(20) NOT NULL';
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$data = array(
|
||||
'name' => 'id',
|
||||
'type' => 'biginteger',
|
||||
'length' => 20,
|
||||
'null' => false,
|
||||
'key' => 'primary',
|
||||
);
|
||||
$result = $this->Dbo->buildColumn($data);
|
||||
$expected = '"id" bigint(20) NOT NULL PRIMARY KEY';
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -262,7 +292,11 @@ class SqliteTest extends CakeTestCase {
|
|||
*/
|
||||
public function testDescribe() {
|
||||
$this->loadFixtures('User');
|
||||
$Model = new Model(array('name' => 'User', 'ds' => 'test', 'table' => 'users'));
|
||||
$Model = new Model(array(
|
||||
'name' => 'User',
|
||||
'ds' => 'test',
|
||||
'table' => 'users'
|
||||
));
|
||||
|
||||
$this->Dbo->cacheSources = true;
|
||||
Configure::write('Cache.disable', false);
|
||||
|
@ -310,6 +344,55 @@ class SqliteTest extends CakeTestCase {
|
|||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that datatypes are reflected
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDatatypes() {
|
||||
$this->loadFixtures('Datatype');
|
||||
$Model = new Model(array(
|
||||
'name' => 'Datatype',
|
||||
'ds' => 'test',
|
||||
'table' => 'datatypes'
|
||||
));
|
||||
$result = $this->Dbo->describe($Model);
|
||||
$expected = array(
|
||||
'id' => array(
|
||||
'type' => 'integer',
|
||||
'null' => false,
|
||||
'default' => '',
|
||||
'length' => 11,
|
||||
'key' => 'primary',
|
||||
),
|
||||
'float_field' => array(
|
||||
'type' => 'float',
|
||||
'null' => false,
|
||||
'default' => '',
|
||||
'length' => '5,2',
|
||||
),
|
||||
'decimal_field' => array(
|
||||
'type' => 'decimal',
|
||||
'null' => true,
|
||||
'default' => '0.000',
|
||||
'length' => '6,3',
|
||||
),
|
||||
'huge_int' => array(
|
||||
'type' => 'biginteger',
|
||||
'null' => true,
|
||||
'default' => null,
|
||||
'length' => 20,
|
||||
),
|
||||
'bool' => array(
|
||||
'type' => 'boolean',
|
||||
'null' => false,
|
||||
'default' => '0',
|
||||
'length' => null
|
||||
),
|
||||
);
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that describe does not corrupt UUID primary keys
|
||||
*
|
||||
|
@ -345,6 +428,40 @@ class SqliteTest extends CakeTestCase {
|
|||
$this->Dbo->query('DROP TABLE ' . $tableName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that describe ignores `default current_timestamp` in timestamp columns.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDescribeHandleCurrentTimestamp() {
|
||||
$name = $this->Dbo->fullTableName('timestamp_default_values');
|
||||
$sql = <<<SQL
|
||||
CREATE TABLE $name (
|
||||
id INT NOT NULL,
|
||||
phone VARCHAR(10),
|
||||
limit_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
SQL;
|
||||
$this->Dbo->execute($sql);
|
||||
$model = new Model(array(
|
||||
'table' => 'timestamp_default_values',
|
||||
'ds' => 'test',
|
||||
'alias' => 'TimestampDefaultValue'
|
||||
));
|
||||
$result = $this->Dbo->describe($model);
|
||||
$this->Dbo->execute('DROP TABLE ' . $name);
|
||||
|
||||
$this->assertNull($result['limit_date']['default']);
|
||||
|
||||
$schema = new CakeSchema(array(
|
||||
'connection' => 'test',
|
||||
'testdescribes' => $result
|
||||
));
|
||||
$result = $this->Dbo->createSchema($schema);
|
||||
$this->assertContains('"limit_date" timestamp NOT NULL', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test virtualFields with functions.
|
||||
*
|
||||
|
@ -362,7 +479,7 @@ class SqliteTest extends CakeTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test that records can be inserted with uuid primary keys, and
|
||||
* Test that records can be inserted with UUID primary keys, and
|
||||
* that the primary key is not blank
|
||||
*
|
||||
* @return void
|
||||
|
@ -372,7 +489,7 @@ class SqliteTest extends CakeTestCase {
|
|||
$Model = ClassRegistry::init('Uuid');
|
||||
|
||||
$data = array(
|
||||
'title' => 'A uuid should work',
|
||||
'title' => 'A UUID should work',
|
||||
'count' => 10
|
||||
);
|
||||
$Model->create($data);
|
||||
|
@ -380,7 +497,7 @@ class SqliteTest extends CakeTestCase {
|
|||
$result = $Model->read();
|
||||
|
||||
$this->assertEquals($data['title'], $result['Uuid']['title']);
|
||||
$this->assertTrue(Validation::uuid($result['Uuid']['id']), 'Not a uuid');
|
||||
$this->assertTrue(Validation::uuid($result['Uuid']['id']), 'Not a UUID');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -389,6 +506,7 @@ class SqliteTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testNestedTransaction() {
|
||||
$this->Dbo->useNestedTransactions = true;
|
||||
$this->skipIf($this->Dbo->nestedTransactionSupported() === false, 'The Sqlite version do not support nested transaction');
|
||||
|
||||
$this->loadFixtures('User');
|
||||
|
@ -416,4 +534,96 @@ class SqliteTest extends CakeTestCase {
|
|||
$this->assertNotEmpty($model->read(null, 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the limit function.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testLimit() {
|
||||
$db = $this->Dbo;
|
||||
|
||||
$result = $db->limit('0');
|
||||
$this->assertNull($result);
|
||||
|
||||
$result = $db->limit('10');
|
||||
$this->assertEquals(' LIMIT 10', $result);
|
||||
|
||||
$result = $db->limit('FARTS', 'BOOGERS');
|
||||
$this->assertEquals(' LIMIT 0 OFFSET 0', $result);
|
||||
|
||||
$result = $db->limit(20, 10);
|
||||
$this->assertEquals(' LIMIT 20 OFFSET 10', $result);
|
||||
|
||||
$result = $db->limit(10, 300000000000000000000000000000);
|
||||
$scientificNotation = sprintf('%.1E', 300000000000000000000000000000);
|
||||
$this->assertNotContains($scientificNotation, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that fields are parsed out in a reasonable fashion.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFetchRowColumnParsing() {
|
||||
$this->loadFixtures('User');
|
||||
$sql = 'SELECT "User"."id", "User"."user", "User"."password", "User"."created", (1 + 1) AS "two" ' .
|
||||
'FROM "users" AS "User" WHERE ' .
|
||||
'"User"."id" IN (SELECT MAX("id") FROM "users") ' .
|
||||
'OR "User.id" IN (5, 6, 7, 8)';
|
||||
$result = $this->Dbo->fetchRow($sql);
|
||||
|
||||
$expected = array(
|
||||
'User' => array(
|
||||
'id' => 4,
|
||||
'user' => 'garrett',
|
||||
'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
||||
'created' => '2007-03-17 01:22:23'
|
||||
),
|
||||
0 => array(
|
||||
'two' => 2
|
||||
)
|
||||
);
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$sql = 'SELECT "User"."id", "User"."user" ' .
|
||||
'FROM "users" AS "User" WHERE "User"."id" = 4 ' .
|
||||
'UNION ' .
|
||||
'SELECT "User"."id", "User"."user" ' .
|
||||
'FROM "users" AS "User" WHERE "User"."id" = 3';
|
||||
$result = $this->Dbo->fetchRow($sql);
|
||||
|
||||
$expected = array(
|
||||
'User' => array(
|
||||
'id' => 3,
|
||||
'user' => 'larry',
|
||||
),
|
||||
);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test parsing more complex field names.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFetchColumnRowParsingMoreComplex() {
|
||||
$this->loadFixtures('User');
|
||||
$sql = 'SELECT
|
||||
COUNT(*) AS User__count,
|
||||
COUNT(CASE id WHEN 2 THEN 1 ELSE NULL END) as User__case,
|
||||
AVG(CAST("User"."id" AS BIGINT)) AS User__bigint
|
||||
FROM "users" AS "User"
|
||||
WHERE "User"."id" > 0';
|
||||
$result = $this->Dbo->fetchRow($sql);
|
||||
|
||||
$expected = array(
|
||||
'0' => array(
|
||||
'User__count' => '4',
|
||||
'User__case' => '1',
|
||||
'User__bigint' => '2.5',
|
||||
),
|
||||
);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,19 +2,18 @@
|
|||
/**
|
||||
* SqlserverTest file
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.Test.Case.Model.Datasource.Database
|
||||
* @since CakePHP(tm) v 1.2.0
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('Model', 'Model');
|
||||
|
@ -98,7 +97,7 @@ class SqlserverTestDb extends Sqlserver {
|
|||
/**
|
||||
* describe method
|
||||
*
|
||||
* @param object $model
|
||||
* @param Model $model
|
||||
* @return void
|
||||
*/
|
||||
public function describe($model) {
|
||||
|
@ -114,17 +113,10 @@ class SqlserverTestDb extends Sqlserver {
|
|||
*/
|
||||
class SqlserverTestModel extends CakeTestModel {
|
||||
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'SqlserverTestModel'
|
||||
*/
|
||||
public $name = 'SqlserverTestModel';
|
||||
|
||||
/**
|
||||
* useTable property
|
||||
*
|
||||
* @var bool false
|
||||
* @var bool
|
||||
*/
|
||||
public $useTable = false;
|
||||
|
||||
|
@ -187,17 +179,10 @@ class SqlserverTestModel extends CakeTestModel {
|
|||
*/
|
||||
class SqlserverClientTestModel extends CakeTestModel {
|
||||
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'SqlserverAssociatedTestModel'
|
||||
*/
|
||||
public $name = 'SqlserverClientTestModel';
|
||||
|
||||
/**
|
||||
* useTable property
|
||||
*
|
||||
* @var bool false
|
||||
* @var bool
|
||||
*/
|
||||
public $useTable = false;
|
||||
|
||||
|
@ -263,7 +248,7 @@ class SqlserverTest extends CakeTestCase {
|
|||
/**
|
||||
* autoFixtures property
|
||||
*
|
||||
* @var bool false
|
||||
* @var bool
|
||||
*/
|
||||
public $autoFixtures = false;
|
||||
|
||||
|
@ -277,8 +262,10 @@ class SqlserverTest extends CakeTestCase {
|
|||
/**
|
||||
* Sets up a Dbo class instance for testing
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->Dbo = ConnectionManager::getDataSource('test');
|
||||
if (!($this->Dbo instanceof Sqlserver)) {
|
||||
$this->markTestSkipped('Please configure the test datasource to use SQL Server.');
|
||||
|
@ -293,6 +280,7 @@ class SqlserverTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function tearDown() {
|
||||
parent::tearDown();
|
||||
unset($this->Dbo);
|
||||
unset($this->model);
|
||||
}
|
||||
|
@ -322,6 +310,10 @@ class SqlserverTest extends CakeTestCase {
|
|||
$expected = "''";
|
||||
$result = $this->db->value('', 'binary');
|
||||
$this->assertSame($expected, $result);
|
||||
|
||||
$expected = 'NULL';
|
||||
$result = $this->db->value(null, 'string');
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -447,7 +439,25 @@ class SqlserverTest extends CakeTestCase {
|
|||
'Length' => 72,
|
||||
'Null' => 'NO',
|
||||
'Size' => ''
|
||||
)
|
||||
),
|
||||
(object)array(
|
||||
'Default' => null,
|
||||
'Field' => 'parent_id',
|
||||
'Key' => '0',
|
||||
'Type' => 'bigint',
|
||||
'Length' => 8,
|
||||
'Null' => 'YES',
|
||||
'Size' => '0',
|
||||
),
|
||||
(object)array(
|
||||
'Default' => null,
|
||||
'Field' => 'description',
|
||||
'Key' => '0',
|
||||
'Type' => 'text',
|
||||
'Length' => 16,
|
||||
'Null' => 'YES',
|
||||
'Size' => '0',
|
||||
),
|
||||
));
|
||||
$this->db->executeResultsStack = array($SqlserverTableDescription);
|
||||
$dummyModel = $this->model;
|
||||
|
@ -477,9 +487,22 @@ class SqlserverTest extends CakeTestCase {
|
|||
'default' => '',
|
||||
'length' => 36,
|
||||
'key' => 'primary'
|
||||
),
|
||||
'parent_id' => array(
|
||||
'type' => 'biginteger',
|
||||
'null' => true,
|
||||
'default' => null,
|
||||
'length' => 8,
|
||||
),
|
||||
'description' => array(
|
||||
'type' => 'text',
|
||||
'null' => true,
|
||||
'default' => null,
|
||||
'length' => null,
|
||||
)
|
||||
);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertSame($expected['parent_id'], $result['parent_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -553,6 +576,14 @@ class SqlserverTest extends CakeTestCase {
|
|||
$result = $this->db->buildColumn($column);
|
||||
$expected = "[checked] bit DEFAULT '1'";
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$column = array(
|
||||
'name' => 'huge',
|
||||
'type' => 'biginteger',
|
||||
);
|
||||
$result = $this->db->buildColumn($column);
|
||||
$expected = "[huge] bigint";
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -2,25 +2,29 @@
|
|||
/**
|
||||
* CacheSessionTest
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.Test.Case.Model.Datasource.Session
|
||||
* @since CakePHP(tm) v 2.0
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('CakeSession', 'Model/Datasource');
|
||||
App::uses('CacheSession', 'Model/Datasource/Session');
|
||||
class_exists('CakeSession');
|
||||
|
||||
/**
|
||||
* CacheSessionTest
|
||||
*
|
||||
* @package Cake.Test.Case.Model.Datasource.Session
|
||||
*/
|
||||
class CacheSessionTest extends CakeTestCase {
|
||||
|
||||
protected static $_sessionBackup;
|
||||
|
@ -35,7 +39,7 @@ class CacheSessionTest extends CakeTestCase {
|
|||
'engine' => 'File',
|
||||
'prefix' => 'session_test_'
|
||||
));
|
||||
self::$_sessionBackup = Configure::read('Session');
|
||||
static::$_sessionBackup = Configure::read('Session');
|
||||
|
||||
Configure::write('Session.handler.config', 'session_test');
|
||||
}
|
||||
|
@ -49,7 +53,7 @@ class CacheSessionTest extends CakeTestCase {
|
|||
Cache::clear(false, 'session_test');
|
||||
Cache::drop('session_test');
|
||||
|
||||
Configure::write('Session', self::$_sessionBackup);
|
||||
Configure::write('Session', static::$_sessionBackup);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -100,6 +104,8 @@ class CacheSessionTest extends CakeTestCase {
|
|||
public function testRead() {
|
||||
$this->storage->write('test_one', 'Some other value');
|
||||
$this->assertEquals('Some other value', $this->storage->read('test_one'), 'Incorrect value.');
|
||||
$this->storage->write('test_two', 0);
|
||||
$this->assertEquals(0, $this->storage->read('test_two'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -114,4 +120,4 @@ class CacheSessionTest extends CakeTestCase {
|
|||
$this->assertFalse(Cache::read('test_one', 'session_test'), 'Value stuck around.');
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,19 +2,18 @@
|
|||
/**
|
||||
* DatabaseSessionTest file
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.Test.Case.Model.Datasource.Session
|
||||
* @since CakePHP(tm) v 2.0
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('Model', 'Model');
|
||||
|
@ -22,10 +21,13 @@ App::uses('CakeSession', 'Model/Datasource');
|
|||
App::uses('DatabaseSession', 'Model/Datasource/Session');
|
||||
class_exists('CakeSession');
|
||||
|
||||
/**
|
||||
* SessionTestModel
|
||||
*
|
||||
* @package Cake.Test.Case.Model.Datasource.Session
|
||||
*/
|
||||
class SessionTestModel extends Model {
|
||||
|
||||
public $name = 'SessionTestModel';
|
||||
|
||||
public $useTable = 'sessions';
|
||||
|
||||
}
|
||||
|
@ -52,7 +54,7 @@ class DatabaseSessionTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public static function setupBeforeClass() {
|
||||
self::$_sessionBackup = Configure::read('Session');
|
||||
static::$_sessionBackup = Configure::read('Session');
|
||||
Configure::write('Session.handler', array(
|
||||
'model' => 'SessionTestModel',
|
||||
));
|
||||
|
@ -65,7 +67,7 @@ class DatabaseSessionTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public static function teardownAfterClass() {
|
||||
Configure::write('Session', self::$_sessionBackup);
|
||||
Configure::write('Session', static::$_sessionBackup);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -96,7 +98,7 @@ class DatabaseSessionTest extends CakeTestCase {
|
|||
*/
|
||||
public function testConstructionSettings() {
|
||||
ClassRegistry::flush();
|
||||
$storage = new DatabaseSession();
|
||||
new DatabaseSession();
|
||||
|
||||
$session = ClassRegistry::getObject('session');
|
||||
$this->assertInstanceOf('SessionTestModel', $session);
|
||||
|
@ -120,19 +122,8 @@ class DatabaseSessionTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testWrite() {
|
||||
$result = $this->storage->write('foo', 'Some value');
|
||||
$expected = array(
|
||||
'Session' => array(
|
||||
'id' => 'foo',
|
||||
'data' => 'Some value',
|
||||
)
|
||||
);
|
||||
$expires = $result['Session']['expires'];
|
||||
unset($result['Session']['expires']);
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$expected = time() + (Configure::read('Session.timeout') * 60);
|
||||
$this->assertWithinMargin($expires, $expected, 1);
|
||||
$this->storage->write('foo', 'Some value');
|
||||
$this->assertEquals($this->storage->read('foo'), 'Some value');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -152,13 +143,10 @@ class DatabaseSessionTest extends CakeTestCase {
|
|||
*/
|
||||
public function testRead() {
|
||||
$this->storage->write('foo', 'Some value');
|
||||
|
||||
$result = $this->storage->read('foo');
|
||||
$expected = 'Some value';
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$result = $this->storage->read('made up value');
|
||||
$this->assertFalse($result);
|
||||
$this->assertEquals($this->storage->read('foo'), 'Some value');
|
||||
$this->storage->write('bar', 0);
|
||||
$this->assertEquals(0, $this->storage->read('bar'));
|
||||
$this->assertSame('', $this->storage->read('made up value'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -170,7 +158,7 @@ class DatabaseSessionTest extends CakeTestCase {
|
|||
$this->storage->write('foo', 'Some value');
|
||||
|
||||
$this->assertTrue($this->storage->destroy('foo'), 'Destroy failed');
|
||||
$this->assertFalse($this->storage->read('foo'), 'Value still present.');
|
||||
$this->assertSame($this->storage->read('foo'), '');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -187,6 +175,58 @@ class DatabaseSessionTest extends CakeTestCase {
|
|||
|
||||
sleep(1);
|
||||
$storage->gc();
|
||||
$this->assertFalse($storage->read('foo'));
|
||||
$this->assertSame($storage->read('foo'), '');
|
||||
}
|
||||
|
||||
/**
|
||||
* testConcurrentInsert
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConcurrentInsert() {
|
||||
$this->skipIf(
|
||||
$this->db instanceof Sqlite,
|
||||
'Sqlite does not throw exceptions when attempting to insert a duplicate primary key'
|
||||
);
|
||||
|
||||
ClassRegistry::removeObject('Session');
|
||||
|
||||
$mockedModel = $this->getMockForModel(
|
||||
'SessionTestModel',
|
||||
array('exists'),
|
||||
array('alias' => 'MockedSessionTestModel', 'table' => 'sessions')
|
||||
);
|
||||
Configure::write('Session.handler.model', 'MockedSessionTestModel');
|
||||
|
||||
$counter = 0;
|
||||
// First save
|
||||
$mockedModel->expects($this->at($counter++))
|
||||
->method('exists')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
// Second save
|
||||
$mockedModel->expects($this->at($counter++))
|
||||
->method('exists')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
// Second save retry
|
||||
$mockedModel->expects($this->at($counter++))
|
||||
->method('exists')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
// Datasource exists check
|
||||
$mockedModel->expects($this->at($counter++))
|
||||
->method('exists')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$this->storage = new DatabaseSession();
|
||||
|
||||
$this->storage->write('foo', 'Some value');
|
||||
$return = $this->storage->read('foo');
|
||||
$this->assertSame('Some value', $return);
|
||||
|
||||
$this->storage->write('foo', 'Some other value');
|
||||
$return = $this->storage->read('foo');
|
||||
$this->assertSame('Some other value', $return);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue