Merge branch 'master' into 2.4

This commit is contained in:
Phally 2013-07-26 19:44:11 +02:00
commit 6b41eaa950
13 changed files with 209 additions and 69 deletions

View file

@ -31,24 +31,24 @@ Cache::config('default', array('engine' => 'File'));
* The settings below can be used to set additional paths to models, views and controllers.
*
* App::build(array(
* 'Model' => array('/path/to/models', '/next/path/to/models'),
* 'Model/Behavior' => array('/path/to/behaviors', '/next/path/to/behaviors'),
* 'Model/Datasource' => array('/path/to/datasources', '/next/path/to/datasources'),
* 'Model/Datasource/Database' => array('/path/to/databases', '/next/path/to/database'),
* 'Model/Datasource/Session' => array('/path/to/sessions', '/next/path/to/sessions'),
* 'Controller' => array('/path/to/controllers', '/next/path/to/controllers'),
* 'Controller/Component' => array('/path/to/components', '/next/path/to/components'),
* 'Controller/Component/Auth' => array('/path/to/auths', '/next/path/to/auths'),
* 'Controller/Component/Acl' => array('/path/to/acls', '/next/path/to/acls'),
* 'View' => array('/path/to/views', '/next/path/to/views'),
* 'View/Helper' => array('/path/to/helpers', '/next/path/to/helpers'),
* 'Console' => array('/path/to/consoles', '/next/path/to/consoles'),
* 'Console/Command' => array('/path/to/commands', '/next/path/to/commands'),
* 'Console/Command/Task' => array('/path/to/tasks', '/next/path/to/tasks'),
* 'Lib' => array('/path/to/libs', '/next/path/to/libs'),
* 'Locale' => array('/path/to/locales', '/next/path/to/locales'),
* 'Vendor' => array('/path/to/vendors', '/next/path/to/vendors'),
* 'Plugin' => array('/path/to/plugins', '/next/path/to/plugins'),
* 'Model' => array('/path/to/models/', '/next/path/to/models/'),
* 'Model/Behavior' => array('/path/to/behaviors/', '/next/path/to/behaviors/'),
* 'Model/Datasource' => array('/path/to/datasources/', '/next/path/to/datasources/'),
* 'Model/Datasource/Database' => array('/path/to/databases/', '/next/path/to/database/'),
* 'Model/Datasource/Session' => array('/path/to/sessions/', '/next/path/to/sessions/'),
* 'Controller' => array('/path/to/controllers/', '/next/path/to/controllers/'),
* 'Controller/Component' => array('/path/to/components/', '/next/path/to/components/'),
* 'Controller/Component/Auth' => array('/path/to/auths/', '/next/path/to/auths/'),
* 'Controller/Component/Acl' => array('/path/to/acls/', '/next/path/to/acls/'),
* 'View' => array('/path/to/views/', '/next/path/to/views/'),
* 'View/Helper' => array('/path/to/helpers/', '/next/path/to/helpers/'),
* 'Console' => array('/path/to/consoles/', '/next/path/to/consoles/'),
* 'Console/Command' => array('/path/to/commands/', '/next/path/to/commands/'),
* 'Console/Command/Task' => array('/path/to/tasks/', '/next/path/to/tasks/'),
* 'Lib' => array('/path/to/libs/', '/next/path/to/libs/'),
* 'Locale' => array('/path/to/locales/', '/next/path/to/locales/'),
* 'Vendor' => array('/path/to/vendors/', '/next/path/to/vendors/'),
* 'Plugin' => array('/path/to/plugins/', '/next/path/to/plugins/'),
* ));
*
*/

View file

