Fixed test cases for successful being built on travis.

This commit is contained in:
Thomas Ploch 2012-03-24 21:32:31 +01:00
parent d748fc7451
commit fda065101b
11 changed files with 79 additions and 33 deletions

View file

@ -1,6 +1,7 @@
language: php language: php
php: php:
- 5.2
- 5.3 - 5.3
- 5.4 - 5.4

View file

@ -250,11 +250,12 @@ class Cache {
* *
* Permanently remove all expired and deleted data * Permanently remove all expired and deleted data
* *
* @param string $config The config name you wish to have garbage collected. Defaults to 'default' * @param string $config [optional] The config name you wish to have garbage collected. Defaults to 'default'
* @param integer $expires [optional] An expires timestamp. Defaults to NULL
* @return void * @return void
*/ */
public static function gc($config = 'default') { public static function gc($config = 'default', $expires = null) {
self::$_engines[$config]->gc(); self::$_engines[$config]->gc($expires);
} }
/** /**

View file

@ -51,9 +51,11 @@ abstract class CacheEngine {
* Garbage collection * Garbage collection
* *
* Permanently remove all expired and deleted data * Permanently remove all expired and deleted data
*
* @param integer $expires [optional] An expires timestamp, invalidataing all data before.
* @return void * @return void
*/ */
public function gc() { public function gc($expires = null) {
} }
/** /**

View file

@ -87,10 +87,11 @@ class FileEngine extends CacheEngine {
/** /**
* Garbage collection. Permanently remove all expired and deleted data * Garbage collection. Permanently remove all expired and deleted data
* *
* @param integer $expires [optional] An expires timestamp, invalidataing all data before.
* @return boolean True if garbage collection was successful, false on failure * @return boolean True if garbage collection was successful, false on failure
*/ */
public function gc() { public function gc($expires = null) {
return $this->clear(true); return $this->clear(true);
} }

View file

@ -180,7 +180,7 @@ class CakeSession {
if (self::started()) { if (self::started()) {
return true; return true;
} }
CakeSession::init(); self::init();
$id = self::id(); $id = self::id();
session_write_close(); session_write_close();
self::_configureSession(); self::_configureSession();
@ -601,8 +601,6 @@ class CakeSession {
if (empty($_SESSION)) { if (empty($_SESSION)) {
$_SESSION = array(); $_SESSION = array();
} }
} elseif (!isset($_SESSION)) {
session_start();
} else { } else {
session_start(); session_start();
} }

View file

@ -43,10 +43,6 @@ class CacheSession implements CakeSessionHandlerInterface {
* @return boolean Success * @return boolean Success
*/ */
public function close() { public function close() {
$probability = mt_rand(1, 150);
if ($probability <= 3) {
Cache::gc();
}
return true; return true;
} }
@ -74,7 +70,7 @@ class CacheSession implements CakeSessionHandlerInterface {
/** /**
* Method called on the destruction of a database session. * Method called on the destruction of a database session.
* *
* @param integer $id ID that uniquely identifies session in database * @param integer $id ID that uniquely identifies session in cache
* @return boolean True for successful delete, false otherwise. * @return boolean True for successful delete, false otherwise.
*/ */
public function destroy($id) { public function destroy($id) {
@ -82,13 +78,22 @@ class CacheSession implements CakeSessionHandlerInterface {
} }
/** /**
* Helper function called on gc for database sessions. * Helper function called on gc for cache sessions.
* *
* @param integer $expires Timestamp (defaults to current time) * @param integer $expires Timestamp (defaults to current time)
* @return boolean Success * @return boolean Success
*/ */
public function gc($expires = null) { public function gc($expires = null) {
return Cache::gc(); return Cache::gc(Configure::read('Session.handler.config'), $expires);
}
/**
* Writes and closes a session
*
* @return void
*/
protected function _writeSession() {
session_write_close();
} }
/** /**
@ -97,7 +102,7 @@ class CacheSession implements CakeSessionHandlerInterface {
* @return void * @return void
*/ */
public function __destruct() { public function __destruct() {
session_write_close(); $this->_writeSession();
} }
} }

View file

@ -79,10 +79,6 @@ class DatabaseSession implements CakeSessionHandlerInterface {
* @return boolean Success * @return boolean Success
*/ */
public function close() { public function close() {
$probability = mt_rand(1, 150);
if ($probability <= 3) {
$this->gc();
}
return true; return true;
} }
@ -144,16 +140,22 @@ class DatabaseSession implements CakeSessionHandlerInterface {
return $this->_model->deleteAll(array($this->_model->alias . ".expires <" => $expires), false, false); return $this->_model->deleteAll(array($this->_model->alias . ".expires <" => $expires), false, false);
} }
/**
* Writes and closes a session
*
* @return void
*/
protected function _writeSession() {
session_write_close();
}
/** /**
* Closes the session before the objects handling it become unavailable * Closes the session before the objects handling it become unavailable
* *
* @return void * @return void
*/ */
public function __destruct() { public function __destruct() {
try { $this->_writeSession();
session_write_close();
} catch (Exception $e) {
}
} }
} }

