Browse Source

Adding tests for Debugger::addFormat()

Mark Story 14 years ago
parent
commit
48c6b78660
1 changed files with 39 additions and 0 deletions
  1. 39 0
      lib/Cake/Test/Case/Utility/DebuggerTest.php

+ 39 - 0
lib/Cake/Test/Case/Utility/DebuggerTest.php

@@ -217,6 +217,45 @@ class DebuggerTest extends CakeTestCase {
 	}
 
 /**
+ * Tests that changes in output formats using Debugger::output() change the templates used.
+ *
+ * @return void
+ */
+	public function testAddFormat() {
+		set_error_handler('Debugger::showError');
+		$this->_restoreError = true;
+
+		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->assertPattern('/' . 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();
+		$foo .= '';
+		$result = ob_get_clean();
+
+		$data = array(
+			'<error',
+			'<code', '8', '/code',
+			'<file', 'preg:/[^<]+/', '/file',
+			'<line', '' . (intval(__LINE__) - 7), '/line',
+			'preg:/Undefined variable:\s+foo/',
+			'/error'
+		);
+		$this->assertTags($result, $data, true);
+	}
+
+/**
  * testTrimPath method
  *
  * @access public