summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Utils/Validators/TitleValidator.php
blob: 16b708025681a73fbfe24f1740a07d23e1b01739 (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
<?php

namespace SMW\Tests\Utils\Validators;

use Title;

/**
 * @license GNU GPL v2+
 * @since   2.1
 *
 * @author mwjames
 */
class TitleValidator extends \PHPUnit_Framework_Assert {

	/**
	 * @since 2.1
	 */
	public function assertThatTitleIsNotKnown( $titles ) {
		$this->assertTitleExists( false, $titles );
	}

	/**
	 * @since 2.1
	 */
	public function assertThatTitleIsKnown( $titles ) {
		$this->assertTitleExists( true, $titles );
	}

	private function assertTitleExists( $isExpected, $titles ) {

		if ( !is_array( $titles ) ) {
			$titles = [ $titles ];
		}

		foreach ( $titles as $title ) {

			if ( !$title instanceof Title && is_string( $title ) ) {
				$title = Title::newFromText( $title );
			}

			$this->assertEquals( $isExpected, $title->exists(), $title->getPrefixedText() );
		}
	}

}