Debian Codegraph @

tests/phpunit/unit/includes/Revision/ContributionsSegmentTest.php

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