Fixed: Not selecting a datalabel used to issue a notice(undefined offset)
[phpmyadmin/ammaryasirr.git] / test / PMA_showHint_test.php
blob83707591ddaf56c3b4d1a12d59049e4dd9924dc1
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Test for PMA_showHint() function from common.lib.php
6 * @package phpMyAdmin-test
7 * @version $Id: PMA_showHint_test.php
8 */
10 /**
11 * Include to test.
13 require_once 'libraries/common.lib.php';
15 class PMA_showHint_test extends PHPUnit_Framework_TestCase
18 /**
19 * @var array temporary variable for globals array
21 protected $tmpGlobals;
23 /**
24 * @var array temporary variable for session array
26 protected $tmpSession;
28 /**
29 * storing globals and session
31 public function setUp()
33 $this->tmpGlobals = $GLOBALS;
34 $this->tmpSession = $_SESSION;
37 /**
38 * recovering globals and session
40 public function tearDown()
42 $GLOBALS = $this->tmpGlobals;
43 $_SESSION = $this->tmpSession;
46 /**
47 * PMA_showHint with defined GLOBALS
49 public function testShowHintReturnValue()
51 $key = md5('test');
52 $nr = 1234;
53 $instance = 1;
55 $GLOBALS['footnotes'][$key]['nr'] = $nr;
56 $GLOBALS['footnotes'][$key]['instance'] = $instance;
57 $this->assertEquals(sprintf('<sup class="footnotemarker" id="footnote_sup_%d_%d">%d</sup>',
58 $nr, $instance + 1, $nr), PMA_showHint('test'));
61 /**
62 * PMA_showHint with defined GLOBALS formatted as BB
64 public function testShowHintReturnValueBbFormat()
66 $key = md5('test');
67 $nr = 1234;
68 $instance = 1;
70 $GLOBALS['footnotes'][$key]['nr'] = $nr;
71 $GLOBALS['footnotes'][$key]['instance'] = $instance;
72 $this->assertEquals(sprintf('[sup]%d[/sup]', $nr),
73 PMA_showHint('test', true));
76 /**
77 * PMA_showHint with not defined GLOBALS
79 public function testShowHintSetting()
81 $key = md5('test');
82 $nr = 1;
83 $instance = 1;
85 $this->assertEquals(sprintf('<sup class="footnotemarker" id="footnote_sup_%d_%d">%d</sup>', $nr, $instance, $nr), PMA_showHint('test', false, 'notice'));
87 $expArray = array(
88 'note' => 'test',
89 'type' => 'notice',
90 'nr' => count($GLOBALS['footnotes']),
91 'instance' => 1,
94 $this->assertEquals($expArray, $GLOBALS['footnotes'][$key]);
97 /**
98 * PMA_showHint with not defined GLOBALS formatted as BB
99 * @depends testShowHintSetting
101 public function testShowHintSettingBbFormat()
103 $key = md5('test');
104 $nr = 1;
105 $instance = 1;
107 $this->assertEquals(sprintf('[sup]%d[/sup]', $nr), PMA_showHint('test', true, 'notice'));
109 $expArray = array(
110 'note' => 'test',
111 'type' => 'notice',
112 'nr' => count($GLOBALS['footnotes']),
113 'instance' => 1,
116 $this->assertEquals($expArray, $GLOBALS['footnotes'][$key]);
120 * PMA_showHint with defined GLOBALS using PMA_Message object
122 public function testShowHintPmaMessageReturnValue()
124 $nr = 1;
125 $instance = 1;
127 $oMock = $this->getMock('PMA_Message',
128 array('setMessage', 'setNumber', 'getHash', 'getLevel'));
129 $oMock->setMessage('test');
130 $oMock->setNumber($nr);
132 $key = $oMock->getHash();
134 $GLOBALS['footnotes'][$key]['nr'] = $nr;
135 $GLOBALS['footnotes'][$key]['instance'] = $instance;
137 $this->assertEquals(sprintf('<sup class="footnotemarker" id="footnote_sup_%d_%d">%d</sup>',
138 $nr, $instance + 1, $nr), PMA_showHint($oMock));
142 * PMA_showHint with not defined GLOBALS using PMA_Message object
144 public function testShowHintPmaMessageSetting()
146 $nr = 1;
147 $instance = 1;
149 $oMock = $this->getMock('PMA_Message',
150 array('setMessage', 'setNumber', 'getHash', 'getLevel', 'getNumber'));
151 $oMock->setMessage('test');
152 $oMock->setNumber($nr);
154 $this->assertEquals(sprintf('<sup class="footnotemarker" id="footnote_sup_%d_%d">%d</sup>', $nr, $instance, $nr), PMA_showHint($oMock, false));
156 $key = $oMock->getHash();
158 $expArray = array(
159 'note' => $oMock,
160 'type' => $oMock->getLevel(),
161 'nr' => count($GLOBALS['footnotes']),
162 'instance' => 1,
165 $this->assertEquals($expArray, $GLOBALS['footnotes'][$key]);