'content' => new JavaScriptContent( 'hellow world.' )
],
];
+ // FIXME: test with and without user ID, and with a user object.
+ // We can't prepare that here though, since we don't yet have a dummy DB
+ }
+
+ /**
+ * @param string $model
+ * @return Title
+ */
+ public function getMockTitle( $model = CONTENT_MODEL_WIKITEXT ) {
+ $mock = $this->getMockBuilder( Title::class )
+ ->disableOriginalConstructor()
+ ->getMock();
+ $mock->expects( $this->any() )
+ ->method( 'getNamespace' )
+ ->will( $this->returnValue( $this->getDefaultWikitextNS() ) );
+ $mock->expects( $this->any() )
+ ->method( 'getPrefixedText' )
+ ->will( $this->returnValue( 'RevisionTest' ) );
+ $mock->expects( $this->any() )
+ ->method( 'getDBKey' )
+ ->will( $this->returnValue( 'RevisionTest' ) );
+ $mock->expects( $this->any() )
+ ->method( 'getArticleID' )
+ ->will( $this->returnValue( 23 ) );
+ $mock->expects( $this->any() )
+ ->method( 'getModel' )
+ ->will( $this->returnValue( $model ) );
+
+ return $mock;
}
/**
$this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $rev->getContentModel() );
}
+ /**
+ * @covers Revision::__construct
+ * @covers Revision::constructFromRowArray
+ */
+ public function testConstructFromEmptyArray() {
+ $rev = new Revision( [], 0, $this->getMockTitle() );
+ $this->assertNull( $rev->getContent(), 'no content object should be available' );
+ }
+
+ 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' => [
[
new Revision( $rowArray );
}
+ /**
+ * @covers Revision::__construct
+ * @covers Revision::constructFromRowArray
+ */
+ public function testConstructFromNothing() {
+ $rev = new Revision( [] );
+ $this->assertNull( $rev->getId(), 'getId()' );
+ }
+
public function provideConstructFromRow() {
yield 'Full construction' => [
[
/**
* @dataProvider provideConstructFromRow
* @covers Revision::__construct
- * @covers Revision::constructFromDbRowObject
+ * @covers Revision::constructFromRowArray
*/
public function testConstructFromRow( array $arrayData, $assertions ) {
$row = (object)$arrayData;
];
yield '(ISO-8859-1 encoding), string in string out' => [
'ISO-8859-1',
- iconv( 'utf8', 'ISO-8859-1', "1®Àþ1" ),
+ iconv( 'utf-8', 'ISO-8859-1', "1®Àþ1" ),
[],
'1®Àþ1',
];
yield '(ISO-8859-1 encoding), serialized object in with gzip flags returns string' => [
'ISO-8859-1',
- gzdeflate( iconv( 'utf8', 'ISO-8859-1', "4®Àþ4" ) ),
+ gzdeflate( iconv( 'utf-8', 'ISO-8859-1', "4®Àþ4" ) ),
[ 'gzip' ],
'4®Àþ4',
];
yield '(ISO-8859-1 encoding), serialized object in with object flags returns string' => [
'ISO-8859-1',
- serialize( new TitleValue( 0, iconv( 'utf8', 'ISO-8859-1', "3®Àþ3" ) ) ),
+ serialize( new TitleValue( 0, iconv( 'utf-8', 'ISO-8859-1', "3®Àþ3" ) ) ),
[ 'object' ],
'3®Àþ3',
];
yield '(ISO-8859-1 encoding), serialized object in with object & gzip flags returns string' => [
'ISO-8859-1',
- gzdeflate( serialize( new TitleValue( 0, iconv( 'utf8', 'ISO-8859-1', "2®Àþ2" ) ) ) ),
+ gzdeflate( serialize( new TitleValue( 0, iconv( 'utf-8', 'ISO-8859-1', "2®Àþ2" ) ) ) ),
[ 'gzip', 'object' ],
'2®Àþ2',
];