Skip to content

Commit

Permalink
Merge branch 'master' into 2.3
Browse files Browse the repository at this point in the history
Conflicts:
	lib/Cake/Test/Case/Model/ModelReadTest.php
	lib/Cake/Test/Case/View/MediaViewTest.php
  • Loading branch information
markstory committed Nov 24, 2012
2 parents 4025794 + 3083b01 commit 82d20ed
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 75 deletions.
2 changes: 0 additions & 2 deletions lib/Cake/Controller/CakeErrorController.php
Expand Up @@ -66,8 +66,6 @@ public function __construct($request = null, $response = null) {
if ($this->Components->enabled('Security')) {
$this->Components->disable('Security');
}
$this->startupProcess();

$this->_set(array('cacheAction' => false, 'viewPath' => 'Errors'));
}

Expand Down
4 changes: 4 additions & 0 deletions lib/Cake/Error/ExceptionRenderer.php
Expand Up @@ -151,7 +151,11 @@ protected function _getController($exception) {

try {
$controller = new CakeErrorController($request, $response);
$controller->startupProcess();
} catch (Exception $e) {
if (!empty($controller) && $controller->Components->enabled('RequestHandler')) {
$controller->RequestHandler->startup($controller);
}
}
if (empty($controller)) {
$controller = new Controller($request, $response);
Expand Down
7 changes: 6 additions & 1 deletion lib/Cake/Model/Datasource/DboSource.php
Expand Up @@ -2281,7 +2281,8 @@ public function fields(Model $model, $alias = null, $fields = array(), $quote =
$virtualFields,
$fields,
$quote,
ConnectionManager::getSourceName($this)
ConnectionManager::getSourceName($this),
$model->table
);
$cacheKey = md5(serialize($cacheKey));
if ($return = $this->cacheMethod(__FUNCTION__, $cacheKey)) {
Expand Down Expand Up @@ -2463,6 +2464,10 @@ public function conditionKeysToString($conditions, $quoteValues = true, $model =
$not = 'NOT ';
}

if (empty($value)) {
continue;
}

if (empty($value[1])) {
if ($not) {
$out[] = $not . '(' . $value[0] . ')';
Expand Down
13 changes: 13 additions & 0 deletions lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php
Expand Up @@ -159,6 +159,19 @@ public function testBooleanNullConditionsParsing() {
$this->assertEquals(' WHERE 1 = 1', $result);
}

/**
* test that booleans work on empty set.
*
* @return void
*/
public function testBooleanEmptyConditionsParsing() {
$result = $this->testDb->conditions(array('OR' => array()));
$this->assertEquals(' WHERE 1 = 1', $result, 'empty conditions failed');

$result = $this->testDb->conditions(array('OR' => array('OR' => array())));
$this->assertEquals(' WHERE 1 = 1', $result, 'nested empty conditions failed');
}

/**
* test that order() will accept objects made from DboSource::expression
*
Expand Down
16 changes: 11 additions & 5 deletions lib/Cake/Test/Case/Model/ModelReadTest.php
Expand Up @@ -5401,7 +5401,7 @@ public function testNonNumericHabtmJoinKey() {
$Post->Tag->primaryKey = 'tag';

$result = $Post->find('all', array(
'order' => array('Post.id' => 'ASC')
'order' => 'Post.id ASC',
));
$expected = array(
array(
Expand Down Expand Up @@ -5617,7 +5617,9 @@ public function testHasManyLimitOptimization() {
$Project = new Project();
$Project->recursive = 3;

$result = $Project->find('all');
$result = $Project->find('all', array(
'order' => 'Project.id ASC',
));
$expected = array(
array(
'Project' => array(
Expand Down Expand Up @@ -5731,7 +5733,9 @@ public function testFindAllRecursiveSelfJoin() {
$TestModel = new Home();
$TestModel->recursive = 2;

$result = $TestModel->find('all');
$result = $TestModel->find('all', array(
'order' => 'Home.id ASC',
));
$expected = array(
array(
'Home' => array(
Expand Down Expand Up @@ -5844,7 +5848,9 @@ public function testFindAllRecursiveWithHabtm() {
$MyUser = new MyUser();
$MyUser->recursive = 2;

$result = $MyUser->find('all');
$result = $MyUser->find('all', array(
'order' => 'MyUser.id ASC'
));
$expected = array(
array(
'MyUser' => array('id' => '1', 'firstname' => 'userA'),
Expand Down Expand Up @@ -6035,7 +6041,7 @@ public function testFindAllFakeThread() {
$fullDebug = $this->db->fullDebug;
$this->db->fullDebug = true;
$TestModel->recursive = 6;
$result = $TestModel->find('all', null, null, 'CategoryThread.id ASC');
$result = $TestModel->find('all');
$expected = array(
array(
'CategoryThread' => array(
Expand Down
120 changes: 53 additions & 67 deletions lib/Cake/Test/Case/View/MediaViewTest.php
Expand Up @@ -40,9 +40,11 @@ public function setUp() {
'_isActive',
'_clearBuffer',
'_flushBuffer',
'send',
'cache',
'type',
'header',
'download'
'download',
'statusCode'
));
}

Expand Down Expand Up @@ -90,29 +92,28 @@ public function testRender() {
->with('css')
->will($this->returnArgument(0));

$this->MediaView->response->expects($this->at(0))
->method('header')
->with(array(
'Expires' => 'Mon, 26 Jul 1997 05:00:00 GMT',
'Cache-Control' => 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0',
'Last-Modified' => gmdate('D, d M Y H:i:s', time()) . ' GMT'
));

$this->MediaView->response->expects($this->at(2))
->method('header')
->with('Content-Length', 38);

$this->MediaView->response->expects($this->once())->method('_clearBuffer');
$this->MediaView->response->expects($this->once())->method('send');
$this->MediaView->response->expects($this->exactly(1))
->method('_isActive')
->will($this->returnValue(true));
$this->MediaView->response->expects($this->once())->method('_clearBuffer');
$this->MediaView->response->expects($this->once())->method('_flushBuffer');

ob_start();
$result = $this->MediaView->render();
$output = ob_get_clean();
$this->assertEquals("/* this is the test asset css file */\n", $output);
$this->assertTrue($result !== false);

$headers = $this->MediaView->response->header();
$this->assertEquals(31, $headers['Content-Length']);
$this->assertEquals(0, $headers['Expires']);
$this->assertEquals(
'private, must-revalidate, post-check=0, pre-check=0',
$headers['Cache-Control']
);
$this->assertEquals('no-cache', $headers['Pragma']);
$this->assertContains(gmdate('D, d M Y H:i', time()), $headers['Date']);
}

/**
Expand All @@ -133,28 +134,10 @@ public function testRenderWithUnknownFileTypeGeneric() {
->with('ini')
->will($this->returnValue(false));

$this->MediaView->response->expects($this->at(0))
->method('header')
->with($this->logicalAnd(
$this->arrayHasKey('Last-Modified'),
$this->arrayHasKey('Expires'),
$this->arrayHasKey('Cache-Control'),
$this->contains('Mon, 26 Jul 1997 05:00:00 GMT'),
$this->contains('no-store, no-cache, must-revalidate, post-check=0, pre-check=0')
));

$this->MediaView->response->expects($this->once())
->method('download')
->with('no_section.ini');

$this->MediaView->response->expects($this->at(3))
->method('header')
->with('Accept-Ranges', 'bytes');

$this->MediaView->response->expects($this->at(4))
->method('header')
->with('Content-Length', 35);

$this->MediaView->response->expects($this->once())->method('_clearBuffer');
$this->MediaView->response->expects($this->exactly(1))
->method('_isActive')
Expand All @@ -169,6 +152,17 @@ public function testRenderWithUnknownFileTypeGeneric() {
if ($currentUserAgent !== null) {
$_SERVER['HTTP_USER_AGENT'] = $currentUserAgent;
}

$headers = $this->MediaView->response->header();
$this->assertEquals(35, $headers['Content-Length']);
$this->assertEquals(0, $headers['Expires']);
$this->assertEquals('bytes', $headers['Accept-Ranges']);
$this->assertEquals(
'private, must-revalidate, post-check=0, pre-check=0',
$headers['Cache-Control']
);
$this->assertEquals('no-cache', $headers['Pragma']);
$this->assertContains(gmdate('D, d M Y H:i', time()), $headers['Date']);
}

/**
Expand All @@ -185,19 +179,11 @@ public function testRenderWithUnknownFileTypeOpera() {
);

$this->MediaView->response->expects($this->at(0))
->method('header')
->with(array(
'Expires' => 'Mon, 26 Jul 1997 05:00:00 GMT',
'Cache-Control' => 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0',
'Last-Modified' => gmdate('D, d M Y H:i:s', time()) . ' GMT'
));

$this->MediaView->response->expects($this->at(1))
->method('type')
->with('ini')
->will($this->returnValue(false));

$this->MediaView->response->expects($this->at(2))
$this->MediaView->response->expects($this->at(1))
->method('type')
->with('application/octetstream')
->will($this->returnValue(false));
Expand All @@ -206,14 +192,7 @@ public function testRenderWithUnknownFileTypeOpera() {
->method('download')
->with('no_section.ini');

$this->MediaView->response->expects($this->at(4))
->method('header')
->with('Accept-Ranges', 'bytes');

$this->MediaView->response->expects($this->at(5))
->method('header')
->with('Content-Length', 35);

$this->MediaView->response->expects($this->once())->method('send');
$this->MediaView->response->expects($this->once())->method('_clearBuffer');
$this->MediaView->response->expects($this->exactly(1))
->method('_isActive')
Expand All @@ -228,6 +207,17 @@ public function testRenderWithUnknownFileTypeOpera() {
if ($currentUserAgent !== null) {
$_SERVER['HTTP_USER_AGENT'] = $currentUserAgent;
}

$headers = $this->MediaView->response->header();
$this->assertEquals(35, $headers['Content-Length']);
$this->assertEquals(0, $headers['Expires']);
$this->assertEquals('bytes', $headers['Accept-Ranges']);
$this->assertEquals(
'private, must-revalidate, post-check=0, pre-check=0',
$headers['Cache-Control']
);
$this->assertEquals('no-cache', $headers['Pragma']);
$this->assertContains(gmdate('D, d M Y H:i', time()), $headers['Date']);
}

/**
Expand All @@ -245,19 +235,11 @@ public function testRenderWithUnknownFileTypeIE() {
);

$this->MediaView->response->expects($this->at(0))
->method('header')
->with(array(
'Expires' => 'Mon, 26 Jul 1997 05:00:00 GMT',
'Cache-Control' => 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0',
'Last-Modified' => gmdate('D, d M Y H:i:s', time()) . ' GMT'
));

$this->MediaView->response->expects($this->at(1))
->method('type')
->with('ini')
->will($this->returnValue(false));

$this->MediaView->response->expects($this->at(2))
$this->MediaView->response->expects($this->at(1))
->method('type')
->with('application/force-download')
->will($this->returnValue(false));
Expand All @@ -266,14 +248,7 @@ public function testRenderWithUnknownFileTypeIE() {
->method('download')
->with('config.ini');

$this->MediaView->response->expects($this->at(4))
->method('header')
->with('Accept-Ranges', 'bytes');

$this->MediaView->response->expects($this->at(5))
->method('header')
->with('Content-Length', 35);

$this->MediaView->response->expects($this->once())->method('send');
$this->MediaView->response->expects($this->once())->method('_clearBuffer');
$this->MediaView->response->expects($this->exactly(1))
->method('_isActive')
Expand All @@ -288,6 +263,17 @@ public function testRenderWithUnknownFileTypeIE() {
if ($currentUserAgent !== null) {
$_SERVER['HTTP_USER_AGENT'] = $currentUserAgent;
}

$headers = $this->MediaView->response->header();
$this->assertEquals(35, $headers['Content-Length']);
$this->assertEquals(0, $headers['Expires']);
$this->assertEquals('bytes', $headers['Accept-Ranges']);
$this->assertEquals(
'private, must-revalidate, post-check=0, pre-check=0',
$headers['Cache-Control']
);
$this->assertEquals('no-cache', $headers['Pragma']);
$this->assertContains(gmdate('D, d M Y H:i', time()), $headers['Date']);
}

/**
Expand Down

0 comments on commit 82d20ed

Please sign in to comment.