Translation update done using Pootle.
[phpmyadmin.git] / test / classes / Advisor_test.php
blobc57b367d568fb24dcf3c71106aba25a11714b820
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';
23 $_SESSION['PMA_Theme'] = PMA_Theme::load('./themes/pmahomme');
26 /**
27 * @dataProvider escapeStrings
29 public function testEscape($text, $expected)
31 $this->assertEquals(Advisor::escapePercent($text), $expected);
34 public function escapeStrings() {
35 return array(
36 array('80%', '80%%'),
37 array('%s%', '%s%%'),
38 array('80% foo', '80%% foo'),
39 array('%s% foo', '%s%% foo'),
43 public function testParse()
45 $advisor = new Advisor();
46 $parseResult = $advisor->parseRulesFile();
47 $this->assertEquals($parseResult['errors'], array());
50 /**
51 * @depends testParse
52 * @dataProvider rulesProvider
54 public function testAddRule($rule, $expected, $error)
56 $advisor = new Advisor();
57 $parseResult = $advisor->parseRulesFile();
58 $this->assertEquals($parseResult['errors'], array());
59 $advisor->variables['value'] = 0;
60 $advisor->addRule('fired', $rule);
61 if (isset($advisor->runResult['errors']) || !is_null($error)) {
62 $this->assertEquals($advisor->runResult['errors'], array($error));
64 if (isset($advisor->runResult['fired']) || $expected != array()) {
65 $this->assertEquals($advisor->runResult['fired'], array($expected));
69 public function rulesProvider()
71 return array(
72 array(
73 array('justification' => 'foo', 'name' => 'Basic', 'issue' => 'issue', 'recommendation' => 'Recommend'),
74 array('justification' => 'foo', 'name' => 'Basic', 'issue' => 'issue', 'recommendation' => 'Recommend'),
75 null,
77 array(
78 array('justification' => 'foo', 'name' => 'Variable', 'issue' => 'issue', 'recommendation' => 'Recommend {status_var}'),
79 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>'),
80 null,
82 array(
83 array('justification' => '%s foo | value', 'name' => 'Format', 'issue' => 'issue', 'recommendation' => 'Recommend'),
84 array('justification' => '0 foo', 'name' => 'Format', 'issue' => 'issue', 'recommendation' => 'Recommend'),
85 null,
87 array(
88 array('justification' => '%s% foo | value', 'name' => 'Percent', 'issue' => 'issue', 'recommendation' => 'Recommend'),
89 array('justification' => '0% foo', 'name' => 'Percent', 'issue' => 'issue', 'recommendation' => 'Recommend'),
90 null,
92 array(
93 array('justification' => '"\'foo', 'name' => 'Quotes', 'issue' => 'issue', 'recommendation' => 'Recommend"\''),
94 array('justification' => '"\'foo', 'name' => 'Quotes', 'issue' => 'issue', 'recommendation' => 'Recommend"\''),
95 null,
97 array(
98 array('justification' => 'foo | fsafdsa', 'name' => 'Failure', 'issue' => 'issue', 'recommendation' => 'Recommend'),
99 array(),
100 'Failed formatting string for rule \'Failure\'. PHP threw following error: Use of undefined constant fsafdsa - assumed \'fsafdsa\'',