MediaWiki  1.23.14
LogFormatterTest.php
Go to the documentation of this file.
1 <?php
6 
10  protected $user;
11 
15  protected $title;
16 
20  protected $context;
21 
22  protected function setUp() {
23  parent::setUp();
24 
26 
27  $this->setMwGlobals( array(
28  'wgLogTypes' => array( 'phpunit' ),
29  'wgLogActionsHandlers' => array( 'phpunit/test' => 'LogFormatter',
30  'phpunit/param' => 'LogFormatter' ),
31  'wgUser' => User::newFromName( 'Testuser' ),
32  'wgExtensionMessagesFiles' => array( 'LogTests' => __DIR__ . '/LogTests.i18n.php' ),
33  ) );
34 
35  Language::getLocalisationCache()->recache( $wgLang->getCode() );
36 
37  $this->user = User::newFromName( 'Testuser' );
38  $this->title = Title::newMainPage();
39 
40  $this->context = new RequestContext();
41  $this->context->setUser( $this->user );
42  $this->context->setTitle( $this->title );
43  $this->context->setLanguage( $wgLang );
44  }
45 
46  protected function tearDown() {
47  parent::tearDown();
48 
50  Language::getLocalisationCache()->recache( $wgLang->getCode() );
51  }
52 
53  public function newLogEntry( $action, $params ) {
54  $logEntry = new ManualLogEntry( 'phpunit', $action );
55  $logEntry->setPerformer( $this->user );
56  $logEntry->setTarget( $this->title );
57  $logEntry->setComment( 'A very good reason' );
58 
59  $logEntry->setParameters( $params );
60 
61  return $logEntry;
62  }
63 
67  public function testNormalLogParams() {
68  $entry = $this->newLogEntry( 'test', array() );
69  $formatter = LogFormatter::newFromEntry( $entry );
70  $formatter->setContext( $this->context );
71 
72  $formatter->setShowUserToolLinks( false );
73  $paramsWithoutTools = $formatter->getMessageParametersForTesting();
74  unset( $formatter->parsedParameters );
75 
76  $formatter->setShowUserToolLinks( true );
77  $paramsWithTools = $formatter->getMessageParametersForTesting();
78 
79  $userLink = Linker::userLink(
80  $this->user->getId(),
81  $this->user->getName()
82  );
83 
85  $this->user->getId(),
86  $this->user->getName(),
87  $this->user->getEditCount()
88  );
89 
90  $titleLink = Linker::link( $this->title, null, array(), array() );
91 
92  // $paramsWithoutTools and $paramsWithTools should be only different
93  // in index 0
94  $this->assertEquals( $paramsWithoutTools[1], $paramsWithTools[1] );
95  $this->assertEquals( $paramsWithoutTools[2], $paramsWithTools[2] );
96 
97  $this->assertEquals( $userLink, $paramsWithoutTools[0]['raw'] );
98  $this->assertEquals( $userLink . $userTools, $paramsWithTools[0]['raw'] );
99 
100  $this->assertEquals( $this->user->getName(), $paramsWithoutTools[1] );
101 
102  $this->assertEquals( $titleLink, $paramsWithoutTools[2]['raw'] );
103  }
104 
109  public function testLogParamsTypeRaw() {
110  $params = array( '4:raw:raw' => Linker::link( $this->title, null, array(), array() ) );
111  $expected = Linker::link( $this->title, null, array(), array() );
112 
113  $entry = $this->newLogEntry( 'param', $params );
114  $formatter = LogFormatter::newFromEntry( $entry );
115  $formatter->setContext( $this->context );
116 
117  $logParam = $formatter->getActionText();
118 
119  $this->assertEquals( $expected, $logParam );
120  }
121 
126  public function testLogParamsTypeMsg() {
127  $params = array( '4:msg:msg' => 'log-description-phpunit' );
128  $expected = wfMessage( 'log-description-phpunit' )->text();
129 
130  $entry = $this->newLogEntry( 'param', $params );
131  $formatter = LogFormatter::newFromEntry( $entry );
132  $formatter->setContext( $this->context );
133 
134  $logParam = $formatter->getActionText();
135 
136  $this->assertEquals( $expected, $logParam );
137  }
138 
143  public function testLogParamsTypeMsgContent() {
144  $params = array( '4:msg-content:msgContent' => 'log-description-phpunit' );
145  $expected = wfMessage( 'log-description-phpunit' )->inContentLanguage()->text();
146 
147  $entry = $this->newLogEntry( 'param', $params );
148  $formatter = LogFormatter::newFromEntry( $entry );
149  $formatter->setContext( $this->context );
150 
151  $logParam = $formatter->getActionText();
152 
153  $this->assertEquals( $expected, $logParam );
154  }
155 
160  public function testLogParamsTypeNumber() {
161  global $wgLang;
162 
163  $params = array( '4:number:number' => 123456789 );
164  $expected = $wgLang->formatNum( 123456789 );
165 
166  $entry = $this->newLogEntry( 'param', $params );
167  $formatter = LogFormatter::newFromEntry( $entry );
168  $formatter->setContext( $this->context );
169 
170  $logParam = $formatter->getActionText();
171 
172  $this->assertEquals( $expected, $logParam );
173  }
174 
179  public function testLogParamsTypeUserLink() {
180  $params = array( '4:user-link:userLink' => $this->user->getName() );
181  $expected = Linker::userLink(
182  $this->user->getId(),
183  $this->user->getName()
184  );
185 
186  $entry = $this->newLogEntry( 'param', $params );
187  $formatter = LogFormatter::newFromEntry( $entry );
188  $formatter->setContext( $this->context );
189 
190  $logParam = $formatter->getActionText();
191 
192  $this->assertEquals( $expected, $logParam );
193  }
194 
199  public function testLogParamsTypeTitleLink() {
200  $params = array( '4:title-link:titleLink' => $this->title->getText() );
201  $expected = Linker::link( $this->title, null, array(), array() );
202 
203  $entry = $this->newLogEntry( 'param', $params );
204  $formatter = LogFormatter::newFromEntry( $entry );
205  $formatter->setContext( $this->context );
206 
207  $logParam = $formatter->getActionText();
208 
209  $this->assertEquals( $expected, $logParam );
210  }
211 
216  public function testLogParamsTypePlain() {
217  $params = array( '4:plain:plain' => 'Some plain text' );
218  $expected = 'Some plain text';
219 
220  $entry = $this->newLogEntry( 'param', $params );
221  $formatter = LogFormatter::newFromEntry( $entry );
222  $formatter->setContext( $this->context );
223 
224  $logParam = $formatter->getActionText();
225 
226  $this->assertEquals( $expected, $logParam );
227  }
228 
233  public function testLogComment() {
234  $entry = $this->newLogEntry( 'test', array() );
235  $formatter = LogFormatter::newFromEntry( $entry );
236  $formatter->setContext( $this->context );
237 
238  $comment = ltrim( Linker::commentBlock( $entry->getComment() ) );
239 
240  $this->assertEquals( $comment, $formatter->getComment() );
241  }
242 }
LogFormatterTest
@group Database
Definition: LogFormatterTest.php:5
Linker\commentBlock
static commentBlock( $comment, $title=null, $local=false)
Wrap a comment in standard punctuation and formatting if it's non-empty, otherwise return empty strin...
Definition: Linker.php:1565
Linker\userToolLinksRedContribs
static userToolLinksRedContribs( $userId, $userText, $edits=null)
Alias for userToolLinks( $userId, $userText, true );.
Definition: Linker.php:1164
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
LogFormatterTest\testLogParamsTypeNumber
testLogParamsTypeNumber()
@covers LogFormatter::newFromEntry @covers LogFormatter::getActionText
Definition: LogFormatterTest.php:157
LogFormatterTest\setUp
setUp()
Definition: LogFormatterTest.php:19
Linker\userLink
static userLink( $userId, $userName, $altUserName=false)
Make user link (or user contributions for unregistered users)
Definition: Linker.php:1081
LogFormatterTest\testLogParamsTypeUserLink
testLogParamsTypeUserLink()
@covers LogFormatter::newFromEntry @covers LogFormatter::getActionText
Definition: LogFormatterTest.php:176
LogFormatterTest\testLogComment
testLogComment()
@covers LogFormatter::newFromEntry @covers LogFormatter::getComment
Definition: LogFormatterTest.php:230
LogFormatterTest\newLogEntry
newLogEntry( $action, $params)
Definition: LogFormatterTest.php:50
Title\newMainPage
static newMainPage()
Create a new Title for the Main Page.
Definition: Title.php:441
LogFormatterTest\testLogParamsTypeTitleLink
testLogParamsTypeTitleLink()
@covers LogFormatter::newFromEntry @covers LogFormatter::getActionText
Definition: LogFormatterTest.php:196
LogFormatterTest\$title
Title $title
Definition: LogFormatterTest.php:13
$params
$params
Definition: styleTest.css.php:40
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:389
LogFormatterTest\testLogParamsTypeMsgContent
testLogParamsTypeMsgContent()
@covers LogFormatter::newFromEntry @covers LogFormatter::getActionText
Definition: LogFormatterTest.php:140
LogFormatterTest\testLogParamsTypeMsg
testLogParamsTypeMsg()
@covers LogFormatter::newFromEntry @covers LogFormatter::getActionText
Definition: LogFormatterTest.php:123
Linker\link
static link( $target, $html=null, $customAttribs=array(), $query=array(), $options=array())
This function returns an HTML link to the given target.
Definition: Linker.php:192
title
to move a page</td >< td > &*You are moving the page across *A non empty talk page already exists under the new or *You uncheck the box below In those you will have to move or merge the page manually if desired</td >< td > be sure to &You are responsible for making sure that links continue to point where they are supposed to go Note that the page will &a page at the new title
Definition: All_system_messages.txt:2703
LogFormatterTest\$context
RequestContext $context
Definition: LogFormatterTest.php:17
Language\getLocalisationCache
static getLocalisationCache()
Get the LocalisationCache instance.
Definition: Language.php:443
LogFormatterTest\$user
User $user
Definition: LogFormatterTest.php:9
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Definition: MediaWikiTestCase.php:302
wfMessage
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 an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing after in associative array form externallinks including delete and has completed for all link tables default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "&lt
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
$comment
$comment
Definition: importImages.php:107
RequestContext
Group all the pieces relevant to the context of a request into one instance.
Definition: RequestContext.php:30
LogFormatterTest\testLogParamsTypeRaw
testLogParamsTypeRaw()
@covers LogFormatter::newFromEntry @covers LogFormatter::getActionText
Definition: LogFormatterTest.php:106
user
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such and we might be restricted by PHP settings such as safe mode or open_basedir We cannot assume that the software even has read access anywhere useful Many shared hosts run all users web applications under the same user
Definition: distributors.txt:9
MediaWikiLangTestCase
Base class that store and restore the Language objects.
Definition: MediaWikiLangTestCase.php:6
LogFormatterTest\testNormalLogParams
testNormalLogParams()
@covers LogFormatter::newFromEntry
Definition: LogFormatterTest.php:64
Title
Represents a title within MediaWiki.
Definition: Title.php:35
$wgLang
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as $wgLang
Definition: design.txt:56
ManualLogEntry
Class for creating log entries manually, for example to inject them into the database.
Definition: LogEntry.php:339
LogFormatterTest\testLogParamsTypePlain
testLogParamsTypePlain()
@covers LogFormatter::newFromEntry @covers LogFormatter::getActionText
Definition: LogFormatterTest.php:213
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:59
LogFormatterTest\tearDown
tearDown()
Definition: LogFormatterTest.php:43
LogFormatter\newFromEntry
static newFromEntry(LogEntry $entry)
Constructs a new formatter suitable for given entry.
Definition: LogFormatter.php:45