Browse Source

Merge pull request #5529 from cakephp/restore-debugger-tests

Restore tests for Debugger::addFormat()
José Lorenzo Rodríguez 11 years ago
parent
commit
0c473eb243
1 changed files with 70 additions and 1 deletions
  1. 70 1
      tests/TestCase/Error/DebuggerTest.php

+ 70 - 1
tests/TestCase/Error/DebuggerTest.php

@@ -147,13 +147,82 @@ class DebuggerTest extends TestCase
     }
     }
 
 
     /**
     /**
+     * Tests that changes in output formats using Debugger::output() change the templates used.
+     *
+     * @return void
+     */
+    public function testAddFormat()
+    {
+        Debugger::addFormat('js', array(
+            'traceLine' => '{:reference} - <a href="txmt://open?url=file://{:file}' .
+                '&line={:line}">{:path}</a>, line {:line}'
+        ));
+        Debugger::outputAs('js');
+
+        $result = Debugger::trace();
+        $this->assertRegExp('/' . preg_quote('txmt://open?url=file://', '/') . '(\/|[A-Z]:\\\\)' . '/', $result);
+
+        Debugger::addFormat('xml', array(
+            'error' => '<error><code>{:code}</code><file>{:file}</file><line>{:line}</line>' .
+                '{:description}</error>',
+        ));
+        Debugger::outputAs('xml');
+
+        ob_start();
+        $debugger = Debugger::getInstance();
+        $debugger->outputError([
+            'level' => E_NOTICE,
+            'code' => E_NOTICE,
+            'file' => __FILE__,
+            'line' => __LINE__,
+            'description' => 'Undefined variable: foo',
+        ]);
+        $result = ob_get_clean();
+
+        $expected = array(
+            '<error',
+            '<code', '8', '/code',
+            '<file', 'preg:/[^<]+/', '/file',
+            '<line', '' . ((int)__LINE__ - 9), '/line',
+            'preg:/Undefined variable:\s+foo/',
+            '/error'
+        );
+        $this->assertHtml($expected, $result, true);
+    }
+
+    /**
+     * Test adding a format that is handled by a callback.
+     *
+     * @return void
+     */
+    public function testAddFormatCallback()
+    {
+        Debugger::addFormat('callback', array('callback' => array($this, 'customFormat')));
+        Debugger::outputAs('callback');
+
+        ob_start();
+        $debugger = Debugger::getInstance();
+        $debugger->outputError([
+            'error' => 'Notice',
+            'code' => E_NOTICE,
+            'level' => E_NOTICE,
+            'description' => 'Undefined variable $foo',
+            'file' => __FILE__,
+            'line' => __LINE__,
+        ]);
+        $result = ob_get_clean();
+        $this->assertContains('Notice: I eated an error', $result);
+        $this->assertContains('DebuggerTest.php', $result);
+    }
+
+    /**
      * Test method for testing addFormat with callbacks.
      * Test method for testing addFormat with callbacks.
      *
      *
      * @return void
      * @return void
      */
      */
     public function customFormat($error, $strings)
     public function customFormat($error, $strings)
     {
     {
-        return $error['error'] . ': I eated an error ' . $error['file'];
+        echo $error['error'] . ': I eated an error ' . $error['file'];
     }
     }
 
 
     /**
     /**