contentModeller = new ContentModeller(); $this->fileFetcher = new FileFetcher(); $this->file = new File(); } public function testCanConstruct() { $this->assertInstanceOf( JsonImportContentsFileDirReader::class, new JsonImportContentsFileDirReader( $this->contentModeller, $this->fileFetcher, $this->file ) ); } public function testGetContentList() { $instance = new JsonImportContentsFileDirReader( $this->contentModeller, $this->fileFetcher, $this->file, [ \SMW_PHPUNIT_DIR . '/Fixtures/Importer/Others/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->fileFetcher, $this->file, [ \SMW_PHPUNIT_DIR . '/Fixtures/Importer/Others/NoImportFormat' ] ); $this->assertEmpty( $instance->getContentList() ); } public function testGetContentListOnMissingSections() { $instance = new JsonImportContentsFileDirReader( $this->contentModeller, $this->fileFetcher, $this->file, [ \SMW_PHPUNIT_DIR . '/Fixtures/Importer/Others/MissingSections' ] ); $contents = $instance->getContentList(); $this->assertArrayHasKey( 'error.json', $contents ); } public function testGetContentListWithInvalidPath() { $instance = new JsonImportContentsFileDirReader( $this->contentModeller, $this->fileFetcher, $this->file, [ \SMW_PHPUNIT_DIR . '/Fixtures/Importer/Others/InvalidPath' ] ); $this->assertEmpty( $instance->getContentList() ); } public function testGetContentListOnInvalidJson_Error() { $instance = new JsonImportContentsFileDirReader( $this->contentModeller, $this->fileFetcher, $this->file, [ \SMW_PHPUNIT_DIR . '/Fixtures/Importer/Others/InvalidJsonContent' ] ); $instance->getContentList(); $this->assertContains( 'JSON error in file', implode( '', $instance->getErrors() ) ); } }