Completed
Push — master ( cebd6a...4982e0 )
by Simon
01:36
created

PartialSubmissionJobTest::testIsDeleted()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 15
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 15
loc 15
rs 9.4285
cc 1
eloc 10
nc 1
nop 0
1
<?php
2
3
namespace Firesphere\PartialUserforms\Tests;
4
5
use Firesphere\PartialUserforms\Jobs\PartialSubmissionJob;
6
use Firesphere\PartialUserforms\Models\PartialFormSubmission;
7
use SilverStripe\Core\Config\Config;
8
use SilverStripe\Core\Injector\Injector;
9
use SilverStripe\Dev\SapphireTest;
10
use SilverStripe\ORM\FieldType\DBDatetime;
11
use SilverStripe\SiteConfig\SiteConfig;
12
use Symbiote\QueuedJobs\Services\QueuedJobService;
13
14
class PartialSubmissionJobTest extends SapphireTest
15
{
16
    protected static $fixture_file = '../fixtures/submission.yml';
17
    /**
18
     * @var PartialSubmissionJob
19
     */
20
    protected $job;
21
22
    public function testGetTitle()
23
    {
24
        $this->assertEquals('Export partial submissions to Email', $this->job->getTitle());
25
    }
26
27
    public function testProcess()
28
    {
29
        $this->assertTrue(method_exists($this->job, 'process'));
30
        $config = SiteConfig::current_site_config();
31
        $config->SendDailyEmail = true;
32
        $config->SendMailTo = '[email protected]';
33
        $config->write();
34
        $this->job->process();
35
36
        $this->assertEmailSent('[email protected]');
37
        $this->assertFileExists('/tmp/Export of TestForm - 2018-01-01 12:00:00.csv');
38
    }
39
40 View Code Duplication
    public function testIsSend()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
41
    {
42
        $submission = $this->objFromFixture(PartialFormSubmission::class, 'submission1');
43
        $config = SiteConfig::current_site_config();
44
        $config->SendDailyEmail = true;
45
        $config->SendMailTo = '[email protected]';
46
        $config->write();
47
        $this->job->process();
48
49
        $processedSubmission = $submission->get()->byID($submission->ID);
50
51
        $this->assertTrue($processedSubmission->IsSend);
52
    }
53
54 View Code Duplication
    public function testIsDeleted()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
55
    {
56
        $submission = $this->objFromFixture(PartialFormSubmission::class, 'submission1');
57
        $config = SiteConfig::current_site_config();
58
        $config->SendDailyEmail = true;
59
        $config->CleanupAfterSend = true;
60
        $config->SendMailTo = '[email protected]';
61
        $config->write();
62
        $this->job->process();
63
64
        $processedSubmission = $submission->get()->byID($submission->ID);
65
66
        $this->assertNull($processedSubmission);
67
68
    }
69
70
    protected function setUp()
71
    {
72
        $this->usesDatabase = true;
73
        Config::modify()->set(QueuedJobService::class, 'use_shutdown_function', false);
74
        DBDatetime::set_mock_now('2018-01-01 12:00:00');
75
        /** @var PartialSubmissionJob $job */
76
        $this->job = Injector::inst()->get(PartialSubmissionJob::class);
77
78
        return parent::setUp();
79
    }
80
81
    protected function tearDown()
82
    {
83
        parent::tearDown(); // TODO: Change the autogenerated stub
84
    }
85
}
86