Syntax:
* Call parent setUp from setUp.
* Set required globals for the test inside the test class instead
of assuming the default settings.
* Data providers are called statically and outside setUp/tearDown
("public static function")
* Test function names should be prefixed with "test"
("testIsRedirect")
* Marked 2 functions as unused. JavascriptContentTest has 2 data
providers for tests that don't exist in it (nor in TextContentText)
but do exist in WikitextContentTest.
Style:
* Single quotes
* Remove odd comment "# =====" lines
* Consistent tree wrapping with arrays.
array(
array(
.. ) );
array(
array(
..
)
);
Some were closing on the previous line instead.
Made it consistent now.
* Remove odd indentation to make nested arrays line up:
array( 'foo' => array( 'bar' => true,
'baz' => array() ) )
array( 'foo' => array(
'bar' => true,
'baz' => array()
) )
We don't do this kind of indentation because it is fragile
and becomes outdates when any of the earlier keys ("foo")
change. Converted to a regular tree instead.
Also triggered git warnings for mixing spaces with tabs, which
is almost always an detector for this style.
* Not using @annotations in inline comments, reserved (and only
parsed/meaningful) for block comments.
Follows-up 8b568be5e2
Change-Id: Ic55d539b9a58f448b550bcd98894d389764e0694
81 lines
1.8 KiB
PHP
81 lines
1.8 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group ContentHandler
|
|
* @group Database
|
|
* ^--- needed, because we do need the database to test link updates
|
|
*/
|
|
class CssContentTest extends MediaWikiTestCase {
|
|
|
|
protected function setUp() {
|
|
parent::setUp();
|
|
|
|
// Anon user
|
|
$user = new User();
|
|
$user->setName( '127.0.0.1' );
|
|
|
|
$this->setMwGlobals( array(
|
|
'wgUser' => $user,
|
|
'wgTextModelsToParse' => array(
|
|
CONTENT_MODEL_CSS,
|
|
)
|
|
) );
|
|
}
|
|
|
|
public function newContent( $text ) {
|
|
return new CssContent( $text );
|
|
}
|
|
|
|
public static function dataGetParserOutput() {
|
|
return array(
|
|
array(
|
|
'MediaWiki:Test.css',
|
|
null,
|
|
"hello <world>\n",
|
|
"<pre class=\"mw-code mw-css\" dir=\"ltr\">\nhello <world>\n\n</pre>"
|
|
),
|
|
array(
|
|
'MediaWiki:Test.css',
|
|
null,
|
|
"/* hello [[world]] */\n",
|
|
"<pre class=\"mw-code mw-css\" dir=\"ltr\">\n/* hello [[world]] */\n\n</pre>",
|
|
array(
|
|
'Links' => array(
|
|
array( 'World' => 0 )
|
|
)
|
|
)
|
|
),
|
|
|
|
// TODO: more...?
|
|
);
|
|
}
|
|
|
|
public function testGetModel() {
|
|
$content = $this->newContent( 'hello world.' );
|
|
|
|
$this->assertEquals( CONTENT_MODEL_CSS, $content->getModel() );
|
|
}
|
|
|
|
public function testGetContentHandler() {
|
|
$content = $this->newContent( 'hello world.' );
|
|
|
|
$this->assertEquals( CONTENT_MODEL_CSS, $content->getContentHandler()->getModelID() );
|
|
}
|
|
|
|
public static function dataEquals( ) {
|
|
return array(
|
|
array( new CssContent( 'hallo' ), null, false ),
|
|
array( new CssContent( 'hallo' ), new CssContent( 'hallo' ), true ),
|
|
array( new CssContent( 'hallo' ), new WikitextContent( 'hallo' ), false ),
|
|
array( new CssContent( 'hallo' ), new CssContent( 'HALLO' ), false ),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @dataProvider dataEquals
|
|
*/
|
|
public function testEquals( Content $a, Content $b = null, $equal = false ) {
|
|
$this->assertEquals( $equal, $a->equals( $b ) );
|
|
}
|
|
|
|
}
|