1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
<?php
namespace MediaWiki\Tests\Revision;
use MediaWiki\Revision\ContributionsSegment;
use MediaWiki\Revision\MutableRevisionRecord;
use MockTitleTrait;
class ContributionsSegmentTest extends \MediaWikiUnitTestCase {
use MockTitleTrait;
public static function provideFlags() {
yield [
[]
];
yield [
[
'newest' => false,
'oldest' => true
]
];
yield [
[
'newest' => true,
'oldest' => false,
]
];
yield [
[
'newest' => false,
'oldest' => false
]
];
yield [
[
'newest' => true,
'oldest' => true,
]
];
yield [
[
'oldest' => true,
]
];
yield [
[
'newest' => true,
]
];
yield [
[
'oldest' => false,
]
];
yield [
[
'newest' => false,
]
];
}
/**
* @dataProvider provideFlags
* @covers \MediaWiki\Revision\ContributionsSegment
*/
public function testFlags( $flags ) {
$contributionsSegment = new ContributionsSegment( [], [], null, null, [], $flags );
$this->assertSame( $flags['newest'] ?? false, $contributionsSegment->isNewest() );
$this->assertSame( $flags['oldest'] ?? false, $contributionsSegment->isOldest() );
}
/**
* @covers \MediaWiki\Revision\ContributionsSegment
*/
public function testConstruction() {
$mockTitle = $this->makeMockTitle( 'Foo', [ 'id' => 1 ] );
$revisionRecords = [ new MutableRevisionRecord( $mockTitle ), new MutableRevisionRecord( $mockTitle ) ];
$before = 'before';
$after = 'after';
$tags = [ 3 => [ 'frob' ] ];
$deltas = [ 3 => -7, 5 => null ];
$contributionsSegment =
new ContributionsSegment( $revisionRecords, $tags, $before, $after, $deltas );
$this->assertSame( $revisionRecords, $contributionsSegment->getRevisions() );
$this->assertSame( $tags[3], $contributionsSegment->getTagsForRevision( 3 ) );
$this->assertSame( [], $contributionsSegment->getTagsForRevision( 17 ) );
$this->assertSame( $before, $contributionsSegment->getBefore() );
$this->assertSame( $after, $contributionsSegment->getAfter() );
$this->assertFalse( $contributionsSegment->isNewest(), 'isNewest' );
$this->assertFalse( $contributionsSegment->isOldest(), 'isOldest' );
$this->assertSame( $deltas[3], $contributionsSegment->getDeltaForRevision( 3 ) );
$this->assertNull( $contributionsSegment->getDeltaForRevision( 5 ) );
$this->assertNull( $contributionsSegment->getDeltaForRevision( 77 ) );
}
}
|