@ -328,6 +328,11 @@ class ControllerTask extends BakeTask {
'plugin' => $this->plugin,
'pluginPath' => empty($this->plugin) ? '' : $this->plugin . '.'
));
if (!in_array('Paginator', (array)$components)) {
$components[] = 'Paginator';
}
$this->Template->set(compact('controllerName', 'actions', 'helpers', 'components', 'isScaffold'));
$contents = $this->Template->generate('classes', 'controller');
@ -370,10 +375,11 @@ class ControllerTask extends BakeTask {
* @return array Components the user wants to use.
*/
public function doComponents() {
return $this->_doPropertyChoices(
__d('cake_console', "Would you like this controller to use any components?"),
$components = array('Paginator');
return array_merge($components, $this->_doPropertyChoices(
__d('cake_console', "Would you like this controller to use other components\nbesides PaginatorComponent?"),
__d('cake_console', "Please provide a comma separated list of the component names you'd like to use.\nExample: 'Acl, Security, RequestHandler'")
);
));
}
/**

View file

@ -26,7 +26,7 @@
*/
public function <?php echo $admin ?>index() {
$this-><?php echo $currentModelName ?>->recursive = 0;
$this->set('<?php echo $pluralName ?>', $this->paginate());
$this->set('<?php echo $pluralName ?>', $this->Paginator->paginate());
}
/**

View file

@ -22,24 +22,24 @@ Cache::config('default', array('engine' => 'File'));
* The settings below can be used to set additional paths to models, views and controllers.
*
* App::build(array(
* 'Model' => array('/path/to/models', '/next/path/to/models'),
* 'Model/Behavior' => array('/path/to/behaviors', '/next/path/to/behaviors'),
* 'Model/Datasource' => array('/path/to/datasources', '/next/path/to/datasources'),
* 'Model/Datasource/Database' => array('/path/to/databases', '/next/path/to/database'),
* 'Model/Datasource/Session' => array('/path/to/sessions', '/next/path/to/sessions'),
* 'Controller' => array('/path/to/controllers', '/next/path/to/controllers'),
* 'Controller/Component' => array('/path/to/components', '/next/path/to/components'),
* 'Controller/Component/Auth' => array('/path/to/auths', '/next/path/to/auths'),
* 'Controller/Component/Acl' => array('/path/to/acls', '/next/path/to/acls'),
* 'View' => array('/path/to/views', '/next/path/to/views'),
* 'View/Helper' => array('/path/to/helpers', '/next/path/to/helpers'),
* 'Console' => array('/path/to/consoles', '/next/path/to/consoles'),
* 'Console/Command' => array('/path/to/commands', '/next/path/to/commands'),
* 'Console/Command/Task' => array('/path/to/tasks', '/next/path/to/tasks'),
* 'Lib' => array('/path/to/libs', '/next/path/to/libs'),
* 'Locale' => array('/path/to/locales', '/next/path/to/locales'),
* 'Vendor' => array('/path/to/vendors', '/next/path/to/vendors'),
* 'Plugin' => array('/path/to/plugins', '/next/path/to/plugins'),
* 'Model' => array('/path/to/models/', '/next/path/to/models/'),
* 'Model/Behavior' => array('/path/to/behaviors/', '/next/path/to/behaviors/'),
* 'Model/Datasource' => array('/path/to/datasources/', '/next/path/to/datasources/'),
* 'Model/Datasource/Database' => array('/path/to/databases/', '/next/path/to/database/'),
* 'Model/Datasource/Session' => array('/path/to/sessions/', '/next/path/to/sessions/'),
* 'Controller' => array('/path/to/controllers/', '/next/path/to/controllers/'),
* 'Controller/Component' => array('/path/to/components/', '/next/path/to/components/'),
* 'Controller/Component/Auth' => array('/path/to/auths/', '/next/path/to/auths/'),
* 'Controller/Component/Acl' => array('/path/to/acls/', '/next/path/to/acls/'),
* 'View' => array('/path/to/views/', '/next/path/to/views/'),
* 'View/Helper' => array('/path/to/helpers/', '/next/path/to/helpers/'),
* 'Console' => array('/path/to/consoles/', '/next/path/to/consoles/'),
* 'Console/Command' => array('/path/to/commands/', '/next/path/to/commands/'),
* 'Console/Command/Task' => array('/path/to/tasks/', '/next/path/to/tasks/'),
* 'Lib' => array('/path/to/libs/', '/next/path/to/libs/'),
* 'Locale' => array('/path/to/locales/', '/next/path/to/locales/'),
* 'Vendor' => array('/path/to/vendors/', '/next/path/to/vendors/'),
* 'Plugin' => array('/path/to/plugins/', '/next/path/to/plugins/'),
* ));
*
*/

View file

@ -733,7 +733,7 @@ class AuthComponent extends Component {
$redir = '/';
}
if (is_array($redir)) {
return Router::url($redir);
return Router::url($redir + array('base' => false));
}
return $redir;
}

