Fixed: 'Browse foreign values' not working properly
[phpmyadmin/ammaryasirr.git] / test / classes / Advisor_test.php
blob9a92fe5614480a1274d4a245102eb6cfaf7fcc6b
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * tests for Advisor class
6 * @package phpMyAdmin-test
7 */
9 /*
10 * Include to 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';
25 /**
26 * @dataProvider escapeStrings
28 public function testEscape($text, $expected)
30 $this->assertEquals(Advisor::escapePercent($text), $expected);
33 public function escapeStrings() {
34 return array(
35 array('80%', '80%%'),
36 array('%s%', '%s%%'),
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());
49 /**
50 * @depends testParse
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()
70 return array(
71 array(
72 array('justification' => 'foo', 'name' => 'Basic', 'issue' => 'issue', 'recommendation' => 'Recommend'),
73 array('justification' => 'foo', 'name' => 'Basic', 'issue' => 'issue', 'recommendation' => 'Recommend'),
74 null,
76 array(
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&amp;token=token#filter=status_var">status_var</a>'),
79 null,
81 array(
82 array('justification' => '%s foo | value', 'name' => 'Format', 'issue' => 'issue', 'recommendation' => 'Recommend'),
83 array('justification' => '0 foo', 'name' => 'Format', 'issue' => 'issue', 'recommendation' => 'Recommend'),
84 null,
86 array(
87 array('justification' => '%s% foo | value', 'name' => 'Percent', 'issue' => 'issue', 'recommendation' => 'Recommend'),
88 array('justification' => '0% foo', 'name' => 'Percent', 'issue' => 'issue', 'recommendation' => 'Recommend'),
89 null,
91 array(
92 array('justification' => '"\'foo', 'name' => 'Quotes', 'issue' => 'issue', 'recommendation' => 'Recommend"\''),
93 array('justification' => '"\'foo', 'name' => 'Quotes', 'issue' => 'issue', 'recommendation' => 'Recommend"\''),
94 null,
96 array(
97 array('justification' => 'foo | fsafdsa', 'name' => 'Failure', 'issue' => 'issue', 'recommendation' => 'Recommend'),
98 array(),
99 'Failed formatting string for rule \'Failure\'. PHP threw following error: Use of undefined constant fsafdsa - assumed \'fsafdsa\'',