Blame view

framework/tests/dev/BacktraceTest.php 1.84 KB
0084d336   Administrator   Importers CRUD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
  <?php
  /**
   * @package framework
   * @subpackage tests
   */
  class BacktraceTest extends SapphireTest {
  	
  	public function testFullFuncNameWithArgsAndCustomCharLimit() {
  		$func = array(
  			'class' => 'MyClass',
  			'type' => '->',
  			'file' => 'MyFile.php',
  			'line' => 99,
  			'function' => 'myFunction',
  			'args' => array(
  				'number' => 1,
  				'mylongstring' => 'more than 20 characters 1234567890',
  			)
  		);
  		$this->assertEquals(
  			'MyClass->myFunction(1,more than 20 charact...)',
  			SS_Backtrace::full_func_name($func, true, 20)
  		);
  	}
  	
  	public function testIgnoredFunctionArgs() {
  		$bt = array(
  			array(
  				'type' => '->',
  				'file' => 'MyFile.php',
  				'line' => 99,
  				'function' => 'myIgnoredGlobalFunction',
  				'args' => array('password' => 'secred',)
  			),
  			array(
  				'class' => 'MyClass',
  				'type' => '->',
  				'file' => 'MyFile.php',
  				'line' => 99,
  				'function' => 'myIgnoredClassFunction',
  				'args' => array('password' => 'secred',)
  			),
  			array(
  				'class' => 'MyClass',
  				'type' => '->',
  				'file' => 'MyFile.php',
  				'line' => 99,
  				'function' => 'myFunction',
  				'args' => array('myarg' => 'myval')
  			)
  		);
  		$orig = Config::inst()->get('SS_Backtrace', 'ignore_function_args');
  		Config::inst()->update('SS_Backtrace', 'ignore_function_args', 
  			array(
  				array('MyClass', 'myIgnoredClassFunction'),
  				'myIgnoredGlobalFunction'
  			)
  		);
  
  		$filtered = SS_Backtrace::filter_backtrace($bt);
  
  		$this->assertEquals('<filtered>', $filtered[0]['args']['password'], 'Filters global functions');
  		$this->assertEquals('<filtered>', $filtered[1]['args']['password'], 'Filters class functions');
  		$this->assertEquals('myval', $filtered[2]['args']['myarg'], 'Doesnt filter other functions');
  		
  		Config::inst()->remove('SS_Backtrace', 'ignore_function_args');
  		Config::inst()->update('SS_Backtrace', 'ignore_function_args', $orig);
  	}
  	
  }