Debian Codegraph @

tests/phpunit/unit/includes/edit/ParsoidRenderIdTest.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Tests\Unit\Edit;
4
5 use InvalidArgumentException;
6 use MediaWiki\Edit\ParsoidRenderID;
7 use MediaWikiUnitTestCase;
8
9 class ParsoidRenderIdTest extends MediaWikiUnitTestCase {
10
11 /**
12 * @covers \MediaWiki\Edit\ParsoidRenderID
13 */
14 public function testConstruction() {
15 $renderID = new ParsoidRenderID( 1, '123-abc' );
16 $this->assertSame( 1, $renderID->getRevisionID() );
17 $this->assertEquals( '123-abc', $renderID->getUniqueID() );
18 $this->assertEquals( '1/123-abc', $renderID->__toString() );
19 }
20
21 /**
22 * @covers \MediaWiki\Edit\ParsoidRenderID::newFromKey
23 */
24 public function testRoundTrip() {
25 $renderID = new ParsoidRenderID( 1, '123-abc' );
26 $stringRenderID = $renderID->__toString();
27 $backToRenderID = $renderID::newFromKey( $stringRenderID );
28 $this->assertSame( $stringRenderID, $backToRenderID->__toString() );
29 }
30
31 /**
32 * @dataProvider provideETags
33 *
34 * @param string $eTag
35 * @param \MediaWiki\Edit\ParsoidRenderID $renderId
36 *
37 * @covers \MediaWiki\Edit\ParsoidRenderID::newFromETag
38 */
39 public function testNewFromETag( $eTag, $renderId ) {
40 $actual = ParsoidRenderID::newFromETag( $eTag );
41 $this->assertSame( $renderId->getKey(), $actual->getKey() );
42 }
43
44 public static function provideETags() {
45 yield [ '"1/abc/stash"', new ParsoidRenderID( 1, 'abc' ) ];
46 yield [ '"1/abc"', new ParsoidRenderID( 1, 'abc' ) ];
47 yield [ '"1/abc/stash/stash"', new ParsoidRenderID( 1, 'abc' ) ];
48 yield [ 'W/"1/abc"', new ParsoidRenderID( 1, 'abc' ) ];
49 }
50
51 /**
52 * @dataProvider provideBadETags
53 *
54 * @param string $eTag
55 *
56 * @covers \MediaWiki\Edit\ParsoidRenderID::newFromETag
57 */
58 public function testNewFromBadETag( $eTag ) {
59 // make sure it doesn't explode
60 $this->assertNull( ParsoidRenderID::newFromETag( $eTag ) );
61 }
62
63 public static function provideBadETags() {
64 yield [ '' ];
65 yield [ '0' ];
66 yield [ '""' ];
67 yield [ '"/"' ];
68 yield [ '"x/y"' ];
69 yield [ '"1/foo"XXX' ];
70 yield [ 'XXX"1/foo"' ];
71 }
72
73 /**
74 * @dataProvider provideNewFromKey
75 * @covers \MediaWiki\Edit\ParsoidRenderID::newFromKey
76 */
77 public function testNewFromKey( string $key, ParsoidRenderID $expected ): void {
78 $actual = ParsoidRenderID::newFromKey( $key );
79 $this->assertSame( $expected->getKey(), $actual->getKey() );
80 }
81
82 public static function provideNewFromKey(): iterable {
83 yield [ '1/abc', new ParsoidRenderID( 1, 'abc' ) ];
84 yield [ '2/bar', new ParsoidRenderID( 2, 'bar' ) ];
85 }
86
87 /**
88 * @dataProvider provideBadKeys
89 * @covers \MediaWiki\Edit\ParsoidRenderID::newFromKey
90 */
91 public function testBadNewFromKey( $key ): void {
92 $this->expectException( InvalidArgumentException::class );
93 $this->expectExceptionMessage( "Bad key: $key" );
94
95 ParsoidRenderID::newFromKey( $key );
96 }
97
98 public static function provideBadKeys(): iterable {
99 yield [ '' ];
100 yield [ '1' ];
101 }
102 }