Browse files

Merge branch '2.1' into 2.2

  • Loading branch information...
2 parents fd216c4 + c6258fa commit 4dc07b6d3958a16d1a0fe31bb3fdd766586539a5 @markstory markstory committed May 16, 2012
View
9 lib/Cake/Test/Case/Utility/DebuggerTest.php
@@ -140,15 +140,16 @@ public function testOutput() {
'a' => array(
'href' => "javascript:void(0);",
'onclick' => "preg:/document\.getElementById\('cakeErr[a-z0-9]+\-trace'\)\.style\.display = " .
- "\(document\.getElementById\('cakeErr[a-z0-9]+\-trace'\)\.style\.display == 'none'" .
- " \? '' \: 'none'\);/"
+ "\(document\.getElementById\('cakeErr[a-z0-9]+\-trace'\)\.style\.display == 'none'" .
+ " \? '' \: 'none'\);/"
),
'b' => array(), 'Notice', '/b', ' (8)',
));
$this->assertRegExp('/Undefined variable:\s+buzz/', $result[1]);
$this->assertRegExp('/<a[^>]+>Code/', $result[1]);
$this->assertRegExp('/<a[^>]+>Context/', $result[2]);
+ $this->assertContains('$wrong = &#039;&#039;', $result[3], 'Context should be HTML escaped.');
}
/**
@@ -162,14 +163,14 @@ public function testChangeOutputFormats() {
Debugger::output('js', array(
'traceLine' => '{:reference} - <a href="txmt://open?url=file://{:file}' .
- '&line={:line}">{:path}</a>, line {:line}'
+ '&line={:line}">{:path}</a>, line {:line}'
));
$result = Debugger::trace();
$this->assertRegExp('/' . preg_quote('txmt://open?url=file://', '/') . '(\/|[A-Z]:\\\\)' . '/', $result);
Debugger::output('xml', array(
'error' => '<error><code>{:code}</code><file>{:file}</file><line>{:line}</line>' .
- '{:description}</error>',
+ '{:description}</error>',
'context' => "<context>{:context}</context>",
'trace' => "<stack>{:trace}</stack>",
));
View
52 lib/Cake/Test/Case/View/Helper/CacheHelperTest.php
@@ -291,15 +291,14 @@ public function testComplexNoCache() {
*/
public function testCacheViewVars() {
$this->Controller->cache_parsing();
- $this->Controller->params = array(
+ $this->Controller->request->addParams(array(
'controller' => 'cache_test',
'action' => 'cache_parsing',
'pass' => array(),
'named' => array()
- );
+ ));
+ $this->Controller->request->here = '/cacheTest/cache_parsing';
$this->Controller->cacheAction = 21600;
- $this->Controller->here = '/cacheTest/cache_parsing';
- $this->Controller->action = 'cache_parsing';
$View = new View($this->Controller);
$result = $View->render('index');
@@ -323,21 +322,20 @@ public function testCacheViewVars() {
* @return void
*/
public function testCacheCallbacks() {
- $this->Controller->cache_parsing();
- $this->Controller->params = array(
+ $this->Controller->request->addParams(array(
'controller' => 'cache_test',
'action' => 'cache_parsing',
'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';
+ $this->Controller->request->here = '/cacheTest/cache_parsing';
+ $this->Controller->cache_parsing();
$View = new View($this->Controller);
$result = $View->render('index');
@@ -358,58 +356,47 @@ public function testCacheCallbacks() {
* @return void
*/
public function testCacheActionArray() {
- $this->Controller->cache_parsing();
$this->Controller->request->addParams(array(
'controller' => 'cache_test',
'action' => 'cache_parsing',
'pass' => array(),
'named' => array()
));
+ $this->Controller->request->here = '/cache_test/cache_parsing';
$this->Controller->cacheAction = array(
'cache_parsing' => 21600
);
- $this->Controller->request->here = '/cache_test/cache_parsing';
- $this->Controller->action = 'cache_parsing';
-
- $View = new View($this->Controller);
- $result = $View->render('index');
-
- $this->assertNotRegExp('/cake:nocache/', $result);
- $this->assertNotRegExp('/php echo/', $result);
-
- $filename = CACHE . 'views' . DS . 'cache_test_cache_parsing.php';
- $this->assertTrue(file_exists($filename));
- @unlink($filename);
$this->Controller->cache_parsing();
- $this->Controller->cacheAction = array(
- 'cache_parsing' => 21600
- );
- $this->Controller->request->here = '/cacheTest/cache_parsing';
- $this->Controller->action = 'cache_parsing';
$View = new View($this->Controller);
$result = $View->render('index');
$this->assertNotRegExp('/cake:nocache/', $result);
$this->assertNotRegExp('/php echo/', $result);
- $filename = CACHE . 'views' . DS . 'cachetest_cache_parsing.php';
+ $filename = CACHE . 'views' . DS . 'cache_test_cache_parsing.php';
$this->assertTrue(file_exists($filename));
@unlink($filename);
+ }
- $this->Controller->cache_parsing();
+/**
+ * Test that cacheAction works with camelcased controller names.
+ *
+ * @return void
+ */
+ public function testCacheActionArrayCamelCase() {
$this->Controller->request->addParams(array(
'controller' => 'cache_test',
'action' => 'cache_parsing',
'pass' => array(),
'named' => array()
));
$this->Controller->cacheAction = array(
- 'some_other_action' => 21600
+ 'cache_parsing' => 21600
);
$this->Controller->request->here = '/cacheTest/cache_parsing';
- $this->Controller->action = 'cache_parsing';
+ $this->Controller->cache_parsing();
$View = new View($this->Controller);
$result = $View->render('index');
@@ -418,7 +405,8 @@ public function testCacheActionArray() {
$this->assertNotRegExp('/php echo/', $result);
$filename = CACHE . 'views' . DS . 'cachetest_cache_parsing.php';
- $this->assertFalse(file_exists($filename));
+ $this->assertTrue(file_exists($filename));
+ @unlink($filename);
}
/**
View
33 lib/Cake/Utility/Debugger.php
@@ -63,11 +63,13 @@ class Debugger {
'trace' => '<pre class="stack-trace">{:trace}</pre>',
'code' => '',
'context' => '',
- 'links' => array()
+ 'links' => array(),
+ 'escapeContext' => true,
),
'html' => array(
'trace' => '<pre class="cake-error trace"><b>Trace</b> <p>{:trace}</p></pre>',
- 'context' => '<pre class="cake-error context"><b>Context</b> <p>{:context}</p></pre>'
+ 'context' => '<pre class="cake-error context"><b>Context</b> <p>{:context}</p></pre>',
+ 'escapeContext' => true,
),
'txt' => array(
'error' => "{:error}: {:code} :: {:description} on line {:line} of {:path}\n{:info}",
@@ -716,7 +718,7 @@ public function outputError($data) {
$info = '';
foreach ((array)$data['context'] as $var => $value) {
- $context[] = "\${$var}\t=\t" . $this->exportVar($value, 1);
+ $context[] = "\${$var} = " . $this->exportVar($value, 1);
}
switch ($this->_outputFormat) {
@@ -731,30 +733,29 @@ public function outputError($data) {
$data['trace'] = $trace;
$data['id'] = 'cakeErr' . uniqid();
$tpl = array_merge($this->_templates['base'], $this->_templates[$this->_outputFormat]);
- $insert = array('context' => join("\n", $context)) + $data;
-
- $detect = array('context');
if (isset($tpl['links'])) {
foreach ($tpl['links'] as $key => $val) {
- if (in_array($key, $detect) && empty($insert[$key])) {
- continue;
- }
- $links[$key] = String::insert($val, $insert, $insertOpts);
+ $links[$key] = String::insert($val, $data, $insertOpts);
}
}
- foreach (array('code', 'context', 'trace') as $key) {
- if (empty($$key) || !isset($tpl[$key])) {
+ if (!empty($tpl['escapeContext'])) {
+ $context = h($context);
+ }
+
+ $infoData = compact('code', 'context', 'trace');
+ foreach ($infoData as $key => $value) {
+ if (empty($value) || !isset($tpl[$key])) {
continue;
}
- if (is_array($$key)) {
- $$key = join("\n", $$key);
+ if (is_array($value)) {
+ $value = join("\n", $value);
}
- $info .= String::insert($tpl[$key], compact($key) + $insert, $insertOpts);
+ $info .= String::insert($tpl[$key], array($key => $value) + $data, $insertOpts);
}
$links = join(' ', $links);
- unset($data['context']);
+
if (isset($tpl['callback']) && is_callable($tpl['callback'])) {
return call_user_func($tpl['callback'], $data, compact('links', 'info'));
}
View
4 lib/Cake/View/View.php
@@ -332,8 +332,10 @@ public function __construct(Controller $controller = null) {
* @return CakeEventManager
*/
public function getEventManager() {
- if (empty($this->_eventManager) || !$this->_eventManagerConfigured) {
+ if (empty($this->_eventManager)) {
$this->_eventManager = new CakeEventManager();
+ }
+ if (!$this->_eventManagerConfigured) {
$this->_eventManager->attach($this->Helpers);
$this->_eventManagerConfigured = true;
}

0 comments on commit 4dc07b6

Please sign in to comment.