Invoices: show only custom documents in upload form (#1786)
This commit is contained in:
@@ -22,6 +22,12 @@ class InvoiceDocumentRepositoryTest extends TestCase
|
||||
'templates/invoice/renderer'
|
||||
];
|
||||
|
||||
protected static $testDocuments = [
|
||||
'spreadsheet.xsls',
|
||||
'open-spreadsheet.ods',
|
||||
'default.pdf.twig',
|
||||
];
|
||||
|
||||
protected static $defaultDocuments = [
|
||||
'company.docx',
|
||||
'default.html.twig',
|
||||
@@ -33,19 +39,50 @@ class InvoiceDocumentRepositoryTest extends TestCase
|
||||
'xml.xml.twig',
|
||||
];
|
||||
|
||||
public function testWithEmptyDirectory()
|
||||
public function testDirectories()
|
||||
{
|
||||
$sut = new InvoiceDocumentRepository([]);
|
||||
$this->assertEmpty($sut->findAll());
|
||||
$this->assertIsArray($sut->findAll());
|
||||
$this->assertNull($sut->findByName('default'));
|
||||
self::assertEmpty($sut->findAll());
|
||||
self::assertIsArray($sut->findAll());
|
||||
self::assertNull($sut->findByName('default'));
|
||||
|
||||
try {
|
||||
$sut->getUploadDirectory();
|
||||
$this->fail('Expected exception was not raised');
|
||||
} catch (\Exception $ex) {
|
||||
$this->assertEquals('Unknown upload directory', $ex->getMessage());
|
||||
}
|
||||
|
||||
$path = realpath(__DIR__ . '/../Invoice/templates/');
|
||||
$sut->addDirectory($path);
|
||||
$sut->addDirectory(InvoiceDocumentRepository::DEFAULT_DIRECTORY);
|
||||
$sut->addDirectory(__DIR__);
|
||||
self::assertEquals(__DIR__, $sut->getUploadDirectory());
|
||||
|
||||
$sut->removeDirectory(__DIR__);
|
||||
|
||||
self::assertCount(\count(self::$defaultDocuments), $sut->findBuiltIn());
|
||||
self::assertCount(\count(self::$testDocuments), $sut->findCustom());
|
||||
|
||||
// template "default" exists twice, so its 10 instead of 11
|
||||
$all = [];
|
||||
foreach (self::$defaultDocuments as $document) {
|
||||
$all[] = substr($document, 0, strpos($document, '.'));
|
||||
}
|
||||
foreach (self::$testDocuments as $document) {
|
||||
$all[] = substr($document, 0, strpos($document, '.'));
|
||||
}
|
||||
$all = array_unique(array_values($all));
|
||||
self::assertCount(\count($all), $sut->findAll());
|
||||
|
||||
self::assertEquals($path, $sut->getUploadDirectory());
|
||||
}
|
||||
|
||||
public function testDefaultTemplatesExists()
|
||||
{
|
||||
$sut = new InvoiceDocumentRepository(self::$defaultDirectories);
|
||||
$all = $sut->findAll();
|
||||
$this->assertEquals(\count(self::$defaultDocuments), \count($all));
|
||||
$this->assertCount(\count(self::$defaultDocuments), $all);
|
||||
|
||||
foreach ($all as $document) {
|
||||
$this->assertTrue(\in_array($document->getName(), self::$defaultDocuments));
|
||||
|
||||
Reference in New Issue
Block a user