1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use SilverStripe\Dev\FunctionalTest; |
4
|
|
|
use SilverStripe\Forms\FieldList; |
5
|
|
|
use Symbiote\QueuedJobs\Controllers\QueuedJobsAdmin; |
6
|
|
|
use Symbiote\QueuedJobs\Jobs\PublishItemsJob; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Tests for the QueuedJobsAdmin ModelAdmin clas |
10
|
|
|
* |
11
|
|
|
* @coversDefaultClass \Symbiote\QueuedJobs\Controllers\QueuedJobsAdmin |
12
|
|
|
* @package queuedjobs |
13
|
|
|
* @author Robbie Averill <[email protected]> |
14
|
|
|
*/ |
15
|
|
|
class QueuedJobsAdminTest extends FunctionalTest |
|
|
|
|
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* {@inheritDoc} |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
// protected static $fixture_file = 'QueuedJobsAdminTest.yml'; |
|
|
|
|
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var QueuedJobsAdmin |
25
|
|
|
*/ |
26
|
|
|
protected $admin; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Get a test class, and mock the job queue for it |
30
|
|
|
* |
31
|
|
|
* {@inheritDoc} |
32
|
|
|
*/ |
33
|
|
|
public function setUp() |
34
|
|
|
{ |
35
|
|
|
parent::setUp(); |
36
|
|
|
$this->admin = new QueuedJobsAdmin; |
37
|
|
|
|
38
|
|
|
// Compatible with both PHPUnit 3 and PHPUnit 5+ |
39
|
|
|
$mockQueue = method_exists($this, 'createMock') ? $this->createMock('Symbiote\\QueuedJobs\\Services\\QueuedJobService') : $this->getMock('Symbiote\\QueuedJobs\\Services\\QueuedJobService'); |
40
|
|
|
$this->admin->jobQueue = $mockQueue; |
41
|
|
|
|
42
|
|
|
$this->logInWithPermission('ADMIN'); |
43
|
|
|
$this->admin->doInit(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Ensure that the JobParams field is added as a Textarea |
48
|
|
|
*/ |
49
|
|
|
public function testConstructorParamsShouldBeATextarea() |
50
|
|
|
{ |
51
|
|
|
$fields = $this->admin->getEditForm('foo', new FieldList)->Fields(); |
|
|
|
|
52
|
|
|
$this->assertInstanceOf('SilverStripe\\Forms\\TextareaField', $fields->fieldByName('JobParams')); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Ensure that when a multi-line value is entered for JobParams, it is split by new line and each value |
57
|
|
|
* passed to the constructor of the JobType that is created by the reflection in createjob() |
58
|
|
|
* |
59
|
|
|
* @covers ::createjob |
60
|
|
|
*/ |
61
|
|
|
public function testCreateJobWithConstructorParams() |
62
|
|
|
{ |
63
|
|
|
$this->admin->jobQueue |
64
|
|
|
->expects($this->once()) |
65
|
|
|
->method('queueJob') |
66
|
|
|
->with($this->callback(function ($job) { |
67
|
|
|
return $job instanceof PublishItemsJob && $job->rootID === 'foo123'; |
|
|
|
|
68
|
|
|
})); |
69
|
|
|
|
70
|
|
|
$form = $this->admin->getEditForm('foo', new FieldList); |
|
|
|
|
71
|
|
|
$form->Fields()->fieldByName('JobParams')->setValue(implode(PHP_EOL, ['foo123', 'bar'])); |
72
|
|
|
$form->Fields()->fieldByName('JobType')->setValue(PublishItemsJob::class); |
73
|
|
|
|
74
|
|
|
$this->admin->createjob($form->getData(), $form); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.