Passed
Push — master ( 05e846...9de07a )
by Jason
02:44
created

JobCollectionTest::testGetPostedJobs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 16
nc 1
nop 0
dl 0
loc 26
rs 9.7333
c 0
b 0
f 0
1
<?php
2
3
namespace Dynamic\Jobs\Test\Page;
4
5
use Dynamic\Jobs\Page\Job;
6
use Dynamic\Jobs\Page\JobCollection;
7
use SilverStripe\Core\Injector\Injector;
8
use \SilverStripe\Dev\SapphireTest;
9
use SilverStripe\Forms\FieldList;
10
use SilverStripe\ORM\FieldType\DBDatetime;
11
use SilverStripe\ORM\ValidationResult;
12
13
/**
14
 * Class JobCollectionTest
15
 * @package Dynamic\Jobs\Tests
16
 */
17
class JobCollectionTest extends SapphireTest
18
{
19
    /**
20
     * @var string
21
     */
22
    protected static $fixture_file = '../fixtures.yml';
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function tearDown()
28
    {
29
        DBDatetime::clear_mock_now();
30
        parent::tearDown();
31
    }
32
33
    /**
34
     * Tests getCMSFields()
35
     */
36
    public function testGetCMSFields()
37
    {
38
        /** @var JobCollection $object */
39
        $object = Injector::inst()->create(JobCollection::class);
40
        $fields = $object->getCMSFields();
41
        $this->assertInstanceOf(FieldList::class, $fields);
42
    }
43
44
    /**
45
     * Tests validate()
46
     */
47
    public function testValidate()
48
    {
49
        /** @var JobCollection $object */
50
        $object = Injector::inst()->create(JobCollection::class);
51
        $valid = $object->validate();
52
        $this->assertInstanceOf(ValidationResult::class, $valid);
53
    }
54
55
    /**
56
     * Tests getPostedJobs()
57
     */
58
    public function testGetPostedJobs()
59
    {
60
        /** @var JobCollection $holder */
61
        $holder = $this->objFromFixture(JobCollection::class, 'default');
62
63
        /** @var Job $past */
64
        $past = $this->objFromFixture(Job::class, 'past');
65
        $past->write();
66
        /** @var Job $open */
67
        $open = $this->objFromFixture(Job::class, 'open');
68
        $open->write();
69
        /** @var Job $future */
70
        $future = $this->objFromFixture(Job::class, 'future');
71
        $future->write();
72
73
        DBDatetime::set_mock_now('2017-11-15');
74
        $jobCount = $holder->getPostedJobs()->count();
75
        $this->assertEquals(1, $jobCount);
76
77
        DBDatetime::set_mock_now('2017-11-29');
78
        $jobCount = $holder->getPostedJobs()->count();
79
        $this->assertEquals(2, $jobCount);
80
81
        DBDatetime::set_mock_now('2017-12-15');
82
        $jobCount = $holder->getPostedJobs()->count();
83
        $this->assertEquals(0, $jobCount);
84
    }
85
}
86