Merge branch '1.3' into merger

Conflicts:
	cake/libs/controller/components/security.php
	cake/libs/view/pages/home.ctp
	cake/libs/view/view.php
	lib/Cake/Cache/Engine/FileEngine.php
	lib/Cake/Config/config.php
	lib/Cake/Model/Datasource/Database/Postgres.php
	lib/Cake/Test/Case/Utility/SanitizeTest.php
	lib/Cake/Test/Case/Utility/SetTest.php
	lib/Cake/Test/Case/View/Helper/CacheHelperTest.php
	lib/Cake/Test/Case/View/Helper/FormHelperTest.php
	lib/Cake/VERSION.txt
	lib/Cake/View/Helper/CacheHelper.php
This commit is contained in:
mark_story 2011-08-14 14:39:49 -04:00
commit d93c8cb200
13 changed files with 147 additions and 34 deletions

View file

@ -66,6 +66,7 @@ class DATABASE_CONFIG {
'password' => 'password',
'database' => 'database_name',
'prefix' => '',
//'encoding' => 'utf8',
);
public $test = array(
@ -76,5 +77,6 @@ class DATABASE_CONFIG {
'password' => 'password',
'database' => 'test_database_name',
'prefix' => '',
//'encoding' => 'utf8',
);
}

View file

@ -124,19 +124,24 @@ class FileEngine extends CacheEngine {
}
}
if ($this->settings['lock']) {
$this->_File->flock(LOCK_EX);
}
$expires = time() + $duration;
$contents = $expires . $lineBreak . $data . $lineBreak;
$success = $this->_File->ftruncate(0) && $this->_File->fwrite($contents);
if (!$handle = fopen($this->_File->path, 'c')) {
return false;
}
if ($this->settings['lock']) {
$this->_File->flock(LOCK_UN);
flock($handle, LOCK_EX);
}
$this->_File = null;
$success = ftruncate($handle, 0) && fwrite($handle, $contents) && fflush($handle);
if ($this->settings['lock']) {
flock($handle, LOCK_UN);
}
fclose($handle);
return $success;
}

View file

@ -66,6 +66,7 @@ class DATABASE_CONFIG {
'password' => 'password',
'database' => 'database_name',
'prefix' => '',
//'encoding' => 'utf8',
);
public $test = array(
@ -76,5 +77,6 @@ class DATABASE_CONFIG {
'password' => 'password',
'database' => 'test_database_name',
'prefix' => '',
//'encoding' => 'utf8',
);
}

View file

