Completed
Push — master ( 4b6f2c...a34ca5 )
by Simon
01:45
created

PartialSubmissionJobTest::testNewJobCreated()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 8
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\Debug;
10
use SilverStripe\Dev\SapphireTest;
11
use SilverStripe\ORM\FieldType\DBDatetime;
12
use SilverStripe\SiteConfig\SiteConfig;
13
use Symbiote\QueuedJobs\Services\QueuedJobService;
14
15
class PartialSubmissionJobTest extends SapphireTest
16
{
17
    protected static $fixture_file = '../fixtures/submission.yml';
18
    /**
19
     * @var PartialSubmissionJob
20
     */
21
    protected $job;
22
23
    public function testGetTitle()
24
    {
25
        $this->assertEquals('Export partial submissions to Email', $this->job->getTitle());
26
    }
27
28
    public function testProcess()
29
    {
30
        $this->assertTrue(method_exists($this->job, 'process'));
31
        $config = SiteConfig::current_site_config();
32
        $config->SendDailyEmail = true;
33
        $config->SendMailTo = '[email protected]';
34
        $config->write();
35
        $this->job->process();
36
37
        $this->assertEmailSent('[email protected]');
38
        $this->assertFileExists('/tmp/Export of TestForm - 2018-01-01 12:00:00.csv');
39
    }
40
41
    public function testProcessNoMail()
42
    {
43
        $this->assertTrue(method_exists($this->job, 'process'));
44
        $config = SiteConfig::current_site_config();
45
        $config->SendDailyEmail = true;
46
        $config->SendMailTo = '';
47
        $config->write();
48
        $this->job->process();
49
50
        $messages = $this->job->getMessages();
51
        foreach ($messages as $message) {
52
            $this->assertContains('Can not process without valid email', $message);
53
        }
54
    }
55
56 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...
57
    {
58
        $submission = $this->objFromFixture(PartialFormSubmission::class, 'submission1');
59
        $config = SiteConfig::current_site_config();
60
        $config->SendDailyEmail = true;
61
        $config->SendMailTo = '[email protected]';
62
        $config->write();
63
        $this->job->process();
64
65
        $processedSubmission = $submission->get()->byID($submission->ID);
66
67
        $this->assertTrue((bool)$processedSubmission->IsSend);
68
    }
69
70 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...
71
    {
72
        $submission = $this->objFromFixture(PartialFormSubmission::class, 'submission1');
73
        $config = SiteConfig::current_site_config();
74
        $config->SendDailyEmail = true;
75
        $config->CleanupAfterSend = true;
76
        $config->SendMailTo = '[email protected]';
77
        $config->write();
78
        $this->job->process();
79
        $this->job->afterComplete();
80
81
        $processedSubmission = $submission->get()->byID($submission->ID);
82
83
        $this->assertNull($processedSubmission);
84
    }
85
//
0 ignored issues
show
Unused Code Comprehensibility introduced by
48% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
86
//    public function testNewJobCreated()
87
//    {
88
//        $config = SiteConfig::current_site_config();
89
//        $config->SendDailyEmail = true;
90
//        $config->CleanupAfterSend = true;
91
//        $config->SendMailTo = '[email protected]';
92
//        $config->write();
93
//        $this->job->process();
94
//        $this->job->afterComplete();
95
//    }
96
97
    protected function setUp()
98
    {
99
        $this->usesDatabase = true;
100
        Config::modify()->set(QueuedJobService::class, 'use_shutdown_function', false);
101
        DBDatetime::set_mock_now('2018-01-01 12:00:00');
102
        /** @var PartialSubmissionJob $job */
103
        $this->job = Injector::inst()->get(PartialSubmissionJob::class);
104
105
        return parent::setUp();
106
    }
107
108
    protected function tearDown()
109
    {
110
        parent::tearDown();
111
    }
112
}
113