|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace CWP\PDFExport\Tests\Extensions; |
|
4
|
|
|
|
|
5
|
|
|
use CWP\CWP\PageTypes\BasePage; |
|
6
|
|
|
use CWP\PDFExport\Extensions\PdfExportExtension; |
|
7
|
|
|
use SilverStripe\Core\Config\Config; |
|
8
|
|
|
use SilverStripe\Dev\SapphireTest; |
|
9
|
|
|
|
|
10
|
|
|
class PdfExportExtensionTest extends SapphireTest |
|
11
|
|
|
{ |
|
12
|
|
|
protected static $fixture_file = 'PdfExportExtensionTest.yml'; |
|
13
|
|
|
|
|
14
|
|
|
protected static $required_extensions = [ |
|
15
|
|
|
BasePage::class => [ |
|
16
|
|
|
PdfExportExtension::class, |
|
17
|
|
|
], |
|
18
|
|
|
]; |
|
19
|
|
|
|
|
20
|
|
|
protected function setUp() |
|
21
|
|
|
{ |
|
22
|
|
|
parent::setUp(); |
|
23
|
|
|
|
|
24
|
|
|
Config::modify() |
|
25
|
|
|
->set(BasePage::class, 'pdf_export', true) |
|
26
|
|
|
->set(BasePage::class, 'generated_pdf_path', 'assets/_generated_pdfs'); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function testPdfFilename() |
|
30
|
|
|
{ |
|
31
|
|
|
$page = $this->objFromFixture(BasePage::class, 'test-page-one'); |
|
32
|
|
|
$this->assertContains( |
|
33
|
|
|
'assets/_generated_pdfs/test-page-one-1.pdf', |
|
34
|
|
|
$page->getPdfFilename(), |
|
35
|
|
|
'Generated filename for PDF' |
|
36
|
|
|
); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function testPdfLink() |
|
40
|
|
|
{ |
|
41
|
|
|
$page = $this->objFromFixture(BasePage::class, 'test-page-one'); |
|
42
|
|
|
$this->assertContains('test-page-one/downloadpdf', $page->PdfLink(), 'Link to download PDF'); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function testHomePagePdfLink() |
|
46
|
|
|
{ |
|
47
|
|
|
$page = $this->objFromFixture(BasePage::class, 'home-page'); |
|
48
|
|
|
$this->assertContains('home/downloadpdf', $page->PdfLink(), 'Link to download PDF'); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function testPdfLinkDisabled() |
|
52
|
|
|
{ |
|
53
|
|
|
Config::modify()->set(BasePage::class, 'pdf_export', false); |
|
54
|
|
|
$page = $this->objFromFixture(BasePage::class, 'test-page-one'); |
|
55
|
|
|
$this->assertFalse($page->PdfLink(), 'No PDF link as the functionality is disabled'); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|