TaskManager_ModelTest::testGetStatus()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 5

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 14
rs 9.4285
cc 1
eloc 5
nc 1
nop 2
1
<?php
2
3
namespace Craft;
4
5
/**
6
 * TaskManager Model Test.
7
 *
8
 * Asserts for the TaskManagerModel class
9
 *
10
 * @author    Bob Olde Hampsink <[email protected]>
11
 * @copyright Copyright (c) 2015, Bob Olde Hampsink
12
 * @license   MIT
13
 *
14
 * @link      http://github.com/boboldehampsink
15
 *
16
 * @coversDefaultClass Craft\TaskManagerModel
17
 * @covers ::<!public>
18
 */
19
class TaskManager_ModelTest extends BaseTest
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public static function setUpBeforeClass()
25
    {
26
        parent::setUpBeforeClass();
27
        require_once __DIR__ . '/../models/TaskManagerModel.php';
28
    }
29
30
    /**
31
     * Test getTitle.
32
     *
33
     * @covers ::getTitle
34
     */
35
    final public function testGetTitle()
36
    {
37
        // Mock localization service
38
        $this->setMockLocalizationService();
39
40
        // Set up model
41
        $model = new TaskManagerModel();
42
43
        // Set description attribute
44
        $model->description = 'test';
45
46
        // Assert title/description
47
        $this->assertSame($model->getTitle(), $model->description);
48
    }
49
50
    /**
51
     * Test getStatus.
52
     *
53
     * @covers ::getStatus
54
     * @dataProvider provideStatuses
55
     */
56
    final public function testGetStatus($taskStatus, $elementStatus)
57
    {
58
        // Mock localization service
59
        $this->setMockLocalizationService();
60
61
        // Set up model
62
        $model = new TaskManagerModel();
63
64
        // Set status attribute
65
        $model->status = $taskStatus;
66
67
        // Assert element status
68
        $this->assertSame($model->getStatus(), $elementStatus);
69
    }
70
71
    /**
72
     * Mock localization service.
73
     *
74
     * @return LocalizationService
75
     */
76
    private function setMockLocalizationService()
77
    {
78
        $mock = $this->getMockBuilder('Craft\LocalizationService')
79
                    ->disableOriginalConstructor()
80
                    ->getMock();
81
82
        $this->setComponent(craft(), 'i18n', $mock);
83
    }
84
85
    /**
86
     * Provide statuses.
87
     *
88
     * @return array
89
     */
90
    final public function provideStatuses()
91
    {
92
        return array(
93
            'Pending' => array(TaskStatus::Pending, EntryModel::PENDING),
94
            'Error'   => array(TaskStatus::Error, EntryModel::EXPIRED),
95
            'Running' => array(TaskStatus::Running, EntryModel::LIVE),
96
            'Unknown' => array('unknown', EntryModel::DISABLED),
97
        );
98
    }
99
}
100