Debian Codegraph @

tests/phpunit/unit/includes/editpage/TextboxBuilderTest.php

raw symbols SCIP
1 <?php
2 /**
3 * Copyright (C) 2017 Kunal Mehta <[email protected]>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 */
20
21 namespace MediaWiki\Tests\Unit\EditPage;
22
23 use MediaWiki\EditPage\TextboxBuilder;
24 use MediaWikiUnitTestCase;
25
26 /**
27 * Split from \MediaWiki\Tests\EditPage\TextboxBuilderTest integration tests
28 *
29 * @covers \MediaWiki\EditPage\TextboxBuilder
30 */
31 class TextboxBuilderTest extends MediaWikiUnitTestCase {
32
33 public static function provideAddNewLineAtEnd() {
34 return [
35 [ '', '' ],
36 [ 'foo', "foo\n" ],
37 ];
38 }
39
40 /**
41 * @dataProvider provideAddNewLineAtEnd
42 */
43 public function testAddNewLineAtEnd( $input, $expected ) {
44 $builder = new TextboxBuilder();
45 $this->assertSame( $expected, $builder->addNewLineAtEnd( $input ) );
46 }
47
48 public static function provideMergeClassesIntoAttributes() {
49 return [
50 [
51 [],
52 [],
53 [],
54 ],
55 [
56 [ 'mw-new-classname' ],
57 [],
58 [ 'class' => 'mw-new-classname' ],
59 ],
60 [
61 [],
62 [ 'title' => 'My Title' ],
63 [ 'title' => 'My Title' ],
64 ],
65 [
66 [ 'mw-new-classname' ],
67 [ 'title' => 'My Title' ],
68 [ 'title' => 'My Title', 'class' => 'mw-new-classname' ],
69 ],
70 [
71 [ 'mw-new-classname' ],
72 [ 'class' => 'mw-existing-classname' ],
73 [ 'class' => 'mw-existing-classname mw-new-classname' ],
74 ],
75 [
76 [ 'mw-new-classname', 'mw-existing-classname' ],
77 [ 'class' => 'mw-existing-classname' ],
78 [ 'class' => 'mw-existing-classname mw-new-classname' ],
79 ],
80 ];
81 }
82
83 /**
84 * @dataProvider provideMergeClassesIntoAttributes
85 */
86 public function testMergeClassesIntoAttributes( $inputClasses, $inputAttributes, $expected ) {
87 $builder = new TextboxBuilder();
88 $this->assertSame(
89 $expected,
90 $builder->mergeClassesIntoAttributes( $inputClasses, $inputAttributes )
91 );
92 }
93
94 }