summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Utils/PageDeleter.php
blob: cebc13c14a8d2185c36b66f2c88c2679626c9325 (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
64
65
66
67
<?php

namespace SMW\Tests\Utils;

use SMW\DIWikiPage;
use SMW\Tests\TestEnvironment;
use Title;
use WikiPage;

/**
 * @group SMW
 * @group SMWExtension
 *
 * @license GNU GPL v2+
 * @since 1.9.1
 */
class PageDeleter {

	/**
	 * @var TestEnvironment
	 */
	private $testEnvironment;

	/**
	 * @since 2.4
	 */
	public function __construct() {
		$this->testEnvironment = new TestEnvironment();
	}

	/**
	 * @since 1.9.1
	 */
	public function deletePage( Title $title ) {
		$page = new WikiPage( $title );
		$page->doDeleteArticle( 'SMW system test: delete page' );
		$this->testEnvironment->executePendingDeferredUpdates();
	}

	/**
	 * @since 2.1
	 *
	 * @param array $poolOfPages
	 */
	public function doDeletePoolOfPages( array $poolOfPages ) {

		foreach ( $poolOfPages as $page ) {

			if ( $page instanceof WikiPage || $page instanceof DIWikiPage ) {
				$page = $page->getTitle();
			}

			if ( is_string( $page ) ) {
				$page = Title::newFromText( $page );
			}

			if ( !$page instanceof Title ) {
				continue;
			}

			$this->deletePage( $page );
		}

		$this->testEnvironment->executePendingDeferredUpdates();
	}

}