@ -297,7 +297,7 @@ class Postgres extends DboSource {
* and if 1, sequences are not modified
* @return boolean SQL TRUNCATE TABLE statement, false if not applicable.
*/
public function truncate($table, $reset = true) {
function truncate($table, $reset = 0) {
$table = $this->fullTableName($table, false);
if (!isset($this->_sequenceMap[$table])) {
$cache = $this->cacheSources;
@ -305,8 +305,9 @@ class Postgres extends DboSource {
$this->describe($table);
$this->cacheSources = $cache;
}
if (parent::truncate($table)) {
if (isset($this->_sequenceMap[$table]) && $reset) {
if ($this->execute('DELETE FROM ' . $this->fullTableName($table))) {
$table = $this->fullTableName($table, false);
if (isset($this->_sequenceMap[$table]) && $reset !== 1) {
foreach ($this->_sequenceMap[$table] as $field => $sequence) {
$this->_execute("ALTER SEQUENCE \"{$sequence}\" RESTART WITH 1");
}

View file

@ -453,6 +453,25 @@ class SecurityComponentTest extends CakeTestCase {
$this->assertTrue($this->Controller->Security->validatePost($this->Controller));
}
/**
* Test that validatePost fails if you are missing the session information.
*
* @return void
*/
function testValidatePostNoSession() {
$this->Controller->Security->startup($this->Controller);
$this->Controller->Session->delete('_Token');
$key = $this->Controller->params['_Token']['key'];
$fields = 'a5475372b40f6e3ccbf9f8af191f20e1642fd877%3AModel.valid';
$this->Controller->data = array(
'Model' => array('username' => 'nate', 'password' => 'foo', 'valid' => '0'),
'_Token' => compact('key', 'fields')
);
$this->assertFalse($this->Controller->Security->validatePost($this->Controller));
}
/**
* test that validatePost fails if any of its required fields are missing.
*

View file

@ -254,7 +254,12 @@ class SanitizeTest extends CakeTestCase {
$string = "This sentence \t\t\t has lots of \n\n white\nspace \rthat \r\n needs to be \t \n trimmed.";
$expected = "This sentence has lots of whitespace that needs to be trimmed.";
$result = Sanitize::stripWhitespace($string);
$this->assertEqual($expected, $result);
$this->assertEquals($expected, $result);
$text = 'I love ßá†ö√ letters.';
$result = Sanitize::stripWhitespace($text);
$expected = 'I love ßá†ö√ letters.';
$this->assertEqual($result, $expected);
}
/**

View file

@ -956,7 +956,7 @@ class SetTest extends CakeTestCase {
);
$result = Set::extract('/ParentNode/name', $hasMany);
$expected = array('Second');
$this->assertEqual($expected, $result);
$this->assertEquals($expected, $result);
$data = array(
array(
@ -990,7 +990,7 @@ class SetTest extends CakeTestCase {
)
);
$result = Set::extract('/Category[id=1]/..', $data);
$this->assertEqual($expected, $result);
$this->assertEquals($expected, $result);
$data = array(
array(
@ -1008,7 +1008,7 @@ class SetTest extends CakeTestCase {
'Item 2'
);
$result = Set::extract('/0/name', $data);
$this->assertEqual($expected, $result);
$this->assertEquals($expected, $result);
$data = array(
array('A1', 'B1'),
@ -1016,7 +1016,7 @@ class SetTest extends CakeTestCase {
);
$expected = array('A1', 'A2');
$result = Set::extract('/0', $data);
$this->assertEqual($expected, $result);
$this->assertEquals($expected, $result);
}
/**

View file

@ -325,6 +325,37 @@ class CacheHelperTest extends CakeTestCase {
@unlink($filename);
}
function testCacheCallbacks() {
$this->Controller->cache_parsing();
$this->Controller->params = array(
'controller' => 'cache_test',
'action' => 'cache_parsing',
'url' => array(),
'pass' => array(),
'named' => array()
);
$this->Controller->cacheAction = array(
'cache_parsing' => array(
'duration' => 21600,
'callbacks' => true
)
);
$this->Controller->here = '/cacheTest/cache_parsing';
$this->Controller->action = 'cache_parsing';
$View = new View($this->Controller);
$result = $View->render('index');
$filename = CACHE . 'views' . DS . 'cachetest_cache_parsing.php';
$this->assertTrue(file_exists($filename));
$contents = file_get_contents($filename);
$this->assertPattern('/\$controller->startupProcess\(\);/', $contents);
@unlink($filename);
}
/**
* test cacheAction set to a boolean
@ -559,11 +590,17 @@ class CacheHelperTest extends CakeTestCase {
* This test must be uncommented/fixed in next release (1.2+)
*
* @return void
* @access public
*
public function testCacheEmptySections () {
*/
public function testCacheEmptySections() {
$this->Controller->cache_parsing();
$this->Controller->cacheAction = array('cacheTest' => 21600);
$this->Controller->params = array(
'controller' => 'cacheTest',
'action' => 'cache_empty_sections',
'url' => array(),
'pass' => array(),
'named' => array()
);
$this->Controller->cacheAction = array('cache_empty_sections' => 21600);
$this->Controller->here = '/cacheTest/cache_empty_sections';
$this->Controller->action = 'cache_empty_sections';
$this->Controller->layout = 'cache_empty_sections';
@ -571,7 +608,7 @@ class CacheHelperTest extends CakeTestCase {
$View = new View($this->Controller);
$result = $View->render('cache_empty_sections');
$this->assertNoPattern('/cake:nocache/', $result);
$this->assertNoPattern('/nocache/', $result);
$this->assertNoPattern('/php echo/', $result);
$this->assertPattern(
'@</title>\s*</head>\s*' .
@ -583,19 +620,18 @@ class CacheHelperTest extends CakeTestCase {
$filename = CACHE . 'views' . DS . 'cachetest_cache_empty_sections.php';
$this->assertTrue(file_exists($filename));
$contents = file_get_contents($filename);
$this->assertNoPattern('/cake:nocache/', $contents);
$this->assertNoPattern('/nocache/', $contents);
$this->assertPattern(
'@<head>\s*<title>Posts</title>\s*' .
"<\?php \$x = 1; \?>\s*" .
'<\?php \$x \= 1; \?>\s*' .
'</head>\s*' .
'<body>\s*' .
"<\?php \$x\+\+; \?>\s*" .
"<\?php \$x\+\+; \?>\s*" .
'<\?php \$x\+\+; \?>\s*' .
'<\?php \$x\+\+; \?>\s*' .
'View Content\s*' .
"<\?php \$y = 1; \?>\s*" .
"<\?php echo 'cached count is:' . \$x; \?>\s*" .
'<\?php \$y = 1; \?>\s*' .
'<\?php echo \'cached count is: \' . \$x; \?>\s*' .
'@', $contents);
@unlink($filename);
}
*/
}

View file

@ -4720,13 +4720,14 @@ class FormHelperTest extends CakeTestCase {
);
$this->assertTags($result, $expected);
$selected = strtotime('2008-10-26 10:33:00');
$selected = strtotime('2008-10-26 12:33:00');
$result = $this->Form->dateTime('Model.field', 'DMY', '12', array('value' => $selected));
$this->assertPattern('/<option[^<>]+value="2008"[^<>]+selected="selected"[^>]*>2008<\/option>/', $result);
$this->assertPattern('/<option[^<>]+value="10"[^<>]+selected="selected"[^>]*>10<\/option>/', $result);
$this->assertPattern('/<option[^<>]+value="10"[^<>]+selected="selected"[^>]*>October<\/option>/', $result);
$this->assertPattern('/<option[^<>]+value="26"[^<>]+selected="selected"[^>]*>26<\/option>/', $result);
$this->assertPattern('/<option[^<>]+value="10"[^<>]+selected="selected"[^>]*>10<\/option>/', $result);
$this->assertPattern('/<option[^<>]+value="12"[^<>]+selected="selected"[^>]*>12<\/option>/', $result);
$this->assertPattern('/<option[^<>]+value="33"[^<>]+selected="selected"[^>]*>33<\/option>/', $result);
$this->assertPattern('/<option[^<>]+value="pm"[^<>]+selected="selected"[^>]*>pm<\/option>/', $result);
$this->Form->create('Contact');
$result = $this->Form->input('published');

View file

@ -611,6 +611,12 @@ class HtmlHelperTest extends CakeTestCase {
);
$this->assertTags($result, $expected);
$result = $this->Html->script('http://example.com/test.json');
$expected = array(
'script' => array('type' => 'text/javascript', 'src' => 'http://example.com/test.json.js')
);
$this->assertTags($result, $expected);
$result = $this->Html->script('/plugin/js/jquery-1.3.2.js?someparam=foo');
$expected = array(
'script' => array('type' => 'text/javascript', 'src' => '/plugin/js/jquery-1.3.2.js?someparam=foo')

View file

@ -122,7 +122,7 @@ class Sanitize {
*/
public static function stripWhitespace($str) {
$r = preg_replace('/[\n\r\t]+/', '', $str);
return preg_replace('/\s{2,}/', ' ', $r);
return preg_replace('/\s{2,}/u', ' ', $r);
}
/**

View file

@ -54,7 +54,7 @@ class CacheHelper extends AppHelper {
public function afterRender($viewFile) {
$caching = (($this->_View->cacheAction != false)) && (Configure::read('Cache.check') === true);
if ($caching) {
$this->cache($viewFile, $this->_View->output, false);
$this->_View->output = $this->cache($viewFile, $this->_View->output, false);
}
}
@ -66,11 +66,18 @@ class CacheHelper extends AppHelper {
public function afterLayout($layoutFile) {
$caching = (($this->_View->cacheAction != false)) && (Configure::read('Cache.check') === true);
if ($caching) {
$this->cache($layoutFile, $this->_View->output, true);
$this->_View->output = $this->cache($layoutFile, $this->_View->output, true);
}
$this->_View->output = preg_replace('/<!--\/?nocache-->/', '', $this->_View->output);
}
/**
* Counter used for counting nocache section tags.
*
* @var integer
*/
var $_counter = 0;
/**
* Main method used to cache a view
*
@ -118,10 +125,13 @@ class CacheHelper extends AppHelper {
}
if ($cacheTime != '' && $cacheTime > 0) {
$out = preg_replace_callback('/<!--nocache-->/', array($this, '_replaceSection'), $out);
$this->_parseFile($file, $out);
if ($cache === true) {
$cached = $this->_parseOutput($out);
$this->_writeFile($cached, $cacheTime, $useCallbacks);
$out = $this->_stripTags($out);
}
return $out;
} else {
@ -141,7 +151,7 @@ class CacheHelper extends AppHelper {
} elseif ($file = fileExistsInPath($file)) {
$file = file_get_contents($file);
}
preg_match_all('/(<!--nocache-->(?<=<!--nocache-->)[\\s\\S]*?(?=<!--\/nocache-->)<!--\/nocache-->)/i', $cache, $outputResult, PREG_PATTERN_ORDER);
preg_match_all('/(<!--nocache:\d{3}-->(?<=<!--nocache:\d{3}-->)[\\s\\S]*?(?=<!--\/nocache-->)<!--\/nocache-->)/i', $cache, $outputResult, PREG_PATTERN_ORDER);
preg_match_all('/(?<=<!--nocache-->)([\\s\\S]*?)(?=<!--\/nocache-->)/i', $file, $fileResult, PREG_PATTERN_ORDER);
$fileResult = $fileResult[0];
$outputResult = $outputResult[0];
@ -168,6 +178,30 @@ class CacheHelper extends AppHelper {
}
}
/**
* Munges the output from a view with cache tags, and numbers the sections.
* This helps solve issues with empty/duplicate content.
*
* @param string $content The content to munge.
* @return string The content with cake:nocache tags replaced.
*/
function _replaceSection($matches) {
$this->_counter += 1;
return sprintf('<!--nocache:%03d-->', $this->_counter);
}
/**
* Strip cake:nocache tags from a string. Since View::render()
* only removes un-numbered nocache tags, remove all the numbered ones.
* This is the complement to _replaceSection.
*
* @param string $content String to remove tags from.
* @return string String with tags removed.
*/
function _stripTags($content) {
return preg_replace('#<!--/?nocache(\:\d{3})?-->#', '', $content);
}
/**
* Parse the output and replace cache tags
*

View file

@ -2103,6 +2103,8 @@ class FormHelper extends AppHelper {
if (($time[0] > 12) && $timeFormat == '12') {
$time[0] = $time[0] - 12;
$meridian = 'pm';
} elseif ($time[0] == '12' && $timeFormat == '12') {
$meridian = 'pm';
} elseif ($time[0] == '00' && $timeFormat == '12') {
$time[0] = 12;
} elseif ($time[0] >= 12) {