MediaWiki  1.29.1
CssContentTest.php
Go to the documentation of this file.
1 <?php
2 
11 
12  protected function setUp() {
13  parent::setUp();
14 
15  // Anon user
16  $user = new User();
17  $user->setName( '127.0.0.1' );
18 
19  $this->setMwGlobals( [
20  'wgUser' => $user,
21  'wgTextModelsToParse' => [
23  ]
24  ] );
25  }
26 
27  public function newContent( $text ) {
28  return new CssContent( $text );
29  }
30 
31  public static function dataGetParserOutput() {
32  return [
33  [
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>"
38  ],
39  [
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  [
45  'Links' => [
46  [ 'World' => 0 ]
47  ]
48  ]
49  ],
50 
51  // TODO: more...?
52  ];
53  }
54 
58  public function testGetModel() {
59  $content = $this->newContent( 'hello world.' );
60 
61  $this->assertEquals( CONTENT_MODEL_CSS, $content->getModel() );
62  }
63 
67  public function testGetContentHandler() {
68  $content = $this->newContent( 'hello world.' );
69 
70  $this->assertEquals( CONTENT_MODEL_CSS, $content->getContentHandler()->getModelID() );
71  }
72 
76  public static function provideUpdateRedirect() {
77  return [
78  [
79  '#REDIRECT [[Someplace]]',
80  '#REDIRECT [[Someplace]]',
81  ],
82  ];
83  }
84 
88  public function testGetRedirectTarget( $title, $text ) {
89  $this->setMwGlobals( [
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 );
97  }
98 
102  public static function provideGetRedirectTarget() {
103  // @codingStandardsIgnoreStart Generic.Files.LineLength
104  return [
105  [ 'MediaWiki:MonoBook.css', "/* #REDIRECT */@import url(//example.org/w/index.php?title=MediaWiki:MonoBook.css&action=raw&ctype=text/css);" ],
106  [ 'User:FooBar/common.css', "/* #REDIRECT */@import url(//example.org/w/index.php?title=User:FooBar/common.css&action=raw&ctype=text/css);" ],
107  [ '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  [ null, "@import url(//example.org/w/index.php?title=Gadget:FooBaz.css&action=raw&ctype=text/css);" ],
110  # Wrong domain
111  [ null, "/* #REDIRECT */@import url(//example.com/w/index.php?title=Gadget:FooBaz.css&action=raw&ctype=text/css);" ],
112  ];
113  // @codingStandardsIgnoreEnd
114  }
115 
116  public static function dataEquals() {
117  return [
118  [ new CssContent( 'hallo' ), null, false ],
119  [ new CssContent( 'hallo' ), new CssContent( 'hallo' ), true ],
120  [ new CssContent( 'hallo' ), new WikitextContent( 'hallo' ), false ],
121  [ new CssContent( 'hallo' ), new CssContent( 'HALLO' ), false ],
122  ];
123  }
124 
129  public function testEquals( Content $a, Content $b = null, $equal = false ) {
130  $this->assertEquals( $equal, $a->equals( $b ) );
131  }
132 }
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:189
CssContentTest\testGetContentHandler
testGetContentHandler()
CssContent::getContentHandler.
Definition: CssContentTest.php:67
CONTENT_MODEL_CSS
const CONTENT_MODEL_CSS
Definition: Defines.php:235
CssContentTest\testEquals
testEquals(Content $a, Content $b=null, $equal=false)
dataEquals CssContent::equals
Definition: CssContentTest.php:129
CssContentTest\dataGetParserOutput
static dataGetParserOutput()
Definition: CssContentTest.php:31
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:246
CssContent
Content object for CSS pages.
Definition: CssContent.php:33
User
User
Definition: All_system_messages.txt:425
CssContentTest\newContent
newContent( $text)
Definition: CssContentTest.php:27
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:934
$content
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content $content
Definition: hooks.txt:1049
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Definition: MediaWikiTestCase.php:658
WikitextContent
Content object for wiki text pages.
Definition: WikitextContent.php:33
Content\equals
equals(Content $that=null)
Returns true if this Content objects is conceptually equivalent to the given Content object.
CssContentTest\testGetRedirectTarget
testGetRedirectTarget( $title, $text)
provideGetRedirectTarget
Definition: CssContentTest.php:88
CssContentTest
ContentHandler Database ^— needed, because we do need the database to test link updates.
Definition: CssContentTest.php:10
CssContentTest\testGetModel
testGetModel()
CssContent::getModel.
Definition: CssContentTest.php:58
JavaScriptContentTest
ContentHandler Database ^— needed, because we do need the database to test link updates.
Definition: JavaScriptContentTest.php:8
Content
Base interface for content objects.
Definition: Content.php:34
CssContentTest\provideUpdateRedirect
static provideUpdateRedirect()
Redirects aren't supported.
Definition: CssContentTest.php:76
CssContentTest\provideGetRedirectTarget
static provideGetRedirectTarget()
Keep this in sync with CssContentHandlerTest::provideMakeRedirectContent()
Definition: CssContentTest.php:102
true
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition: hooks.txt:1956
CssContentTest\dataEquals
static dataEquals()
Definition: CssContentTest.php:116
CssContentTest\setUp
setUp()
Definition: CssContentTest.php:12