Import: Handle uploads with sha1 starting with 0 properly
[mediawiki.git] / tests / phpunit / includes / content / CssContentTest.php
blob24b0c68227d63c875b140d76b31b4cffcb3eef7c
1 <?php
3 /**
4 * @group ContentHandler
5 * @group Database
6 * ^--- needed, because we do need the database to test link updates
8 * @FIXME this should not extend JavaScriptContentTest.
9 */
10 class CssContentTest extends JavaScriptContentTest {
12 protected function setUp() {
13 parent::setUp();
15 // Anon user
16 $user = new User();
17 $user->setName( '127.0.0.1' );
19 $this->setMwGlobals( array(
20 'wgUser' => $user,
21 'wgTextModelsToParse' => array(
22 CONTENT_MODEL_CSS,
24 ) );
27 public function newContent( $text ) {
28 return new CssContent( $text );
31 public static function dataGetParserOutput() {
32 return array(
33 array(
34 'MediaWiki:Test.css',
35 null,
36 "hello <world>\n",
37 "<pre class=\"mw-code mw-css\" dir=\"ltr\">\nhello &lt;world&gt;\n\n</pre>"
39 array(
40 'MediaWiki:Test.css',
41 null,
42 "/* hello [[world]] */\n",
43 "<pre class=\"mw-code mw-css\" dir=\"ltr\">\n/* hello [[world]] */\n\n</pre>",
44 array(
45 'Links' => array(
46 array( 'World' => 0 )
51 // TODO: more...?
55 /**
56 * @covers CssContent::getModel
58 public function testGetModel() {
59 $content = $this->newContent( 'hello world.' );
61 $this->assertEquals( CONTENT_MODEL_CSS, $content->getModel() );
64 /**
65 * @covers CssContent::getContentHandler
67 public function testGetContentHandler() {
68 $content = $this->newContent( 'hello world.' );
70 $this->assertEquals( CONTENT_MODEL_CSS, $content->getContentHandler()->getModelID() );
73 /**
74 * Redirects aren't supported
76 public static function provideUpdateRedirect() {
77 return array(
78 array(
79 '#REDIRECT [[Someplace]]',
80 '#REDIRECT [[Someplace]]',
85 /**
86 * @dataProvider provideGetRedirectTarget
88 public function testGetRedirectTarget( $title, $text ) {
89 $this->setMwGlobals( array(
90 'wgServer' => '//example.org',
91 'wgScriptPath' => '/w',
92 'wgScript' => '/w/index.php',
93 ) );
94 $content = new CssContent( $text );
95 $target = $content->getRedirectTarget();
96 $this->assertEquals( $title, $target ? $target->getPrefixedText() : null );
99 /**
100 * Keep this in sync with CssContentHandlerTest::provideMakeRedirectContent()
102 public static function provideGetRedirectTarget() {
103 // @codingStandardsIgnoreStart Generic.Files.LineLength
104 return array(
105 array( 'MediaWiki:MonoBook.css', "/* #REDIRECT */@import url(//example.org/w/index.php?title=MediaWiki:MonoBook.css&action=raw&ctype=text/css);" ),
106 array( 'User:FooBar/common.css', "/* #REDIRECT */@import url(//example.org/w/index.php?title=User:FooBar/common.css&action=raw&ctype=text/css);" ),
107 array( 'Gadget:FooBaz.css', "/* #REDIRECT */@import url(//example.org/w/index.php?title=Gadget:FooBaz.css&action=raw&ctype=text/css);" ),
108 # No #REDIRECT comment
109 array( null, "@import url(//example.org/w/index.php?title=Gadget:FooBaz.css&action=raw&ctype=text/css);" ),
110 # Wrong domain
111 array( null, "/* #REDIRECT */@import url(//example.com/w/index.php?title=Gadget:FooBaz.css&action=raw&ctype=text/css);" ),
113 // @codingStandardsIgnoreEnd
116 public static function dataEquals() {
117 return array(
118 array( new CssContent( 'hallo' ), null, false ),
119 array( new CssContent( 'hallo' ), new CssContent( 'hallo' ), true ),
120 array( new CssContent( 'hallo' ), new WikitextContent( 'hallo' ), false ),
121 array( new CssContent( 'hallo' ), new CssContent( 'HALLO' ), false ),
126 * @dataProvider dataEquals
127 * @covers CssContent::equals
129 public function testEquals( Content $a, Content $b = null, $equal = false ) {
130 $this->assertEquals( $equal, $a->equals( $b ) );