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

XmlContentCreatorTest::setUp()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

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