_restoreError) { restore_error_handler(); } } /** * testDocRef method * * @return void */ public function testDocRef() { ini_set('docref_root', ''); $this->assertEquals(ini_get('docref_root'), ''); new Debugger(); $this->assertEquals(ini_get('docref_root'), 'http://php.net/'); } /** * test Excerpt writing * * @return void */ public function testExcerpt() { $result = Debugger::excerpt(__FILE__, __LINE__, 2); $this->assertTrue(is_array($result)); $this->assertEquals(5, count($result)); $this->assertMatchesRegularExpression('/function(.+)testExcerpt/', $result[1]); $result = Debugger::excerpt(__FILE__, 2, 2); $this->assertTrue(is_array($result)); $this->assertEquals(4, count($result)); $pattern = '/.*?.*?<\?php/'; $this->assertMatchesRegularExpression($pattern, $result[0]); $result = Debugger::excerpt(__FILE__, 11, 2); $this->assertEquals(5, count($result)); $pattern = '/\*<\/span>/'; $this->assertMatchesRegularExpression($pattern, $result[0]); $return = Debugger::excerpt('[internal]', 2, 2); $this->assertTrue(empty($return)); } /** * testOutput method * * @return void */ public function testOutput() { set_error_handler('Debugger::showError'); $this->_restoreError = true; $result = Debugger::output(false); $this->assertEquals('', $result); $out .= ''; $result = Debugger::output(true); $this->assertEquals('Notice', $result[0]['error']); $this->assertMatchesRegularExpression('/Undefined variable\:\s+out/', $result[0]['description']); $this->assertMatchesRegularExpression('/DebuggerTest::testOutput/i', $result[0]['trace']); ob_start(); Debugger::output('txt'); $other .= ''; $result = ob_get_clean(); $this->assertMatchesRegularExpression('/Undefined variable:\s+other/', $result); $this->assertMatchesRegularExpression('/Context:/', $result); $this->assertMatchesRegularExpression('/DebuggerTest::testOutput/i', $result); ob_start(); Debugger::output('html'); $wrong .= ''; $result = ob_get_clean(); $this->assertMatchesRegularExpression('/
.+<\/pre>/', $result);
		$this->assertMatchesRegularExpression('/Notice<\/b>/', $result);
		$this->assertMatchesRegularExpression('/variable:\s+wrong/', $result);

		ob_start();
		Debugger::output('js');
		$buzz .= '';
		$result = explode('', ob_get_clean());
		$this->assertTags($result[0], array(
			'pre' => array('class' => 'cake-error'),
			'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'\);/"
			),
			'b' => array(), 'Notice', '/b', ' (8)',
		));

		$this->assertMatchesRegularExpression('/Undefined variable:\s+buzz/', $result[1]);
		$this->assertMatchesRegularExpression('/]+>Code/', $result[1]);
		$this->assertMatchesRegularExpression('/]+>Context/', $result[2]);
		$this->assertContains('$wrong = ''', $result[3], 'Context should be HTML escaped.');
	}

/**
 * test encodes error messages
 *
 * @return void
 */
	public function testOutputEncodeDescription() {
		set_error_handler('Debugger::showError');
		$this->_restoreError = true;

		ob_start();
		$a = array();
		$b = $a[''];
		$result = ob_get_clean();

		$this->assertNotContains('