View file

@ -121,7 +121,7 @@ class PaginatorComponent extends Component {
* @param Model|string $object Model to paginate (e.g: model instance, or 'Model', or 'Model.InnerModel')
* @param string|array $scope Additional find conditions to use while paginating
* @param array $whitelist List of allowed fields for ordering. This allows you to prevent ordering
* on non-indexed, or undesirable columns. See PaginatorComponent::validateSort() for additional details
* on non-indexed, or undesirable columns. See PaginatorComponent::validateSort() for additional details
* on how the whitelisting and sort field validation works.
* @return array Model query results
* @throws MissingModelException

View file

@ -1316,6 +1316,15 @@ class CakeResponse {
$fileSize = $file->size();
$lastByte = $fileSize - 1;
if ($start === '') {
$start = $fileSize - $end;
$end = $lastByte;
}
if ($end === '') {
$end = $lastByte;
}
if ($start > $end || $end > $lastByte || $start > $lastByte) {
$this->statusCode(416);
$this->header(array(

View file

@ -36,6 +36,10 @@ class ApcEngineTest extends CakeTestCase {
parent::setUp();
$this->skipIf(!function_exists('apc_store'), 'Apc is not installed or configured properly.');
if (php_sapi_name() === 'cli') {
$this->skipIf(!ini_get('apc.enable_cli'), 'APC is not enabled for the CLI.');
}
$this->_cacheDisable = Configure::read('Cache.disable');
Configure::write('Cache.disable', false);
Cache::config('apc', array('engine' => 'Apc', 'prefix' => 'cake_'));

View file

@ -224,7 +224,7 @@ class ControllerTaskTest extends CakeTestCase {
public function testDoComponentsNo() {
$this->Task->expects($this->any())->method('in')->will($this->returnValue('n'));
$result = $this->Task->doComponents();
$this->assertSame(array(), $result);
$this->assertSame(array('Paginator'), $result);
}
/**
@ -237,7 +237,7 @@ class ControllerTaskTest extends CakeTestCase {
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' RequestHandler, Security '));
$result = $this->Task->doComponents();
$expected = array('RequestHandler', 'Security');
$expected = array('Paginator', 'RequestHandler', 'Security');
$this->assertEquals($expected, $result);
}
@ -251,7 +251,7 @@ class ControllerTaskTest extends CakeTestCase {
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' RequestHandler, Security, , '));
$result = $this->Task->doComponents();
$expected = array('RequestHandler', 'Security');
$expected = array('Paginator', 'RequestHandler', 'Security');
$this->assertEquals($expected, $result);
}
@ -286,8 +286,9 @@ class ControllerTaskTest extends CakeTestCase {
$this->assertContains(' * @property Article $Article', $result);
$this->assertContains(' * @property AclComponent $Acl', $result);
$this->assertContains(' * @property AuthComponent $Auth', $result);
$this->assertContains(' * @property PaginatorComponent $Paginator', $result);
$this->assertContains('class ArticlesController extends AppController', $result);
$this->assertContains("public \$components = array('Acl', 'Auth')", $result);
$this->assertContains("public \$components = array('Acl', 'Auth', 'Paginator')", $result);
$this->assertContains("public \$helpers = array('Js', 'Time')", $result);
$this->assertContains("--actions--", $result);
@ -300,8 +301,8 @@ class ControllerTaskTest extends CakeTestCase {
$result = $this->Task->bake('Articles', '--actions--', array(), array());
$this->assertContains('class ArticlesController extends AppController', $result);
$this->assertSame(substr_count($result, '@property'), 1);
$this->assertNotContains('components', $result);
$this->assertSame(substr_count($result, '@property'), 2);
$this->assertContains("public \$components = array('Paginator')", $result);
$this->assertNotContains('helpers', $result);
$this->assertContains('--actions--', $result);
}
@ -350,7 +351,7 @@ class ControllerTaskTest extends CakeTestCase {
$this->assertContains('function index() {', $result);
$this->assertContains('$this->BakeArticle->recursive = 0;', $result);
$this->assertContains("\$this->set('bakeArticles', \$this->paginate());", $result);
$this->assertContains("\$this->set('bakeArticles', \$this->Paginator->paginate());", $result);
$this->assertContains('function view($id = null)', $result);
$this->assertContains("throw new NotFoundException(__('Invalid bake article'));", $result);
@ -388,7 +389,7 @@ class ControllerTaskTest extends CakeTestCase {
$this->assertContains('function index() {', $result);
$this->assertContains('$this->BakeArticle->recursive = 0;', $result);
$this->assertContains("\$this->set('bakeArticles', \$this->paginate());", $result);
$this->assertContains("\$this->set('bakeArticles', \$this->Paginator->paginate());", $result);
$this->assertContains('function view($id = null)', $result);
$this->assertContains("throw new NotFoundException(__('Invalid bake article'));", $result);

View file

@ -1321,6 +1321,41 @@ class AuthComponentTest extends CakeTestCase {
$this->assertFalse($this->Auth->Session->check('Auth.redirect'));
}
/**
* test that the returned URL doesn't contain the base URL.
*
* @see https://cakephp.lighthouseapp.com/projects/42648/tickets/3922-authcomponentredirecturl-prepends-appbaseurl
*
* @return void This test method doesn't return anything.
*/
public function testRedirectUrlWithBaseSet() {
$App = Configure::read('App');
Configure::write('App', array(
'dir' => APP_DIR,
'webroot' => WEBROOT_DIR,
'base' => false,
'baseUrl' => '/cake/index.php'
));
$url = '/users/login';
$this->Auth->request = $this->Controller->request = new CakeRequest($url);
$this->Auth->request->addParams(Router::parse($url));
$this->Auth->request->url = Router::normalize($url);
Router::setRequestInfo($this->Auth->request);
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
$this->Auth->loginRedirect = array('controller' => 'users', 'action' => 'home');
$result = $this->Auth->redirectUrl();
$this->assertEquals('/users/home', $result);
$this->assertFalse($this->Auth->Session->check('Auth.redirect'));
Configure::write('App', $App);
Router::reload();
}
/**
* test password hashing
*

View file

@ -30,6 +30,7 @@ class CakeResponseTest extends CakeTestCase {
* @return void
*/
public function setUp() {
parent::setUp();
ob_start();
}
@ -39,6 +40,7 @@ class CakeResponseTest extends CakeTestCase {
* @return void
*/
public function tearDown() {
parent::tearDown();
ob_end_clean();
}
@ -1385,6 +1387,76 @@ class CakeResponseTest extends CakeTestCase {
$response->file(CAKE . 'Test' . DS . 'test_app' . DS . 'Vendor' . DS . 'img' . DS . 'test_2.JPG');
}
/**
* A data provider for testing various ranges
*
* @return array
*/
public static function rangeProvider() {
return array(
// suffix-byte-range
array(
'bytes=-25', 25, 'bytes 13-37/38'
),
array(
'bytes=0-', 38, 'bytes 0-37/38'
),
array(
'bytes=10-', 28, 'bytes 10-37/38'
),
array(
'bytes=10-20', 11, 'bytes 10-20/38'
),
);
}
/**
* Test the various range offset types.
*
* @dataProvider rangeProvider
* @return void
*/
public function testFileRangeOffsets($range, $length, $offsetResponse) {
$_SERVER['HTTP_RANGE'] = $range;
$response = $this->getMock('CakeResponse', array(
'header',
'type',
'_sendHeader',
'_isActive',
'_clearBuffer',
'_flushBuffer'
));
$response->expects($this->at(1))
->method('header')
->with('Content-Disposition', 'attachment; filename="test_asset.css"');
$response->expects($this->at(2))
->method('header')
->with('Accept-Ranges', 'bytes');
$response->expects($this->at(3))
->method('header')
->with(array(
'Content-Length' => $length,
'Content-Range' => $offsetResponse,
));
$response->expects($this->any())
->method('_isActive')
->will($this->returnValue(true));
$response->file(
CAKE . 'Test' . DS . 'test_app' . DS . 'Vendor' . DS . 'css' . DS . 'test_asset.css',
array('download' => true)
);
ob_start();
$result = $response->send();
ob_get_clean();
}
/**
* Test fetching ranges from a file.
*

View file

@ -106,7 +106,7 @@ class TestThemeView extends View {
*
* @param string $name
* @param array $params
* @return void
* @return string The given name
*/
public function renderElement($name, $params = array()) {
return $name;
@ -115,8 +115,8 @@ class TestThemeView extends View {
/**
* getViewFileName method
*
* @param string $name
* @return void
* @param string $name Controller action to find template filename for
* @return string Template filename
*/
public function getViewFileName($name = null) {
return $this->_getViewFileName($name);
@ -125,8 +125,8 @@ class TestThemeView extends View {
/**
* getLayoutFileName method
*
* @param string $name
* @return void
* @param string $name The name of the layout to find.
* @return string Filename for layout file (.ctp).
*/
public function getLayoutFileName($name = null) {
return $this->_getLayoutFileName($name);
@ -144,8 +144,8 @@ class TestView extends View {
/**
* getViewFileName method
*
* @param string $name
* @return void
* @param string $name Controller action to find template filename for
* @return string Template filename
*/
public function getViewFileName($name = null) {
return $this->_getViewFileName($name);
@ -154,8 +154,8 @@ class TestView extends View {
/**
* getLayoutFileName method
*
* @param string $name
* @return void
* @param string $name The name of the layout to find.
* @return string Filename for layout file (.ctp).
*/
public function getLayoutFileName($name = null) {
return $this->_getLayoutFileName($name);
@ -164,9 +164,9 @@ class TestView extends View {
/**
* paths method
*
* @param string $plugin
* @param boolean $cached
* @return void
* @param string $plugin Optional plugin name to scan for view files.
* @param boolean $cached Set to true to force a refresh of view paths.
* @return array paths
*/
public function paths($plugin = null, $cached = true) {
return $this->_paths($plugin, $cached);
@ -200,6 +200,7 @@ class TestAfterHelper extends Helper {
/**
* beforeLayout method
*
* @param string $viewFile
* @return void
*/
public function beforeLayout($viewFile) {
@ -209,6 +210,7 @@ class TestAfterHelper extends Helper {
/**
* afterLayout method
*
* @param string $layoutFile
* @return void
*/
public function afterLayout($layoutFile) {
@ -529,7 +531,7 @@ class ViewTest extends CakeTestCase {
$View = new TestView($this->Controller);
ob_start();
$result = $View->getViewFileName('does_not_exist');
$View->getViewFileName('does_not_exist');
$this->ThemeController->plugin = null;
$this->ThemeController->name = 'Pages';
@ -557,8 +559,8 @@ class ViewTest extends CakeTestCase {
$View = new TestView($this->Controller);
ob_start();
$result = $View->getLayoutFileName();
$expected = ob_get_clean();
$View->getLayoutFileName();
ob_get_clean();
$this->ThemeController->plugin = null;
$this->ThemeController->name = 'Posts';
@ -567,7 +569,7 @@ class ViewTest extends CakeTestCase {
$this->ThemeController->theme = 'my_theme';
$View = new TestThemeView($this->ThemeController);
$result = $View->getLayoutFileName();
$View->getLayoutFileName();
}
/**
@ -762,7 +764,7 @@ class ViewTest extends CakeTestCase {
$result = Cache::read('element__test_element_cache_callbacks_param_foo', 'test_view');
$this->assertEquals($expected, $result);
$result = $View->element('test_element', array(
$View->element('test_element', array(
'param' => 'one',
'foo' => 'two'
), array(
@ -772,7 +774,7 @@ class ViewTest extends CakeTestCase {
$this->assertEquals($expected, $result);
$View->elementCache = 'default';
$result = $View->element('test_element', array(
$View->element('test_element', array(
'param' => 'one',
'foo' => 'two'
), array(
@ -1310,6 +1312,17 @@ class ViewTest extends CakeTestCase {
$this->assertEquals('Block content', $result);
}
/**
* Test resetting a block's content.
*
* @return void
*/
public function testBlockReset() {
$this->View->assign('test', '');
$result = $this->View->fetch('test', 'This should not be returned');
$this->assertSame('', $result);
}
/**
* Test appending to a block with append.
*

View file

@ -61,7 +61,7 @@
<?php
if (!empty($filePresent)):
App::uses('ConnectionManager', 'Model');
$connected = ConnectionManager::getDataSource('default');
$connected = ConnectionManager::getDataSource('default');
?>
<p>
<span class="notice">