assertEqual(ini_get('docref_root'), ''); $debugger = new Debugger(); $this->assertEqual(ini_get('docref_root'), 'http://php.net/'); } /** * test Excerpt writing * * @access public * @return void */ function testExcerpt() { $result = Debugger::excerpt(__FILE__, __LINE__, 2); $this->assertTrue(is_array($result)); $this->assertEqual(count($result), 5); $this->assertPattern('/function(.+)testExcerpt/', $result[1]); $result = Debugger::excerpt(__FILE__, 2, 2); $this->assertTrue(is_array($result)); $this->assertEqual(count($result), 4); $expected = '<?php'; $expected .= ''; $this->assertEqual($result[0], $expected); $return = Debugger::excerpt('[internal]', 2, 2); $this->assertTrue(empty($return)); } /** * testOutput method * * @access public * @return void */ function testOutput() { Debugger::invoke(Debugger::getInstance()); $result = Debugger::output(false); $this->assertEqual($result, ''); $out .= ''; $result = Debugger::output(true); $this->assertEqual($result[0]['error'], 'Notice'); $this->assertEqual($result[0]['description'], 'Undefined variable: out'); $this->assertPattern('/DebuggerTest::testOutput/', $result[0]['trace']); $this->assertPattern('/SimpleInvoker::invoke/', $result[0]['trace']); ob_start(); Debugger::output('txt'); $other .= ''; $result = ob_get_clean(); $this->assertPattern('/Undefined variable: other/', $result); $this->assertPattern('/Context:/', $result); $this->assertPattern('/DebuggerTest::testOutput/', $result); $this->assertPattern('/SimpleInvoker::invoke/', $result); ob_start(); Debugger::output('html'); $wrong .= ''; $result = ob_get_clean(); $this->assertPattern('/
.+<\/pre>/', $result);
		$this->assertPattern('/Notice<\/b>/', $result);
		$this->assertPattern('/variable: wrong/', $result);

		ob_start();
		Debugger::output('js');
		$buzz .= '';
		$result = explode('', ob_get_clean());
		$this->assertTags($result[0], array(
			'pre' => array('class' => 'cake-debug'),
			'a' => array(
				'href' => "javascript:void(0);",
				'onclick' => "document.getElementById('cakeErr4-trace').style.display = " .
				             "(document.getElementById('cakeErr4-trace').style.display == 'none'" .
				             " ? '' : 'none');"
			),
			'b' => array(), 'Notice', '/b', ' (8)',
		));

		$this->assertPattern('/Undefined variable: buzz/', $result[1]);
		$this->assertPattern('/]+>Code/', $result[1]);
		$this->assertPattern('/]+>Context/', $result[2]);
		set_error_handler('simpleTestErrorHandler');
	}

/**
 * Tests that changes in output formats using Debugger::output() change the templates used.
 *
 * @return void
 */
	function testChangeOutputFormats() {
		Debugger::invoke(Debugger::getInstance());
		Debugger::output('js', array(
			'traceLine' => '{:reference} - {:path}, line {:line}'
		));
		$result = Debugger::trace();
		$this->assertPattern('/' . preg_quote('txmt://open?url=file:///', '/') . '/', $result);

		Debugger::output('xml', array(
			'error' => '{:code}{:file}{:line}' .
			           '{:description}',
			'context' => "{:context}",
			'trace' => "{:trace}",
		));
		Debugger::output('xml');

		ob_start();
		$foo .= '';
		$result = ob_get_clean();
		set_error_handler('simpleTestErrorHandler');

		$data = array(
			'error' => array(),
			'code' => array(), '8', '/code',
			'file' => array(), 'preg:/[^<]+/', '/file',
			'line' => array(), '' . (intval(__LINE__) + -8), '/line',
			'Undefined variable: foo',
			'/error'
		);
		$this->assertTags($result, $data, true);
	}

/**
 * testTrimPath method
 *
 * @access public
 * @return void
 */
	function testTrimPath() {
		$this->assertEqual(Debugger::trimPath(APP), 'APP' . DS);
		$this->assertEqual(Debugger::trimPath(CAKE_CORE_INCLUDE_PATH), 'CORE');
	}

/**
 * testExportVar method
 *
 * @access public
 * @return void
 */
	function testExportVar() {
		App::import('Controller');
		$Controller = new Controller();
		$Controller->helpers = array('Html', 'Form');
		$View = new View($Controller);
		$result = Debugger::exportVar($View);
		$expected = 'ViewView::$base = NULL
		View::$here = NULL
		View::$plugin = NULL
		View::$name = ""
		View::$action = NULL
		View::$params = array
		View::$passedArgs = array
		View::$data = array
		View::$helpers = array
		View::$viewPath = ""
		View::$viewVars = array
		View::$layout = "default"
		View::$layoutPath = NULL
		View::$pageTitle = false
		View::$autoRender = true
		View::$autoLayout = true
		View::$ext = ".ctp"
		View::$subDir = NULL
		View::$themeWeb = NULL
		View::$cacheAction = false
		View::$validationErrors = array
		View::$hasRendered = false
		View::$loaded = array
		View::$modelScope = false
		View::$model = NULL
		View::$association = NULL
		View::$field = NULL
		View::$fieldSuffix = NULL
		View::$modelId = NULL
		View::$uuids = array
		View::$output = false
		View::$__passedVars = array
		View::$__scripts = array
		View::$__paths = array
		View::$_log = NULL
		View::$webroot = NULL';
		$result = str_replace(array("\t", "\r\n", "\n"), "", $result);
		$expected =  str_replace(array("\t", "\r\n", "\n"), "", $expected);
		$this->assertEqual($result, $expected);
	}

/**
 * testLog method
 *
 * @access public
 * @return void
 */
	function testLog() {
		if (file_exists(LOGS . 'debug.log')) {
			unlink(LOGS . 'debug.log');
		}

		Debugger::log('cool');
		$result = file_get_contents(LOGS . 'debug.log');
		$this->assertPattern('/DebuggerTest\:\:testLog/', $result);
		$this->assertPattern('/"cool"/', $result);

		unlink(TMP . 'logs' . DS . 'debug.log');

		Debugger::log(array('whatever', 'here'));
		$result = file_get_contents(TMP . 'logs' . DS . 'debug.log');
		$this->assertPattern('/DebuggerTest\:\:testLog/', $result);
		$this->assertPattern('/array/', $result);
		$this->assertPattern('/"whatever",/', $result);
		$this->assertPattern('/"here"/', $result);
	}

/**
 * testDump method
 *
 * @access public
 * @return void
 */
	function testDump() {
		$var = array('People' => array(
					array(
					'name' => 'joeseph',
					'coat' => 'technicolor',
					'hair_color' => 'brown'
					),
					array(
					'name' => 'Shaft',
					'coat' => 'black',
					'hair' => 'black'
					)
				)
			);
		ob_start();
		Debugger::dump($var);
		$result = ob_get_clean();
		$expected = "
array(\n\t\"People\" => array()\n)
"; $this->assertEqual($expected, $result); } /** * test getInstance. * * @access public * @return void */ function testGetInstance() { $result = Debugger::getInstance(); $this->assertIsA($result, 'Debugger'); $result = Debugger::getInstance('DebuggerTestCaseDebugger'); $this->assertIsA($result, 'DebuggerTestCaseDebugger'); $result = Debugger::getInstance(); $this->assertIsA($result, 'DebuggerTestCaseDebugger'); $result = Debugger::getInstance('Debugger'); $this->assertIsA($result, 'Debugger'); } } ?>