. */ namespace SP\Tests\Services\Import; use PHPUnit\Framework\TestCase; use SP\Services\Import\FileImport; use SP\Services\Import\ImportException; use SP\Services\Import\XmlFileImport; use SP\Storage\File\FileException; /** * Class XmlFileImportTest * * @package SP\Tests\Services\Import */ class XmlFileImportTest extends TestCase { /** * @throws ImportException * @throws FileException */ public function testDetectXMLFormat() { $file = RESOURCE_PATH . DIRECTORY_SEPARATOR . 'import' . DIRECTORY_SEPARATOR . 'data_syspass.xml'; $import = new XmlFileImport(FileImport::fromFilesystem($file)); $this->assertEquals('syspass', $import->detectXMLFormat()); $file = RESOURCE_PATH . DIRECTORY_SEPARATOR . 'import' . DIRECTORY_SEPARATOR . 'data_keepass.xml'; $import = new XmlFileImport(FileImport::fromFilesystem($file)); $this->assertEquals('keepass', $import->detectXMLFormat()); } /** * @throws ImportException * @throws FileException */ public function testInvalidFile() { $file = RESOURCE_PATH . DIRECTORY_SEPARATOR . 'import' . DIRECTORY_SEPARATOR . 'data.csv'; $this->expectException(ImportException::class); new XmlFileImport(FileImport::fromFilesystem($file)); } /** * @throws ImportException * @throws FileException */ public function testEmptyFile() { $file = RESOURCE_PATH . DIRECTORY_SEPARATOR . 'import' . DIRECTORY_SEPARATOR . 'data_empty.xml'; $import = new XmlFileImport(FileImport::fromFilesystem($file)); $this->expectException(ImportException::class); $import->detectXMLFormat(); } }