Merge branch '2.7' into 2.8

This commit is contained in:
Jose Lorenzo Rodriguez 2015-08-21 10:54:30 +02:00
commit 40d628530a
16 changed files with 130 additions and 35 deletions

View file

@ -42,7 +42,7 @@ $cakeVersion = __d('cake_dev', 'CakePHP %s', Configure::version())
</div>
<div id="content">
<?php echo $this->Session->flash(); ?>
<?php echo $this->Flash->render(); ?>
<?php echo $this->fetch('content'); ?>
</div>

View file

@ -384,9 +384,9 @@ class ControllerTask extends BakeTask {
* @return array Components the user wants to use.
*/
public function doComponents() {
$components = array('Paginator');
$components = array('Paginator', 'Flash');
return array_merge($components, $this->_doPropertyChoices(
__d('cake_console', "Would you like this controller to use other components\nbesides PaginatorComponent?"),
__d('cake_console', "Would you like this controller to use other components\nbesides PaginatorComponent and FlashComponent?"),
__d('cake_console', "Please provide a comma separated list of the component names you'd like to use.\nExample: 'Acl, Security, RequestHandler'")
));
}

View file

@ -53,10 +53,10 @@
$this-><?php echo $currentModelName; ?>->create();
if ($this-><?php echo $currentModelName; ?>->save($this->request->data)) {
<?php if ($wannaUseSession): ?>
$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> has been saved.'));
$this->Flash->success(__('The <?php echo strtolower($singularHumanName); ?> has been saved.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> could not be saved. Please, try again.'));
$this->Flash->error(__('The <?php echo strtolower($singularHumanName); ?> could not be saved. Please, try again.'));
<?php else: ?>
return $this->flash(__('The <?php echo strtolower($singularHumanName); ?> has been saved.'), array('action' => 'index'));
<?php endif; ?>
@ -94,10 +94,10 @@
if ($this->request->is(array('post', 'put'))) {
if ($this-><?php echo $currentModelName; ?>->save($this->request->data)) {
<?php if ($wannaUseSession): ?>
$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> has been saved.'));
$this->Flash->success(__('The <?php echo strtolower($singularHumanName); ?> has been saved.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> could not be saved. Please, try again.'));
$this->Flash->error(__('The <?php echo strtolower($singularHumanName); ?> could not be saved. Please, try again.'));
<?php else: ?>
return $this->flash(__('The <?php echo strtolower($singularHumanName); ?> has been saved.'), array('action' => 'index'));
<?php endif; ?>
@ -138,9 +138,9 @@
$this->request->allowMethod('post', 'delete');
if ($this-><?php echo $currentModelName; ?>->delete()) {
<?php if ($wannaUseSession): ?>
$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> has been deleted.'));
$this->Flash->success(__('The <?php echo strtolower($singularHumanName); ?> has been deleted.'));
} else {
$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> could not be deleted. Please, try again.'));
$this->Flash->error(__('The <?php echo strtolower($singularHumanName); ?> could not be deleted. Please, try again.'));
}
return $this->redirect(array('action' => 'index'));
<?php else: ?>

View file

@ -2895,6 +2895,10 @@ class Model extends Object implements CakeEventListener {
return false;
}
if ($this->useTable === false) {
return false;
}
return (bool)$this->find('count', array(
'conditions' => array(
$this->alias . '.' . $this->primaryKey => $id

View file

@ -1337,7 +1337,7 @@ class CakeResponse {
'download' => null
);
if (strpos($path, '..' . DS) !== false) {
if (strpos($path, '../') !== false || strpos($path, '..\\') !== false) {
throw new NotFoundException(__d(
'cake_dev',
'The requested file contains `..` and will not be read.'

View file

@ -222,7 +222,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('Paginator'), $result);
$this->assertSame(array('Paginator', 'Flash'), $result);
}
/**
@ -235,7 +235,7 @@ class ControllerTaskTest extends CakeTestCase {
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' RequestHandler, Security '));
$result = $this->Task->doComponents();
$expected = array('Paginator', 'RequestHandler', 'Security');
$expected = array('Paginator', 'Flash', 'RequestHandler', 'Security');
$this->assertEquals($expected, $result);
}
@ -249,7 +249,7 @@ class ControllerTaskTest extends CakeTestCase {
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' RequestHandler, Security, , '));
$result = $this->Task->doComponents();
$expected = array('Paginator', 'RequestHandler', 'Security');
$expected = array('Paginator', 'Flash', 'RequestHandler', 'Security');
$this->assertEquals($expected, $result);
}

View file

@ -1334,7 +1334,7 @@ class ModelIntegrationTest extends BaseModelTest {
$Article->useTable = false;
$Article->id = 1;
$result = $Article->exists();
$this->assertTrue($result);
$this->assertFalse($result);
}
/**

View file

@ -554,6 +554,44 @@ class ModelValidationTest extends BaseModelTest {
$this->assertEquals($expected, $result);
}
/**
* test that validates() still performs correctly when useTable = false on the model.
*
* @return void
*/
public function testValidatesWithNoTable() {
$TestModel = new TheVoid();
$TestModel->validate = array(
'title' => array(
'notEmpty' => array(
'rule' => array('notBlank'),
'required' => true,
),
'tooShort' => array(
'rule' => array('minLength', 10),
),
),
);
$data = array(
'TheVoid' => array(
'title' => 'too short',
),
);
$TestModel->create($data);
$result = $TestModel->validates();
$this->assertFalse($result);
$data = array(
'TheVoid' => array(
'id' => '1',
'title' => 'A good title',
),
);
$TestModel->create($data);
$result = $TestModel->validates();
$this->assertTrue($result);
}
/**
* test that validates() checks all the 'with' associations as well for validation
* as this can cause partial/wrong data insertion.

View file

@ -2785,18 +2785,9 @@ class ModelWriteTest extends BaseModelTest {
$TestModel = new TheVoid();
$this->assertFalse($TestModel->exists());
}
/**
* testRecordExistsMissingTable method
*
* @expectedException PDOException
* @return void
*/
public function testRecordExistsMissingTable() {
$TestModel = new TheVoid();
$TestModel->id = 5;
$TestModel->exists();
$this->assertFalse($TestModel->exists());
}
/**

View file

@ -1167,17 +1167,29 @@ class CakeResponseTest extends CakeTestCase {
}
/**
* test file with ..
* test file with ../
*
* @expectedException NotFoundException
* @expectedExceptionMessage The requested file contains `..` and will not be read.
* @return void
*/
public function testFileWithPathTraversal() {
public function testFileWithForwardSlashPathTraversal() {
$response = new CakeResponse();
$response->file('my/../cat.gif');
}
/**
* test file with ..\
*
* @expectedException NotFoundException
* @expectedExceptionMessage The requested file contains `..` and will not be read.
* @return void
*/
public function testFileWithBackwardSlashPathTraversal() {
$response = new CakeResponse();
$response->file('my\..\cat.gif');
}
/**
* Although unlikely, a file may contain dots in its filename.
* This should be allowed, as long as the dots doesn't specify a path (../ or ..\)

View file

@ -19,17 +19,28 @@
App::uses('CakeText', 'Utility');
/**
* CakeTextTest class
* CakeText Tests
*
* @package Cake.Test.Case.Utility
* @package Cake.Test.Case.Utility
* @coversDefaultClass CakeText
*/
class CakeTextTest extends CakeTestCase {
/**
* Setup object under test
*
* @return void
*/
public function setUp() {
parent::setUp();
$this->Text = new CakeText();
}
/**
* Tear down object under test
*
* @return void
*/
public function tearDown() {
parent::tearDown();
unset($this->Text);
@ -39,6 +50,7 @@ class CakeTextTest extends CakeTestCase {
* testUuidGeneration method
*
* @return void
* @covers ::uuid
*/
public function testUuidGeneration() {
$result = CakeText::uuid();
@ -51,6 +63,7 @@ class CakeTextTest extends CakeTestCase {
* testMultipleUuidGeneration method
*
* @return void
* @covers ::uuid
*/
public function testMultipleUuidGeneration() {
$check = array();
@ -70,6 +83,7 @@ class CakeTextTest extends CakeTestCase {
* testInsert method
*
* @return void
* @covers ::insert
*/
public function testInsert() {
$string = 'some string';
@ -231,6 +245,7 @@ class CakeTextTest extends CakeTestCase {
* test Clean Insert
*
* @return void
* @covers ::cleanInsert
*/
public function testCleanInsert() {
$result = CakeText::cleanInsert(':incomplete', array(
@ -271,6 +286,7 @@ class CakeTextTest extends CakeTestCase {
* CakeText::insert().
*
* @return void
* @covers ::insert
*/
public function testAutoIgnoreBadInsertData() {
$data = array('foo' => 'alpha', 'bar' => 'beta', 'fale' => array());
@ -282,6 +298,7 @@ class CakeTextTest extends CakeTestCase {
* testTokenize method
*
* @return void
* @covers ::tokenize
*/
public function testTokenize() {
$result = CakeText::tokenize('A,(short,boring test)');
@ -318,6 +335,7 @@ class CakeTextTest extends CakeTestCase {
* testReplaceWithQuestionMarkInString method
*
* @return void
* @covers ::insert
*/
public function testReplaceWithQuestionMarkInString() {
$string = ':a, :b and :c?';
@ -331,6 +349,8 @@ class CakeTextTest extends CakeTestCase {
*
* @dataProvider wordWrapProvider
* @return void
* @covers ::wordWrap
* @covers ::_wordWrap
*/
public function testWordWrap($text, $width, $break = "\n", $cut = false) {
$result = CakeText::wordWrap($text, $width, $break, $cut);
@ -364,6 +384,8 @@ class CakeTextTest extends CakeTestCase {
* test that wordWrap() properly handle unicode strings.
*
* @return void
* @covers ::wordWrap
* @covers ::_wordWrap
*/
public function testWordWrapUnicodeAware() {
$text = 'Но вим омниюм факёльиси элыктрам, мюнырэ лэгыры векж ыт. Выльёт квюандо нюмквуам ты кюм. Зыд эю рыбюм.';
@ -391,6 +413,8 @@ TEXT;
* test that wordWrap() properly handle newline characters.
*
* @return void
* @covers ::wordWrap
* @covers ::_wordWrap
*/
public function testWordWrapNewlineAware() {
$text = 'This is a line that is almost the 55 chars long.
@ -408,6 +432,9 @@ TEXT;
* test wrap method.
*
* @return void
* @covers ::wrap
* @covers ::wordWrap
* @covers ::_wordWrap
*/
public function testWrap() {
$text = 'This is the song that never ends. This is the song that never ends. This is the song that never ends.';
@ -443,6 +470,9 @@ TEXT;
* test wrap() indenting
*
* @return void
* @covers ::wrap
* @covers ::wordWrap
* @covers ::_wordWrap
*/
public function testWrapIndent() {
$text = 'This is the song that never ends. This is the song that never ends. This is the song that never ends.';
@ -459,6 +489,7 @@ TEXT;
* testTruncate method
*
* @return void
* @covers ::truncate
*/
public function testTruncate() {
$text1 = 'The quick brown fox jumps over the lazy dog';
@ -564,6 +595,7 @@ podeís adquirirla.</span></p>
* testTruncate method with non utf8 sites
*
* @return void
* @covers ::truncate
*/
public function testTruncateLegacy() {
Configure::write('App.encoding', 'ISO-8859-1');
@ -587,6 +619,7 @@ podeís adquirirla.</span></p>
* testTail method
*
* @return void
* @covers ::tail
*/
public function testTail() {
$text1 = 'The quick brown fox jumps over the lazy dog';
@ -630,6 +663,7 @@ podeís adquirirla.</span></p>
* testHighlight method
*
* @return void
* @covers ::highlight
*/
public function testHighlight() {
$text = 'This is a test text';
@ -664,6 +698,7 @@ podeís adquirirla.</span></p>
* testHighlightHtml method
*
* @return void
* @covers ::highlight
*/
public function testHighlightHtml() {
$text1 = '<p>strongbow isn&rsquo;t real cider</p>';
@ -690,6 +725,7 @@ podeís adquirirla.</span></p>
* testHighlightMulti method
*
* @return void
* @covers ::highlight
*/
public function testHighlightMulti() {
$text = 'This is a test text';
@ -703,6 +739,7 @@ podeís adquirirla.</span></p>
* testStripLinks method
*
* @return void
* @covers ::stripLinks
*/
public function testStripLinks() {
$text = 'This is a test text';
@ -730,6 +767,7 @@ podeís adquirirla.</span></p>
* testHighlightCaseInsensitivity method
*
* @return void
* @covers ::highlight
*/
public function testHighlightCaseInsensitivity() {
$text = 'This is a Test text';
@ -746,6 +784,7 @@ podeís adquirirla.</span></p>
* testExcerpt method
*
* @return void
* @covers ::excerpt
*/
public function testExcerpt() {
$text = 'This is a phrase with test text to play with';
@ -786,6 +825,7 @@ podeís adquirirla.</span></p>
* testExcerptCaseInsensitivity method
*
* @return void
* @covers ::excerpt
*/
public function testExcerptCaseInsensitivity() {
$text = 'This is a phrase with test text to play with';
@ -803,6 +843,7 @@ podeís adquirirla.</span></p>
* testListGeneration method
*
* @return void
* @covers ::toList
*/
public function testListGeneration() {
$result = $this->Text->toList(array());

View file

@ -33,10 +33,10 @@
if ($this->request->is('post')) {
$this->BakeArticle->create();
if ($this->BakeArticle->save($this->request->data)) {
$this->Session->setFlash(__('The bake article has been saved.'));
$this->Flash->success(__('The bake article has been saved.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The bake article could not be saved. Please, try again.'));
$this->Flash->error(__('The bake article could not be saved. Please, try again.'));
}
}
$bakeTags = $this->BakeArticle->BakeTag->find('list');
@ -56,10 +56,10 @@
}
if ($this->request->is(array('post', 'put'))) {
if ($this->BakeArticle->save($this->request->data)) {
$this->Session->setFlash(__('The bake article has been saved.'));
$this->Flash->success(__('The bake article has been saved.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The bake article could not be saved. Please, try again.'));
$this->Flash->error(__('The bake article could not be saved. Please, try again.'));
}
} else {
$options = array('conditions' => array('BakeArticle.' . $this->BakeArticle->primaryKey => $id));
@ -83,9 +83,9 @@
}
$this->request->allowMethod('post', 'delete');
if ($this->BakeArticle->delete()) {
$this->Session->setFlash(__('The bake article has been deleted.'));
$this->Flash->success(__('The bake article has been deleted.'));
} else {
$this->Session->setFlash(__('The bake article could not be deleted. Please, try again.'));
$this->Flash->error(__('The bake article could not be deleted. Please, try again.'));
}
return $this->redirect(array('action' => 'index'));
}

View file

@ -1 +1,7 @@
<div id="<?php echo $key; ?>Message" class="<?php echo !empty($params['class']) ? $params['class'] : 'message'; ?>"><?php echo $message; ?></div>
<?php
$class = 'message';
if (!empty($params['class'])) {
$class .= ' ' . $params['class'];
}
?>
<div id="<?php echo h($key) ?>Message" class="<?php echo h($class) ?>"><?php echo h($message) ?></div>

View file

@ -0,0 +1 @@
<div id="<?php echo h($key) ?>Message" class="message error"><?php echo h($message) ?></div>

View file

@ -0,0 +1 @@
<div id="<?php echo h($key) ?>Message" class="message success"><?php echo h($message) ?></div>

View file

@ -84,6 +84,7 @@ class FlashHelper extends AppHelper {
$flash = $options + $flash;
CakeSession::delete("Message.$key");
$flash['key'] = $key;
return $this->_View->element($flash['element'], $flash);
}