assertFalse($sut->supports($this->getInvoiceDocument('default.html.twig'))); $this->assertFalse($sut->supports($this->getInvoiceDocument('freelancer.pdf.twig'))); $this->assertFalse($sut->supports($this->getInvoiceDocument('timesheet.html.twig'))); $this->assertFalse($sut->supports($this->getInvoiceDocument('company.docx'))); $this->assertFalse($sut->supports($this->getInvoiceDocument('spreadsheet.xlsx', true))); $this->assertFalse($sut->supports($this->getInvoiceDocument('open-spreadsheet.ods', true))); $this->assertTrue($sut->supports($this->getInvoiceDocument('text.txt.twig'))); $this->assertFalse($sut->supports($this->getInvoiceDocument('javascript.json.twig'))); $this->assertFalse($sut->supports($this->getInvoiceDocument('xml.xml.twig'))); } public function testRender() { $kernel = self::bootKernel(); /** @var Environment $twig */ $twig = $kernel->getContainer()->get('twig'); $stack = $kernel->getContainer()->get('request_stack'); $request = new Request(); $request->setLocale('en'); $stack->push($request); /** @var FilesystemLoader $loader */ $loader = $twig->getLoader(); $loader->addPath($this->getInvoiceTemplatePath(), 'invoice'); $sut = new TextRenderer($twig); $model = $this->getInvoiceModel(); $document = $this->getInvoiceDocument('text.txt.twig'); $response = $sut->render($document, $model); self::assertEquals('text/plain', $response->headers->get('Content-Type')); $content = $response->getContent(); foreach ($model->toArray() as $key => $value) { if (null === $value || '' === $value) { self::assertStringContainsString(sprintf("%s\n", $key), $content); } else { self::assertStringContainsString(sprintf("%s\n %s", $key, explode("\n", $value)[0]), $content); } } foreach ($model->getCalculator()->getEntries() as $entry) { foreach ($model->itemToArray($entry) as $key => $value) { if (null === $value || '' === $value) { self::assertStringContainsString(sprintf("%s\n", $key), $content); } else { self::assertStringContainsString(sprintf("%s\n %s", $key, explode("\n", $value)[0]), $content); } } } self::assertEquals(\count($model->getCalculator()->getEntries()), substr_count($content, PHP_EOL . '---' . PHP_EOL)); $this->assertStringContainsString( 'entry.description' . PHP_EOL . ' foo' . PHP_EOL . ' foo' . PHP_EOL . ' foo' . PHP_EOL . ' bar' . PHP_EOL . ' bar' . PHP_EOL . ' Hello', $content ); } }