1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: simon |
5
|
|
|
* Date: 10-May-18 |
6
|
|
|
* Time: 10:02 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Firesphere\PartialUserforms\Tests; |
10
|
|
|
|
11
|
|
|
use Firesphere\PartialUserforms\Tasks\PartialSubmissionTask; |
12
|
|
|
use SilverStripe\Control\HTTPRequest; |
13
|
|
|
use SilverStripe\Core\Config\Config; |
14
|
|
|
use SilverStripe\Core\Injector\Injector; |
15
|
|
|
use SilverStripe\Dev\SapphireTest; |
16
|
|
|
use SilverStripe\Security\IdentityStore; |
17
|
|
|
use SilverStripe\Security\Member; |
18
|
|
|
use SilverStripe\Security\Security; |
19
|
|
|
use SilverStripe\SiteConfig\SiteConfig; |
20
|
|
|
use Symbiote\QueuedJobs\Services\QueuedJobService; |
21
|
|
|
|
22
|
|
|
class PartialSubmissionTaskTest extends SapphireTest |
23
|
|
|
{ |
24
|
|
|
public function testTitle() |
25
|
|
|
{ |
26
|
|
|
$task = Injector::inst()->get(PartialSubmissionTask::class); |
27
|
|
|
$this->assertEquals('Export partial form submissions to email address', $task->getTitle()); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testRun() |
31
|
|
|
{ |
32
|
|
|
$config = SiteConfig::current_site_config(); |
33
|
|
|
$config->SendDailyEmail = true; |
34
|
|
|
$config->SendMailTo = '[email protected]'; |
35
|
|
|
$config->write(); |
36
|
|
|
$request = new HTTPRequest('GET', 'dev/tasks/partialsubmissiontask'); |
37
|
|
|
|
38
|
|
|
$task = Injector::inst()->get(PartialSubmissionTask::class); |
39
|
|
|
|
40
|
|
|
$task->run($request); |
41
|
|
|
|
42
|
|
|
$this->assertEmailSent('[email protected]'); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
View Code Duplication |
public function testExtraUser() |
|
|
|
|
46
|
|
|
{ |
47
|
|
|
$config = SiteConfig::current_site_config(); |
48
|
|
|
$config->SendDailyEmail = true; |
49
|
|
|
$config->SendMailTo = '[email protected]'; |
50
|
|
|
$config->write(); |
51
|
|
|
$rand = uniqid('', false); |
52
|
|
|
$user = Member::create(['FirstName' => 'Test', 'Email' => $rand . '@example.com']); |
53
|
|
|
$user->write(); |
54
|
|
|
Security::setCurrentUser($user); |
55
|
|
|
$request = new HTTPRequest('GET', 'dev/tasks/partialsubmissiontask'); |
56
|
|
|
|
57
|
|
|
$task = Injector::inst()->get(PartialSubmissionTask::class); |
58
|
|
|
|
59
|
|
|
$task->run($request); |
60
|
|
|
|
61
|
|
|
$this->assertEmailSent($rand . '@example.com'); |
62
|
|
|
$this->assertEmailSent('[email protected]'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
View Code Duplication |
public function testNoConfigButUser() |
|
|
|
|
66
|
|
|
{ |
67
|
|
|
$rand = uniqid('', false); |
68
|
|
|
$user = Member::create(['FirstName' => 'Test', 'Email' => $rand . '@example.com']); |
69
|
|
|
$user->write(); |
70
|
|
|
Security::setCurrentUser($user); |
71
|
|
|
$config = SiteConfig::current_site_config(); |
72
|
|
|
$config->SendDailyEmail = true; |
73
|
|
|
$config->write(); |
74
|
|
|
$request = new HTTPRequest('GET', 'dev/tasks/partialsubmissiontask'); |
75
|
|
|
|
76
|
|
|
$task = Injector::inst()->get(PartialSubmissionTask::class); |
77
|
|
|
|
78
|
|
|
$task->run($request); |
79
|
|
|
|
80
|
|
|
$this->assertEmailSent($rand . '@example.com'); |
81
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
protected function setUp() |
85
|
|
|
{ |
86
|
|
|
parent::setUp(); |
87
|
|
|
Config::modify()->set(QueuedJobService::class, 'use_shutdown_function', false); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
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.