File: ParsoidRenderIdTest.php

package info (click to toggle)
mediawiki 1%3A1.43.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 417,464 kB
  • sloc: php: 1,062,949; javascript: 664,290; sql: 9,714; python: 5,458; xml: 3,489; sh: 1,131; makefile: 64
file content (102 lines) | stat: -rw-r--r-- 2,840 bytes parent folder | download
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
97
98
99
100
101
102
<?php

namespace MediaWiki\Tests\Unit\Edit;

use InvalidArgumentException;
use MediaWiki\Edit\ParsoidRenderID;
use MediaWikiUnitTestCase;

class ParsoidRenderIdTest extends MediaWikiUnitTestCase {

	/**
	 * @covers \MediaWiki\Edit\ParsoidRenderID
	 */
	public function testConstruction() {
		$renderID = new ParsoidRenderID( 1, '123-abc' );
		$this->assertSame( 1, $renderID->getRevisionID() );
		$this->assertEquals( '123-abc', $renderID->getUniqueID() );
		$this->assertEquals( '1/123-abc', $renderID->__toString() );
	}

	/**
	 * @covers \MediaWiki\Edit\ParsoidRenderID::newFromKey
	 */
	public function testRoundTrip() {
		$renderID = new ParsoidRenderID( 1, '123-abc' );
		$stringRenderID = $renderID->__toString();
		$backToRenderID = $renderID::newFromKey( $stringRenderID );
		$this->assertSame( $stringRenderID, $backToRenderID->__toString() );
	}

	/**
	 * @dataProvider provideETags
	 *
	 * @param string $eTag
	 * @param \MediaWiki\Edit\ParsoidRenderID $renderId
	 *
	 * @covers \MediaWiki\Edit\ParsoidRenderID::newFromETag
	 */
	public function testNewFromETag( $eTag, $renderId ) {
		$actual = ParsoidRenderID::newFromETag( $eTag );
		$this->assertSame( $renderId->getKey(), $actual->getKey() );
	}

	public static function provideETags() {
		yield [ '"1/abc/stash"', new ParsoidRenderID( 1, 'abc' ) ];
		yield [ '"1/abc"', new ParsoidRenderID( 1, 'abc' ) ];
		yield [ '"1/abc/stash/stash"', new ParsoidRenderID( 1, 'abc' ) ];
		yield [ 'W/"1/abc"', new ParsoidRenderID( 1, 'abc' ) ];
	}

	/**
	 * @dataProvider provideBadETags
	 *
	 * @param string $eTag
	 *
	 * @covers \MediaWiki\Edit\ParsoidRenderID::newFromETag
	 */
	public function testNewFromBadETag( $eTag ) {
		// make sure it doesn't explode
		$this->assertNull( ParsoidRenderID::newFromETag( $eTag ) );
	}

	public static function provideBadETags() {
		yield [ '' ];
		yield [ '0' ];
		yield [ '""' ];
		yield [ '"/"' ];
		yield [ '"x/y"' ];
		yield [ '"1/foo"XXX' ];
		yield [ 'XXX"1/foo"' ];
	}

	/**
	 * @dataProvider provideNewFromKey
	 * @covers \MediaWiki\Edit\ParsoidRenderID::newFromKey
	 */
	public function testNewFromKey( string $key, ParsoidRenderID $expected ): void {
		$actual = ParsoidRenderID::newFromKey( $key );
		$this->assertSame( $expected->getKey(), $actual->getKey() );
	}

	public static function provideNewFromKey(): iterable {
		yield [ '1/abc', new ParsoidRenderID( 1, 'abc' ) ];
		yield [ '2/bar', new ParsoidRenderID( 2, 'bar' ) ];
	}

	/**
	 * @dataProvider provideBadKeys
	 * @covers \MediaWiki\Edit\ParsoidRenderID::newFromKey
	 */
	public function testBadNewFromKey( $key ): void {
		$this->expectException( InvalidArgumentException::class );
		$this->expectExceptionMessage( "Bad key: $key" );

		ParsoidRenderID::newFromKey( $key );
	}

	public static function provideBadKeys(): iterable {
		yield [ '' ];
		yield [ '1' ];
	}
}