1 | <?php |
||
12 | class GenerateCSVJobTest extends SapphireTest |
||
13 | { |
||
14 | |||
15 | protected static $fixture_file = 'GenerateCSVJobTest.yml'; |
||
16 | |||
17 | protected static $extra_dataobjects = [GenerateCSVJobTestRecord::class]; |
||
18 | |||
19 | protected static $extra_controllers = [GenerateCSVJobTestController::class]; |
||
20 | |||
21 | protected function setUp() |
||
29 | |||
30 | protected $paths = []; |
||
31 | |||
32 | protected function tearDown() |
||
39 | |||
40 | public function testGenerateExport() |
||
41 | { |
||
42 | // Build session |
||
43 | $memberID = $this->logInWithPermission('ADMIN'); |
||
44 | $session = ['loggedInAs' => $memberID]; |
||
45 | |||
46 | // Build controller |
||
47 | $controller = new GenerateCSVJobTestController(); |
||
48 | $form = $controller->Form(); |
||
49 | $gridfield = $form->Fields()->fieldByName('MyGridfield'); |
||
50 | |||
51 | // Build job |
||
52 | $job = $this->createJob($gridfield, $session); |
||
53 | $path = sprintf('%1$s/.exports/%2$s/%2$s.csv', ASSETS_PATH, $job->getSignature()); |
||
54 | $this->paths[] = $path; // Mark for cleanup later |
||
55 | |||
56 | // Test that the job runs |
||
57 | $this->assertFileNotExists($path); |
||
58 | $job->process(); |
||
59 | $this->assertFileExists($path); |
||
60 | |||
61 | // Test that the output matches the expected |
||
62 | $expected = [ |
||
63 | 'Title,Content,"Publish On"', |
||
64 | '"Record 1","<p>""Record 1"" Body</p>","2015-01-01 23:34:01"', |
||
65 | '"Record 2","<p>""Record 2"" Body</p>","2015-01-02 23:34:01"', |
||
66 | '"Record 3","<p>""Record 3"" Body</p>","2015-01-03 23:34:01"', |
||
67 | '', |
||
68 | ]; |
||
69 | $actual = file_get_contents($path); |
||
70 | $this->assertEquals(implode("\r\n", $expected), $actual); |
||
71 | } |
||
72 | |||
73 | public function testGenerateExportOverMultipleSteps() |
||
110 | |||
111 | /** |
||
112 | * Rough copy of GridFieldQueuedExportButton::startExport |
||
113 | * |
||
114 | * @param GridField $gridField |
||
115 | * @param array $session |
||
116 | * @return GenerateCSVJob |
||
117 | */ |
||
118 | protected function createJob($gridField, $session) |
||
127 | } |
||
128 |