View file

@ -18,6 +18,8 @@
*/ */
App::uses('CakeSession', 'Model/Datasource'); App::uses('CakeSession', 'Model/Datasource');
App::uses('DatabaseSession', 'Model/Datasource/Session');
App::uses('CacheSession', 'Model/Datasource/Session');
class TestCakeSession extends CakeSession { class TestCakeSession extends CakeSession {
@ -31,6 +33,20 @@ class TestCakeSession extends CakeSession {
} }
class TestCacheSession extends CacheSession {
protected function _writeSession() {
return true;
}
}
class TestDatabaseSession extends DatabaseSession {
protected function _writeSession() {
return true;
}
}
/** /**
* CakeSessionTest class * CakeSessionTest class
* *
@ -92,7 +108,7 @@ class CakeSessionTest extends CakeTestCase {
*/ */
public function teardown() { public function teardown() {
if (TestCakeSession::started()) { if (TestCakeSession::started()) {
TestCakeSession::clear(); session_write_close();
} }
unset($_SESSION); unset($_SESSION);
parent::teardown(); parent::teardown();
@ -550,6 +566,7 @@ class CakeSessionTest extends CakeTestCase {
*/ */
public function testReadAndWriteWithCacheStorage() { public function testReadAndWriteWithCacheStorage() {
Configure::write('Session.defaults', 'cache'); Configure::write('Session.defaults', 'cache');
Configure::write('Session.handler.engine', 'TestCacheSession');
TestCakeSession::init(); TestCakeSession::init();
TestCakeSession::destroy(); TestCakeSession::destroy();
@ -585,6 +602,7 @@ class CakeSessionTest extends CakeTestCase {
*/ */
public function testReadAndWriteWithCustomCacheConfig() { public function testReadAndWriteWithCustomCacheConfig() {
Configure::write('Session.defaults', 'cache'); Configure::write('Session.defaults', 'cache');
Configure::write('Session.handler.engine', 'TestCacheSession');
Configure::write('Session.handler.config', 'session_test'); Configure::write('Session.handler.config', 'session_test');
Cache::config('session_test', array( Cache::config('session_test', array(
@ -609,6 +627,7 @@ class CakeSessionTest extends CakeTestCase {
*/ */
public function testReadAndWriteWithDatabaseStorage() { public function testReadAndWriteWithDatabaseStorage() {
Configure::write('Session.defaults', 'database'); Configure::write('Session.defaults', 'database');
Configure::write('Session.handler.engine', 'TestDatabaseSession');
Configure::write('Session.handler.table', 'sessions'); Configure::write('Session.handler.table', 'sessions');
Configure::write('Session.handler.model', 'Session'); Configure::write('Session.handler.model', 'Session');
Configure::write('Session.handler.database', 'test'); Configure::write('Session.handler.database', 'test');
@ -651,6 +670,7 @@ class CakeSessionTest extends CakeTestCase {
*/ */
public function testSessionTimeout() { public function testSessionTimeout() {
Configure::write('debug', 2); Configure::write('debug', 2);
Configure::write('Session.defaults', 'cake');
Configure::write('Session.autoRegenerate', false); Configure::write('Session.autoRegenerate', false);
$timeoutSeconds = Configure::read('Session.timeout') * 60; $timeoutSeconds = Configure::read('Session.timeout') * 60;
@ -683,7 +703,7 @@ class CakeSessionTest extends CakeTestCase {
public function testCookieTimeoutFallback() { public function testCookieTimeoutFallback() {
$_SESSION = null; $_SESSION = null;
Configure::write('Session', array( Configure::write('Session', array(
'defaults' => 'php', 'defaults' => 'cake',
'timeout' => 400, 'timeout' => 400,
)); ));
TestCakeSession::start(); TestCakeSession::start();
@ -692,7 +712,7 @@ class CakeSessionTest extends CakeTestCase {
$_SESSION = null; $_SESSION = null;
Configure::write('Session', array( Configure::write('Session', array(
'defaults' => 'php', 'defaults' => 'cake',
'timeout' => 400, 'timeout' => 400,
'cookieTimeout' => 600 'cookieTimeout' => 600
)); ));

View file

@ -353,7 +353,7 @@ class SqliteTest extends CakeTestCase {
public function testVirtualFieldWithFunction() { public function testVirtualFieldWithFunction() {
$this->loadFixtures('User'); $this->loadFixtures('User');
$User = ClassRegistry::init('User'); $User = ClassRegistry::init('User');
$User->virtualFields = array('name' => 'SUBSTR(User.user, 5)'); $User->virtualFields = array('name' => 'SUBSTR(User.user, 5, LENGTH(User.user) - 4)');
$result = $User->find('first', array( $result = $User->find('first', array(
'conditions' => array('User.user' => 'garrett') 'conditions' => array('User.user' => 'garrett')

View file

@ -80,7 +80,8 @@ class FileTest extends CakeTestCase {
'filesize' => filesize($file), 'filesize' => filesize($file),
'mime' => 'text/x-php' 'mime' => 'text/x-php'
); );
if (!function_exists('finfo_open') && !function_exists('mime_content_type')) { if (!function_exists('finfo_open') && (!function_exists('mime_content_type') ||
function_exists('mime_content_type') && false === mime_content_type($this->File->pwd()))) {
$expecting['mime'] = false; $expecting['mime'] = false;
} }
@ -480,7 +481,11 @@ class FileTest extends CakeTestCase {
$this->skipIf(!function_exists('finfo_open') && !function_exists('mime_content_type'), 'Not able to read mime type'); $this->skipIf(!function_exists('finfo_open') && !function_exists('mime_content_type'), 'Not able to read mime type');
$path = CAKE . 'Test' . DS . 'test_app' . DS . 'webroot' . DS . 'img' . DS . 'cake.power.gif'; $path = CAKE . 'Test' . DS . 'test_app' . DS . 'webroot' . DS . 'img' . DS . 'cake.power.gif';
$file = new File($path); $file = new File($path);
$this->assertEquals('image/gif', $file->mime()); $expected = 'image/gif';
if (function_exists('mime_content_type') && false === mime_content_type($file->pwd())) {
$expected = false;
}
$this->assertEquals($expected, $file->mime());
} }
/** /**

View file

@ -607,7 +607,12 @@ class RssHelperTest extends CakeTestCase {
$File = new File($tmpFile, true); $File = new File($tmpFile, true);
$this->assertTrue($File->write('123'), 'Could not write to ' . $tmpFile); $this->assertTrue($File->write('123'), 'Could not write to ' . $tmpFile);
clearstatcache(true, $tmpFile);
if (50300 <= PHP_VERSION_ID) {
clearstatcache(true, $tmpFile);
} else {
clearstatcache();
}
$item = array( $item = array(
'title' => array( 'title' => array(
@ -637,6 +642,12 @@ class RssHelperTest extends CakeTestCase {
) )
); );
$result = $this->Rss->item(null, $item); $result = $this->Rss->item(null, $item);
if (!function_exists('finfo_open') &&
(function_exists('mime_content_type') && false === mime_content_type($tmpFile))) {
$type = false;
} else {
$type = 'text/plain';
}
$expected = array( $expected = array(
'<item', '<item',
'<title', '<title',
@ -651,7 +662,7 @@ class RssHelperTest extends CakeTestCase {
'enclosure' => array( 'enclosure' => array(
'url' => $this->Rss->url('/tests/cakephp.file.test.tmp', true), 'url' => $this->Rss->url('/tests/cakephp.file.test.tmp', true),
'length' => filesize($tmpFile), 'length' => filesize($tmpFile),
'type' => 'text/plain' 'type' => $type
), ),
'<pubDate', '<pubDate',
date('r', strtotime('2008-05-31 12:00:00')), date('r', strtotime('2008-05-31 12:00:00')),