Separate MediaWiki unit and integration tests
[lhc/web/wiklou.git] / tests / phpunit / unit / includes / libs / rdbms / ChronologyProtectorTest.php
1 <?php
2
3 /**
4 * Holds tests for ChronologyProtector abstract MediaWiki class.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
20 *
21 * @file
22 */
23
24 use Wikimedia\Rdbms\ChronologyProtector;
25
26 /**
27 * @group Database
28 * @covers \Wikimedia\Rdbms\ChronologyProtector::__construct
29 * @covers \Wikimedia\Rdbms\ChronologyProtector::getClientId
30 */
31 class ChronologyProtectorTest extends PHPUnit\Framework\TestCase {
32 /**
33 * @dataProvider clientIdProvider
34 * @param array $client
35 * @param string $secret
36 * @param string $expectedId
37 */
38 public function testClientId( array $client, $secret, $expectedId ) {
39 $bag = new HashBagOStuff();
40 $cp = new ChronologyProtector( $bag, $client, null, $secret );
41
42 $this->assertEquals( $expectedId, $cp->getClientId() );
43 }
44
45 public function clientIdProvider() {
46 return [
47 [
48 [
49 'ip' => '127.0.0.1',
50 'agent' => "Totally-Not-FireFox"
51 ],
52 '',
53 '45e93a9c215c031d38b7c42d8e4700ca',
54 ],
55 [
56 [
57 'ip' => '127.0.0.7',
58 'agent' => "Totally-Not-FireFox"
59 ],
60 '',
61 'b1d604117b51746c35c3df9f293c84dc'
62 ],
63 [
64 [
65 'ip' => '127.0.0.1',
66 'agent' => "Totally-FireFox"
67 ],
68 '',
69 '731b4e06a65e2346b497fc811571c4d7'
70 ],
71 [
72 [
73 'ip' => '127.0.0.1',
74 'agent' => "Totally-Not-FireFox"
75 ],
76 'secret',
77 'defff51ded73cd901253d874c9b2077d'
78 ]
79 ];
80 }
81 }