blob: c4965e521f9ffc37ff17e4780427a2d3e5f91258 (
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
<?php
namespace SMW\Tests\Importer;
use SMW\Importer\ContentModeller;
use SMW\Importer\JsonImportContentsFileDirReader;
use SMW\Tests\TestEnvironment;
use SMW\Tests\PHPUnitCompat;
/**
* @covers \SMW\Importer\JsonImportContentsFileDirReader
* @group semantic-mediawiki
*
* @license GNU GPL v2+
* @since 2.5
*
* @author mwjames
*/
class JsonImportContentsFileDirReaderTest extends \PHPUnit_Framework_TestCase {
use PHPUnitCompat;
private $contentModeller;
private $testEnvironment;
private $fixtures;
protected function setUp() {
parent::setUp();
$this->contentModeller = new ContentModeller();
$this->testEnvironment = new TestEnvironment();
$this->fixtures = __DIR__ . '/Fixtures';
}
public function testCanConstruct() {
$this->assertInstanceOf(
JsonImportContentsFileDirReader::class,
new JsonImportContentsFileDirReader( $this->contentModeller, $this->fixtures )
);
}
public function testGetContentList() {
$instance = new JsonImportContentsFileDirReader(
$this->contentModeller,
[ $this->fixtures . '/ValidTextContent' ]
);
$contents = $instance->getContentList();
$this->assertArrayHasKey(
'content.json',
$contents
);
foreach ( $contents as $content ) {
foreach ( $content as $importContents ) {
$this->assertInstanceOf(
'\SMW\Importer\ImportContents',
$importContents
);
}
}
}
public function testGetContentListOnFalseImportFormat() {
$instance = new JsonImportContentsFileDirReader(
$this->contentModeller,
[ $this->fixtures . '/NoImportFormat' ]
);
$this->assertEmpty(
$instance->getContentList()
);
}
public function testGetContentListOnMissingSections() {
$instance = new JsonImportContentsFileDirReader(
$this->contentModeller,
[ $this->fixtures . '/MissingSections' ]
);
$contents = $instance->getContentList();
$this->assertArrayHasKey(
'error.json',
$contents
);
}
public function testGetContentListWithInvalidPath() {
$instance = new JsonImportContentsFileDirReader(
$this->contentModeller,
[ __DIR__ . '/InvalidPath' ]
);
$this->assertEmpty(
$instance->getContentList()
);
}
public function testGetContentListOnInvalidJsonThrowsException() {
$instance = new JsonImportContentsFileDirReader(
$this->contentModeller,
[ $this->fixtures . '/InvalidJsonContent' ]
);
$this->setExpectedException( 'RuntimeException' );
$instance->getContentList();
}
}
|