1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\Tests\Importer\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
|
|
|
if ( !interface_exists( '\ImportSource' ) ) { |
27
|
|
|
$this->markTestSkipped( "ImportSource interface is unknown (MW 1.25-)" ); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
$importStreamSource = $this->getMockBuilder( '\ImportStreamSource' ) |
31
|
|
|
->disableOriginalConstructor() |
32
|
|
|
->getMock(); |
33
|
|
|
|
34
|
|
|
$this->wikiImporter = $this->getMockBuilder( '\WikiImporter' ) |
35
|
|
|
->disableOriginalConstructor() |
36
|
|
|
->getMock(); |
37
|
|
|
|
38
|
|
|
$this->importServicesFactory = $this->getMockBuilder( '\SMW\Services\ImportServicesFactory' ) |
39
|
|
|
->disableOriginalConstructor() |
40
|
|
|
->getMock(); |
41
|
|
|
|
42
|
|
|
$this->importServicesFactory->expects( $this->any() ) |
43
|
|
|
->method( 'newImportStreamSource' ) |
44
|
|
|
->will( $this->returnValue( $importStreamSource ) ); |
45
|
|
|
|
46
|
|
|
$this->importServicesFactory->expects( $this->any() ) |
47
|
|
|
->method( 'newWikiImporter' ) |
48
|
|
|
->will( $this->returnValue( $this->wikiImporter ) ); |
49
|
|
|
|
50
|
|
|
$this->messageReporter = $this->getMockBuilder( '\Onoi\MessageReporter\MessageReporter' ) |
51
|
|
|
->disableOriginalConstructor() |
52
|
|
|
->getMock(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function testCanConstruct() { |
56
|
|
|
|
57
|
|
|
$this->assertInstanceOf( |
58
|
|
|
'\SMW\Importer\ContentCreators\XmlContentCreator', |
59
|
|
|
new XmlContentCreator( $this->importServicesFactory ) |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testCanCreateContentsFor() { |
64
|
|
|
|
65
|
|
|
$instance = new XmlContentCreator( |
66
|
|
|
$this->importServicesFactory |
67
|
|
|
); |
68
|
|
|
|
69
|
|
|
$importContents = new ImportContents(); |
70
|
|
|
$importContents->setContentType( ImportContents::CONTENT_XML ); |
71
|
|
|
|
72
|
|
|
$this->assertTrue( |
73
|
|
|
$instance->canCreateContentsFor( $importContents ) |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function testDoCreateFrom() { |
78
|
|
|
|
79
|
|
|
$this->wikiImporter->expects( $this->atLeastOnce() ) |
80
|
|
|
->method( 'doImport' ); |
81
|
|
|
|
82
|
|
|
$instance = new XmlContentCreator( |
83
|
|
|
$this->importServicesFactory |
84
|
|
|
); |
85
|
|
|
|
86
|
|
|
$instance->setMessageReporter( |
87
|
|
|
$this->messageReporter |
88
|
|
|
); |
89
|
|
|
|
90
|
|
|
$importContents = new ImportContents(); |
91
|
|
|
$importContents->setContentType( ImportContents::CONTENT_XML ); |
92
|
|
|
$importContents->setContentsFile( 'Foo' ); |
93
|
|
|
|
94
|
|
|
$instance->doCreateFrom( $importContents ); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
} |
98
|
|
|
|