X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FRevisionTest.php;h=73d69a528cd9699c6a3cc489f63350425591afec;hb=37ae7b98be7f57b83ec58b7d8fa6ff17a7907992;hp=0db76ff1932a1a2146d4241d223d4323b1eae024;hpb=a4997d99ed86a7f5d95cc794fa29e9d3cd0cc843;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/RevisionTest.php b/tests/phpunit/includes/RevisionTest.php index 0db76ff193..73d69a528c 100644 --- a/tests/phpunit/includes/RevisionTest.php +++ b/tests/phpunit/includes/RevisionTest.php @@ -1,7 +1,11 @@ assertNull( $rev->getContent(), 'no content object should be available' ); } + /** + * @covers Revision::__construct + * @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray + */ + public function testConstructFromArrayWithBadPageId() { + MediaWiki\suppressWarnings(); + $rev = new Revision( [ 'page' => 77777777 ] ); + $this->assertSame( 77777777, $rev->getPage() ); + MediaWiki\restoreWarnings(); + } + public function provideConstructFromArray_userSetAsExpected() { yield 'no user defaults to wgUser' => [ [ @@ -297,6 +312,17 @@ class RevisionTest extends MediaWikiTestCase { $assertions( $this, $rev ); } + /** + * @covers Revision::__construct + * @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray + */ + public function testConstructFromRowWithBadPageId() { + MediaWiki\suppressWarnings(); + $rev = new Revision( (object)[ 'rev_page' => 77777777 ] ); + $this->assertSame( 77777777, $rev->getPage() ); + MediaWiki\restoreWarnings(); + } + public function provideGetRevisionText() { yield 'Generic test' => [ 'This is a goat of revision text.', @@ -1567,4 +1593,102 @@ class RevisionTest extends MediaWikiTestCase { ); } + /** + * @covers Revision::getSize + */ + public function testGetSize() { + $title = $this->getMockTitle(); + + $rec = new MutableRevisionRecord( $title ); + $rev = new Revision( $rec, 0, $title ); + + $this->assertSame( 0, $rev->getSize(), 'Size of no slots is 0' ); + + $rec->setSize( 13 ); + $this->assertSame( 13, $rev->getSize() ); + } + + /** + * @covers Revision::getSize + */ + public function testGetSize_failure() { + $title = $this->getMockTitle(); + + $rec = $this->getMockBuilder( RevisionRecord::class ) + ->disableOriginalConstructor() + ->getMock(); + + $rec->method( 'getSize' ) + ->willThrowException( new RevisionAccessException( 'Oops!' ) ); + + $rev = new Revision( $rec, 0, $title ); + $this->assertNull( $rev->getSize() ); + } + + /** + * @covers Revision::getSha1 + */ + public function testGetSha1() { + $title = $this->getMockTitle(); + + $rec = new MutableRevisionRecord( $title ); + $rev = new Revision( $rec, 0, $title ); + + $emptyHash = SlotRecord::base36Sha1( '' ); + $this->assertSame( $emptyHash, $rev->getSha1(), 'Sha1 of no slots is hash of empty string' ); + + $rec->setSha1( 'deadbeef' ); + $this->assertSame( 'deadbeef', $rev->getSha1() ); + } + + /** + * @covers Revision::getSha1 + */ + public function testGetSha1_failure() { + $title = $this->getMockTitle(); + + $rec = $this->getMockBuilder( RevisionRecord::class ) + ->disableOriginalConstructor() + ->getMock(); + + $rec->method( 'getSha1' ) + ->willThrowException( new RevisionAccessException( 'Oops!' ) ); + + $rev = new Revision( $rec, 0, $title ); + $this->assertNull( $rev->getSha1() ); + } + + /** + * @covers Revision::getContent + */ + public function testGetContent() { + $title = $this->getMockTitle(); + + $rec = new MutableRevisionRecord( $title ); + $rev = new Revision( $rec, 0, $title ); + + $this->assertNull( $rev->getContent(), 'Content of no slots is null' ); + + $content = new TextContent( 'Hello Kittens!' ); + $rec->setContent( 'main', $content ); + $this->assertSame( $content, $rev->getContent() ); + } + + /** + * @covers Revision::getContent + */ + public function testGetContent_failure() { + $title = $this->getMockTitle(); + + $rec = $this->getMockBuilder( RevisionRecord::class ) + ->disableOriginalConstructor() + ->getMock(); + + $rec->method( 'getContent' ) + ->willThrowException( new RevisionAccessException( 'Oops!' ) ); + + $rev = new Revision( $rec, 0, $title ); + $this->assertNull( $rev->getContent() ); + } + }