wiki.techinc.nl/tests/phpunit/unit/includes/Revision/ContributionsSegmentTest.php
Petr Pchelko 816e02ae51 Convert RevisionRecord to Authority and PageIdentity
As we convert the RevisionRecord to using Authority,
we no longer need Title instances, so we can convert
that to PageIdentity.

Ideally, we'd part away from using Title at all, but:
1. For foreign wikis PageIdentity has stronger validation,
so calling PageIdentity getId() on Title will break things.
There's still a lot of code depending on lax Title guarantees,
so we keep it.
2. A lot of code still depends on Title, so we try to pass it
through even if we don't nesessarily need to, to save cost
on recreating it later on.

Bug: T271458
Depends-On: I287400b967b467ea18bebbb579e881a785a19158
Change-Id: I63d9807264d7e2295afef51fc9d982447f92fcbd
2021-01-21 13:37:01 -06:00

96 lines
2.3 KiB
PHP

<?php
namespace MediaWiki\Tests\Revision;
use MediaWiki\Revision\ContributionsSegment;
use MediaWiki\Storage\MutableRevisionRecord;
use MockTitleTrait;
class ContributionsSegmentTest extends \MediaWikiUnitTestCase {
use MockTitleTrait;
public 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 ) );
}
}