2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * tests for Advisor class
6 * @package phpMyAdmin-test
12 require_once 'libraries/Advisor.class.php';
13 require_once 'libraries/php-gettext/gettext.inc';
14 require_once 'libraries/url_generating.lib.php';
15 require_once 'libraries/core.lib.php';
17 class Advisor_test
extends PHPUnit_Framework_TestCase
19 public function setup()
21 $_SESSION[' PMA_token '] = 'token';
22 $GLOBALS['lang'] = 'en';
26 * @dataProvider escapeStrings
28 public function testEscape($text, $expected)
30 $this->assertEquals(Advisor
::escapePercent($text), $expected);
33 public function escapeStrings() {
37 array('80% foo', '80%% foo'),
38 array('%s% foo', '%s%% foo'),
42 public function testParse()
44 $advisor = new Advisor();
45 $parseResult = $advisor->parseRulesFile();
46 $this->assertEquals($parseResult['errors'], array());
51 * @dataProvider rulesProvider
53 public function testAddRule($rule, $expected, $error)
55 $advisor = new Advisor();
56 $parseResult = $advisor->parseRulesFile();
57 $this->assertEquals($parseResult['errors'], array());
58 $advisor->variables
['value'] = 0;
59 $advisor->addRule('fired', $rule);
60 if (isset($advisor->runResult
['errors']) ||
!is_null($error)) {
61 $this->assertEquals($advisor->runResult
['errors'], array($error));
63 if (isset($advisor->runResult
['fired']) ||
$expected != array()) {
64 $this->assertEquals($advisor->runResult
['fired'], array($expected));
68 public function rulesProvider()
72 array('justification' => 'foo', 'name' => 'Basic', 'issue' => 'issue', 'recommendation' => 'Recommend'),
73 array('justification' => 'foo', 'name' => 'Basic', 'issue' => 'issue', 'recommendation' => 'Recommend'),
77 array('justification' => 'foo', 'name' => 'Variable', 'issue' => 'issue', 'recommendation' => 'Recommend {status_var}'),
78 array('justification' => 'foo', 'name' => 'Variable', 'issue' => 'issue', 'recommendation' => 'Recommend <a href="server_variables.php?lang=en&token=token#filter=status_var">status_var</a>'),
82 array('justification' => '%s foo | value', 'name' => 'Format', 'issue' => 'issue', 'recommendation' => 'Recommend'),
83 array('justification' => '0 foo', 'name' => 'Format', 'issue' => 'issue', 'recommendation' => 'Recommend'),
87 array('justification' => '%s% foo | value', 'name' => 'Percent', 'issue' => 'issue', 'recommendation' => 'Recommend'),
88 array('justification' => '0% foo', 'name' => 'Percent', 'issue' => 'issue', 'recommendation' => 'Recommend'),
92 array('justification' => '"\'foo', 'name' => 'Quotes', 'issue' => 'issue', 'recommendation' => 'Recommend"\''),
93 array('justification' => '"\'foo', 'name' => 'Quotes', 'issue' => 'issue', 'recommendation' => 'Recommend"\''),
97 array('justification' => 'foo | fsafdsa', 'name' => 'Failure', 'issue' => 'issue', 'recommendation' => 'Recommend'),
99 'Failed formatting string for rule \'Failure\'. PHP threw following error: Use of undefined constant fsafdsa - assumed \'fsafdsa\'',