2011-06-29 22:09:51 +00:00
|
|
|
<?php
|
|
|
|
|
|
2020-11-15 15:57:24 +00:00
|
|
|
/**
|
|
|
|
|
* @group Database
|
|
|
|
|
*/
|
2020-06-30 15:09:24 +00:00
|
|
|
class ArticleTest extends \MediaWikiIntegrationTestCase {
|
2011-06-29 22:09:51 +00:00
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
/**
|
|
|
|
|
* @var Title
|
|
|
|
|
*/
|
|
|
|
|
private $title;
|
|
|
|
|
/**
|
|
|
|
|
* @var Article
|
|
|
|
|
*/
|
|
|
|
|
private $article;
|
2011-07-03 17:51:11 +00:00
|
|
|
|
|
|
|
|
/** creates a title object and its article object */
|
2021-07-22 03:11:47 +00:00
|
|
|
protected function setUp(): void {
|
2012-10-23 17:02:36 +00:00
|
|
|
parent::setUp();
|
2012-10-08 10:56:20 +00:00
|
|
|
$this->title = Title::makeTitle( NS_MAIN, 'SomePage' );
|
2011-07-03 17:51:11 +00:00
|
|
|
$this->article = new Article( $this->title );
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-24 10:54:02 +00:00
|
|
|
/**
|
|
|
|
|
* @covers Article::__get
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testImplementsGetMagic() {
|
Introduce wfDeprecatedMsg()
Deprecating something means to say something nasty about it, or to draw
its character into question. For example, "this function is lazy and good
for nothing". Deprecatory remarks by a developer are generally taken as a
warning that violence will soon be done against the function in question.
Other developers are thus warned to avoid associating with the deprecated
function.
However, since wfDeprecated() was introduced, it has become obvious that
the targets of deprecation are not limited to functions. Developers can
deprecate literally anything: a parameter, a return value, a file
format, Mondays, the concept of being, etc. wfDeprecated() requires
every deprecatory statement to begin with "use of", leading to some
awkward sentences. For example, one might say: "Use of your mouth to
cough without it being covered by your arm is deprecated since 2020."
So, introduce wfDeprecatedMsg(), which allows deprecation messages to be
specified in plain text, with the caller description being optionally
appended. Migrate incorrect or gramatically awkward uses of wfDeprecated()
to wfDeprecatedMsg().
Change-Id: Ib3dd2fe37677d98425d0f3692db5c9e988943ae8
2020-06-12 04:18:35 +00:00
|
|
|
$this->filterDeprecated( '/Accessing Article::\$mLatest/' );
|
2019-09-17 14:19:26 +00:00
|
|
|
$this->assertFalse( $this->article->mLatest, "Article __get magic" );
|
2011-07-03 17:51:11 +00:00
|
|
|
}
|
2011-06-29 22:09:51 +00:00
|
|
|
|
2011-07-03 17:51:11 +00:00
|
|
|
/**
|
|
|
|
|
* @depends testImplementsGetMagic
|
2013-10-24 10:54:02 +00:00
|
|
|
* @covers Article::__set
|
2011-07-03 17:51:11 +00:00
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testImplementsSetMagic() {
|
Introduce wfDeprecatedMsg()
Deprecating something means to say something nasty about it, or to draw
its character into question. For example, "this function is lazy and good
for nothing". Deprecatory remarks by a developer are generally taken as a
warning that violence will soon be done against the function in question.
Other developers are thus warned to avoid associating with the deprecated
function.
However, since wfDeprecated() was introduced, it has become obvious that
the targets of deprecation are not limited to functions. Developers can
deprecate literally anything: a parameter, a return value, a file
format, Mondays, the concept of being, etc. wfDeprecated() requires
every deprecatory statement to begin with "use of", leading to some
awkward sentences. For example, one might say: "Use of your mouth to
cough without it being covered by your arm is deprecated since 2020."
So, introduce wfDeprecatedMsg(), which allows deprecation messages to be
specified in plain text, with the caller description being optionally
appended. Migrate incorrect or gramatically awkward uses of wfDeprecated()
to wfDeprecatedMsg().
Change-Id: Ib3dd2fe37677d98425d0f3692db5c9e988943ae8
2020-06-12 04:18:35 +00:00
|
|
|
$this->filterDeprecated( '/Accessing Article::\$mLatest/' );
|
|
|
|
|
$this->filterDeprecated( '/Setting Article::\$mLatest/' );
|
2011-12-11 13:29:21 +00:00
|
|
|
$this->article->mLatest = 2;
|
|
|
|
|
$this->assertEquals( 2, $this->article->mLatest, "Article __set magic" );
|
2011-07-03 17:51:11 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-24 10:54:02 +00:00
|
|
|
/**
|
|
|
|
|
* @covers Article::__get
|
|
|
|
|
* @covers Article::__set
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testGetOrSetOnNewProperty() {
|
Introduce wfDeprecatedMsg()
Deprecating something means to say something nasty about it, or to draw
its character into question. For example, "this function is lazy and good
for nothing". Deprecatory remarks by a developer are generally taken as a
warning that violence will soon be done against the function in question.
Other developers are thus warned to avoid associating with the deprecated
function.
However, since wfDeprecated() was introduced, it has become obvious that
the targets of deprecation are not limited to functions. Developers can
deprecate literally anything: a parameter, a return value, a file
format, Mondays, the concept of being, etc. wfDeprecated() requires
every deprecatory statement to begin with "use of", leading to some
awkward sentences. For example, one might say: "Use of your mouth to
cough without it being covered by your arm is deprecated since 2020."
So, introduce wfDeprecatedMsg(), which allows deprecation messages to be
specified in plain text, with the caller description being optionally
appended. Migrate incorrect or gramatically awkward uses of wfDeprecated()
to wfDeprecatedMsg().
Change-Id: Ib3dd2fe37677d98425d0f3692db5c9e988943ae8
2020-06-12 04:18:35 +00:00
|
|
|
$this->filterDeprecated(
|
|
|
|
|
'/Accessing Article::\$ext_someNewProperty/'
|
2020-03-19 03:23:43 +00:00
|
|
|
);
|
Introduce wfDeprecatedMsg()
Deprecating something means to say something nasty about it, or to draw
its character into question. For example, "this function is lazy and good
for nothing". Deprecatory remarks by a developer are generally taken as a
warning that violence will soon be done against the function in question.
Other developers are thus warned to avoid associating with the deprecated
function.
However, since wfDeprecated() was introduced, it has become obvious that
the targets of deprecation are not limited to functions. Developers can
deprecate literally anything: a parameter, a return value, a file
format, Mondays, the concept of being, etc. wfDeprecated() requires
every deprecatory statement to begin with "use of", leading to some
awkward sentences. For example, one might say: "Use of your mouth to
cough without it being covered by your arm is deprecated since 2020."
So, introduce wfDeprecatedMsg(), which allows deprecation messages to be
specified in plain text, with the caller description being optionally
appended. Migrate incorrect or gramatically awkward uses of wfDeprecated()
to wfDeprecatedMsg().
Change-Id: Ib3dd2fe37677d98425d0f3692db5c9e988943ae8
2020-06-12 04:18:35 +00:00
|
|
|
$this->filterDeprecated(
|
|
|
|
|
'/Setting Article::\$ext_someNewProperty/'
|
2020-03-19 03:23:43 +00:00
|
|
|
);
|
2011-07-03 17:51:11 +00:00
|
|
|
$this->article->ext_someNewProperty = 12;
|
|
|
|
|
$this->assertEquals( 12, $this->article->ext_someNewProperty,
|
|
|
|
|
"Article get/set magic on new field" );
|
2020-03-19 03:23:43 +00:00
|
|
|
$this->assertEquals( 12, $this->article->getPage()->ext_someNewProperty,
|
|
|
|
|
"Article get/set magic on new field" );
|
2011-07-03 17:51:11 +00:00
|
|
|
$this->article->ext_someNewProperty = -8;
|
|
|
|
|
$this->assertEquals( -8, $this->article->ext_someNewProperty,
|
|
|
|
|
"Article get/set magic on update to new field" );
|
2020-03-19 03:23:43 +00:00
|
|
|
$this->assertEquals( -8, $this->article->getPage()->ext_someNewProperty,
|
|
|
|
|
"Article get/set magic on new field" );
|
2011-07-03 17:51:11 +00:00
|
|
|
}
|
2020-09-07 09:30:43 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers Article::__sleep
|
|
|
|
|
*/
|
|
|
|
|
public function testSerialization_fails() {
|
|
|
|
|
$this->expectException( LogicException::class );
|
|
|
|
|
serialize( $this->article );
|
|
|
|
|
}
|
2020-11-15 15:57:24 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tests that missing article page shows parser contents
|
|
|
|
|
* of the well-known system message for NS_MEDIAWIKI pages
|
|
|
|
|
* @covers Article::showMissingArticle
|
|
|
|
|
*/
|
|
|
|
|
public function testMissingArticleMessage() {
|
|
|
|
|
// Use a well-known system message
|
2021-01-19 19:57:24 +00:00
|
|
|
$title = Title::makeTitle( NS_MEDIAWIKI, 'Uploadedimage' );
|
2020-11-15 15:57:24 +00:00
|
|
|
$article = new Article( $title, 0 );
|
|
|
|
|
$article->getContext()->getOutput()->setTitle( $title );
|
|
|
|
|
$article->showMissingArticle();
|
|
|
|
|
$output = $article->getContext()->getOutput();
|
|
|
|
|
$this->assertStringContainsString(
|
|
|
|
|
Message::newFromKey( 'uploadedimage' )->parse(),
|
|
|
|
|
$output->getHTML()
|
|
|
|
|
);
|
|
|
|
|
}
|
2021-05-25 15:39:48 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test if patrol footer is possible to show
|
|
|
|
|
* @covers Article::showPatrolFooter
|
|
|
|
|
* @dataProvider provideShowPatrolFooter
|
|
|
|
|
*/
|
|
|
|
|
public function testShowPatrolFooter( $group, $title, $editPageText, $isEditedBySameUser, $expectedResult ) {
|
|
|
|
|
$context = new RequestContext();
|
|
|
|
|
$article = new Article( $title );
|
|
|
|
|
$user1 = $this->getTestUser( $group )->getUser();
|
|
|
|
|
$user2 = $this->getTestUser()->getUser();
|
|
|
|
|
$context->setUser( $user1 );
|
|
|
|
|
$article->setContext( $context );
|
|
|
|
|
if ( $editPageText !== null ) {
|
|
|
|
|
$editedUser = $isEditedBySameUser ? $user1 : $user2;
|
|
|
|
|
$editIsGood = $this->editPage( $article->getPage(), $editPageText, '', NS_MAIN, $editedUser )->isGood();
|
|
|
|
|
$this->assertTrue( $editIsGood, 'Sanity: edited a page' );
|
|
|
|
|
}
|
|
|
|
|
$this->assertSame( $expectedResult, $article->showPatrolFooter() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function provideShowPatrolFooter() {
|
|
|
|
|
yield 'UserAllowedRevExist' => [
|
|
|
|
|
'sysop',
|
|
|
|
|
Title::makeTitle( NS_MAIN, 'Page1' ),
|
|
|
|
|
'EditPage1',
|
|
|
|
|
false,
|
|
|
|
|
true
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
yield 'UserNotAllowedRevExist' => [
|
|
|
|
|
null,
|
|
|
|
|
Title::makeTitle( NS_MAIN, 'Page2' ),
|
|
|
|
|
'EditPage2',
|
|
|
|
|
false,
|
|
|
|
|
false
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
yield 'UserAllowedNoRev' => [
|
|
|
|
|
'sysop',
|
|
|
|
|
Title::makeTitle( NS_MAIN, 'Page3' ),
|
|
|
|
|
null,
|
|
|
|
|
false,
|
|
|
|
|
false
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
yield 'UserAllowedRevExistBySameUser' => [
|
|
|
|
|
'sysop',
|
|
|
|
|
Title::makeTitle( NS_MAIN, 'Page4' ),
|
|
|
|
|
'EditPage4',
|
|
|
|
|
true,
|
|
|
|
|
false
|
|
|
|
|
];
|
|
|
|
|
}
|
2011-06-29 22:09:51 +00:00
|
|
|
}
|