Addshore has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/392484 )
Change subject: More user related Revision construction test cases
......................................................................
More user related Revision construction test cases
I4f24e7fbb683cb51f3fd8b250732bae9c7541ba2 releaved
a failing test "PageArchiveTest::testUndeleteRevisions"
that constructs a revision from an array only passing
in 'user_text' and no 'user' field.
After investigation this is quite an odd case that
probably shouldnt happen in production code.
The test cases in this patch test the current behaviour.
Bug: T180210
Change-Id: I7040a16ac6cb29b49f8e7bed1caee72cdd4c6a61
---
M tests/phpunit/includes/RevisionTest.php
1 file changed, 66 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/84/392484/1
diff --git a/tests/phpunit/includes/RevisionTest.php
b/tests/phpunit/includes/RevisionTest.php
index d933d93..3d0556e 100644
--- a/tests/phpunit/includes/RevisionTest.php
+++ b/tests/phpunit/includes/RevisionTest.php
@@ -34,6 +34,72 @@
$this->assertEquals( CONTENT_MODEL_JAVASCRIPT,
$rev->getContentModel() );
}
+ public function provideConstructFromArray_userSetAsExpected() {
+ yield 'no user defaults to wgUser' => [
+ [
+ 'content' => new JavaScriptContent( 'hello
world.' ),
+ ],
+ null,
+ null,
+ ];
+ yield 'user text and id' => [
+ [
+ 'content' => new JavaScriptContent( 'hello
world.' ),
+ 'user_text' => 'SomeTextUserName',
+ 'user' => 99,
+
+ ],
+ 99,
+ 'SomeTextUserName',
+ ];
+ // Note: the below XXX test cases are odd and probably result
in unexpected behaviour if used
+ // in production code.
+ yield 'XXX: user text only' => [
+ [
+ 'content' => new JavaScriptContent( 'hello
world.' ),
+ 'user_text' => '111.111.111.111',
+ ],
+ null,
+ '111.111.111.111',
+ ];
+ yield 'XXX: user id only' => [
+ [
+ 'content' => new JavaScriptContent( 'hello
world.' ),
+ 'user' => 9989,
+ ],
+ 9989,
+ null,
+ ];
+ }
+
+ /**
+ * @dataProvider provideConstructFromArray_userSetAsExpected
+ * @covers Revision::__construct
+ * @covers Revision::constructFromRowArray
+ *
+ * @param array $rowArray
+ * @param mixed $expectedUserId null to expect the current wgUser ID
+ * @param mixed $expectedUserName null to expect the current wgUser name
+ */
+ public function testConstructFromArray_userSetAsExpected(
+ array $rowArray,
+ $expectedUserId,
+ $expectedUserName
+ ) {
+ $testUser = $this->getTestUser()->getUser();
+ $this->setMwGlobals( 'wgUser', $testUser );
+ if ( $expectedUserId === null ) {
+ $expectedUserId = $testUser->getId();
+ }
+ if ( $expectedUserName === null ) {
+ $expectedUserName = $testUser->getName();
+ }
+
+ $rev = new Revision( $rowArray );
+ $this->assertEquals( $expectedUserId, $rev->getUser() );
+ $this->assertEquals( $expectedUserName, $rev->getUserText() );
+ }
+
public function provideConstructFromArrayThrowsExceptions() {
yield 'content and text_id both not empty' => [
[
--
To view, visit https://gerrit.wikimedia.org/r/392484
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I7040a16ac6cb29b49f8e7bed1caee72cdd4c6a61
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits