Completed
Push — master ( 813ff2...07dd29 )
by mw
377:22 queued 342:34
created

TextContentCreatorTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
c 0
b 0
f 0
cc 1
eloc 11
nc 1
nop 0
rs 9.4285
1
<?php
2
3
namespace SMW\TestsImporter\ContentCreators;
4
5
use SMW\Importer\ContentCreators\TextContentCreator;
6
use SMW\Importer\ImportContents;
7
8
/**
9
 * @covers \SMW\Importer\ContentCreators\TextContentCreator
10
 * @group semantic-mediawiki
11
 *
12
 * @license GNU GPL v2+
13
 * @since 2.5
14
 *
15
 * @author mwjames
16
 */
17
class TextContentCreatorTest extends \PHPUnit_Framework_TestCase {
18
19
	private $pageCreator;
20
	private $connection;
21
	private $messageReporter;
22
23
	protected function setUp() {
24
		parent::setUp();
25
26
		$this->pageCreator = $this->getMockBuilder( '\SMW\MediaWiki\PageCreator' )
27
			->disableOriginalConstructor()
28
			->getMock();
29
30
		$this->connection = $this->getMockBuilder( '\SMW\MediaWiki\Database' )
31
			->disableOriginalConstructor()
32
			->getMock();
33
34
		$this->messageReporter = $this->getMockBuilder( '\Onoi\MessageReporter\MessageReporter' )
35
			->disableOriginalConstructor()
36
			->getMock();
37
	}
38
39
	public function testCanConstruct() {
40
41
		$this->assertInstanceOf(
42
			'\SMW\Importer\ContentCreators\TextContentCreator',
43
			new TextContentCreator( $this->pageCreator, $this->connection )
44
		);
45
	}
46
47
	public function testCanCreateContentsFor() {
48
49
		$instance = new TextContentCreator(
50
			$this->pageCreator,
51
			$this->connection
52
		);
53
54
		$importContents = new ImportContents();
55
		$importContents->setContentType( ImportContents::CONTENT_TEXT );
56
57
		$this->assertTrue(
58
			$instance->canCreateContentsFor( $importContents )
59
		);
60
	}
61
62
	public function testDoCreateFrom() {
63
64
		$this->connection->expects( $this->once() )
65
			->method( 'onTransactionIdle' )
66
			->will( $this->returnCallback( function( $callback ) {
67
				return call_user_func( $callback ); }
68
			) );
69
70
		$page = $this->getMockBuilder( '\WikiPage' )
71
			->disableOriginalConstructor()
72
			->getMock();
73
74
		$page->expects( $this->once() )
75
			->method( 'doEditContent' );
76
77
		$this->pageCreator->expects( $this->atLeastOnce() )
78
			->method( 'createPage' )
79
			->will( $this->returnValue( $page ) );
80
81
		$instance = new TextContentCreator(
82
			$this->pageCreator,
83
			$this->connection
84
		);
85
86
		$instance->setMessageReporter(
87
			$this->messageReporter
88
		);
89
90
		$importContents = new ImportContents();
91
		$importContents->setContentType( ImportContents::CONTENT_TEXT );
92
		$importContents->setName( 'Foo' );
93
94
		$instance->doCreateFrom( $importContents );
95
	}
96
97
}
98