summaryrefslogtreecommitdiff
blob: c8ce82041ead6df69a447d01d7a2e8def28814c4 (plain)
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
<?php

namespace Babel\Tests;

use BabelAutoCreate;
use MediaWikiIntegrationTestCase;
use Title;
use WikiPage;

/**
 * @covers BabelAutoCreate
 *
 * @group Babel
 * @group Database
 *
 * @license GPL-2.0-or-later
 * @author Thiemo Kreuz
 */
class BabelAutoCreateTest extends MediaWikiIntegrationTestCase {

	protected function setUp(): void {
		parent::setUp();

		$this->setContentLang( 'qqx' );
	}

	public function testOnUserGetReservedNames() {
		$names = [];
		$this->assertSame( [], $names, 'Precondition' );

		$this->assertTrue( BabelAutoCreate::onUserGetReservedNames( $names ) );
		$this->assertSame( [ 'msg:babel-autocreate-user' ], $names );
	}

	/**
	 * @dataProvider createProvider
	 */
	public function testCreate( $category, $code, $level, $expected ) {
		BabelAutoCreate::create( $category, $code, $level );
		$page = WikiPage::factory( Title::newFromText( 'Category:' . $category ) );
		$this->assertTrue( $page->exists() );
		$this->assertSame( $expected, $page->getContent()->getText() );
	}

	public function createProvider() {
		return [
			[
				'category-1', 'en', null,
				'(babel-autocreate-text-main: English, en)'
			],
			[
				'category-2', 'en', 'level-2',
				'(babel-autocreate-text-levels: level-2, English, en)'
			],
		];
	}

	public function testUser() {
		$user = BabelAutoCreate::user();
		$this->assertInstanceOf( 'User', $user );
	}

}