1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\TestsImporter; |
4
|
|
|
|
5
|
|
|
use SMW\Importer\JsonImportContentsFileDirReader; |
6
|
|
|
use SMW\Tests\TestEnvironment; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @covers \SMW\Importer\JsonImportContentsFileDirReader |
10
|
|
|
* @group semantic-mediawiki |
11
|
|
|
* |
12
|
|
|
* @license GNU GPL v2+ |
13
|
|
|
* @since 2.5 |
14
|
|
|
* |
15
|
|
|
* @author mwjames |
16
|
|
|
*/ |
17
|
|
|
class JsonImportContentsFileDirReaderTest extends \PHPUnit_Framework_TestCase { |
18
|
|
|
|
19
|
|
|
private $testEnvironment; |
20
|
|
|
|
21
|
|
|
protected function setUp() { |
22
|
|
|
parent::setUp(); |
23
|
|
|
|
24
|
|
|
$this->testEnvironment = new TestEnvironment(); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function testCanConstruct() { |
28
|
|
|
|
29
|
|
|
$this->assertInstanceOf( |
30
|
|
|
'\SMW\Importer\JsonImportContentsFileDirReader', |
31
|
|
|
new JsonImportContentsFileDirReader( $this->testEnvironment->getFixturesLocation() ) |
32
|
|
|
); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testGetContentList() { |
36
|
|
|
|
37
|
|
|
$instance = new JsonImportContentsFileDirReader( |
38
|
|
|
$this->testEnvironment->getFixturesLocation( 'Importer/ValidTextContent' ) |
39
|
|
|
); |
40
|
|
|
|
41
|
|
|
$contents = $instance->getContentList(); |
42
|
|
|
|
43
|
|
|
$this->assertArrayHasKey( |
44
|
|
|
'content.json', |
45
|
|
|
$contents |
46
|
|
|
); |
47
|
|
|
|
48
|
|
|
foreach ( $contents as $content ) { |
49
|
|
|
foreach ( $content as $importContents ) { |
|
|
|
|
50
|
|
|
$this->assertInstanceOf( |
51
|
|
|
'\SMW\Importer\ImportContents', |
52
|
|
|
$importContents |
53
|
|
|
); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testGetContentListOnFalseImportFormat() { |
59
|
|
|
|
60
|
|
|
$instance = new JsonImportContentsFileDirReader( |
61
|
|
|
$this->testEnvironment->getFixturesLocation( 'Importer/NoImportFormat' ) |
62
|
|
|
); |
63
|
|
|
|
64
|
|
|
$this->assertEmpty( |
65
|
|
|
$instance->getContentList() |
66
|
|
|
); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function testGetContentListOnMissingSections() { |
70
|
|
|
|
71
|
|
|
$instance = new JsonImportContentsFileDirReader( |
72
|
|
|
$this->testEnvironment->getFixturesLocation( 'Importer/MissingSections' ) |
73
|
|
|
); |
74
|
|
|
|
75
|
|
|
$contents = $instance->getContentList(); |
76
|
|
|
|
77
|
|
|
$this->assertArrayHasKey( |
78
|
|
|
'error.json', |
79
|
|
|
$contents |
80
|
|
|
); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function testGetContentListWithInvalidPath() { |
84
|
|
|
|
85
|
|
|
$instance = new JsonImportContentsFileDirReader( |
86
|
|
|
__DIR__ . '/InvalidPath' |
87
|
|
|
); |
88
|
|
|
|
89
|
|
|
$this->assertEmpty( |
90
|
|
|
$instance->getContentList() |
91
|
|
|
); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function testGetContentListOnInvalidJsonThrowsException() { |
95
|
|
|
|
96
|
|
|
$instance = new JsonImportContentsFileDirReader( |
97
|
|
|
$this->testEnvironment->getFixturesLocation( 'Importer/InvalidJsonContent' ) |
98
|
|
|
); |
99
|
|
|
|
100
|
|
|
$this->setExpectedException( 'RuntimeException' ); |
101
|
|
|
$instance->getContentList(); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
} |
105
|
|
|
|