3
* Spring Signage Ltd - http://www.springsignage.com
4
* Copyright (C) 2015 Spring Signage Ltd
5
* (ClockWidgetTestCase.php)
8
namespace Xibo\Tests\Integration\Widget;
10
use Xibo\Helper\Random;
11
use Xibo\OAuth2\Client\Entity\XiboLayout;
12
use Xibo\OAuth2\Client\Entity\XiboRegion;
13
use Xibo\OAuth2\Client\Entity\XiboClock;
14
use Xibo\OAuth2\Client\Entity\XiboWidget;
15
use Xibo\Tests\LocalWebTestCase;
16
use Xibo\Tests\Integration\Widget\WidgetTestCase;
18
class ClockWidgetTestCase extends WidgetTestCase
20
protected $startLayouts;
22
* setUp - called before every test automatically
24
public function setup()
27
$this->startLayouts = (new XiboLayout($this->getEntityProvider()))->get(['start' => 0, 'length' => 10000]);
30
* tearDown - called after every test automatically
32
public function tearDown()
34
// tearDown all layouts that weren't there initially
35
$finalLayouts = (new XiboLayout($this->getEntityProvider()))->get(['start' => 0, 'length' => 10000]);
36
# Loop over any remaining layouts and nuke them
37
foreach ($finalLayouts as $layout) {
38
/** @var XiboLayout $layout */
40
foreach ($this->startLayouts as $startLayout) {
41
if ($startLayout->layoutId == $layout->layoutId) {
48
} catch (\Exception $e) {
49
fwrite(STDERR, 'Unable to delete ' . $layout->layoutId . '. E:' . $e->getMessage());
58
* @dataProvider provideSuccessCases
60
public function testAdd($name, $duration, $useDuration, $theme, $clockTypeId, $offset, $format, $showSeconds, $clockFace)
63
$layout = (new XiboLayout($this->getEntityProvider()))->create('Clock add Layout', 'phpunit description', '', 9);
64
# Add region to our layout
65
$region = (new XiboRegion($this->getEntityProvider()))->create($layout->layoutId, 1000,1000,200,200);
67
$response = $this->client->post('/playlist/widget/clock/' . $region->playlists[0]['playlistId'], [
69
'duration' => $duration,
70
'useDuration' => $useDuration,
72
'clockTypeId' => $clockTypeId,
75
'showSeconds' => $showSeconds,
76
'clockFace' => $clockFace
78
$this->assertSame(200, $this->client->response->status());
79
$this->assertNotEmpty($this->client->response->body());
80
$object = json_decode($this->client->response->body());
81
$this->assertObjectHasAttribute('data', $object, $this->client->response->body());
82
$clockOptions = (new XiboClock($this->getEntityProvider()))->getById($region->playlists[0]['playlistId']);
83
$this->assertSame($name, $clockOptions->name);
84
$this->assertSame($duration, $clockOptions->duration);
86
foreach ($clockOptions->widgetOptions as $option) {
87
if ($option['option'] == 'theme') {
88
$this->assertSame($theme, intval($option['value']));
90
if ($option['option'] == 'clockTypeId') {
91
$this->assertSame($clockTypeId, intval($option['value']));
93
if ($option['option'] == 'offset') {
94
$this->assertSame($offset, intval($option['value']));
96
if ($option['option'] == 'format') {
97
$this->assertSame($format, $option['value']);
99
if ($option['option'] == 'showSeconds') {
100
$this->assertSame($showSeconds, intval($option['value']));
102
if ($option['option'] == 'clockFace') {
103
$this->assertSame($clockFace, $option['value']);
109
* Each array is a test run
110
* Format ($name, $duration, $useDuration, $theme, $clockTypeId, $offset, $format, $showSeconds, $clockFace)
113
public function provideSuccessCases()
115
# Sets of data used in testAdd
117
'Analogue' => ['Api Analogue clock', 20, 1, 1, 1, 0, '', 0, 'TwentyFourHourClock'],
118
'Digital' => ['API digital clock', 20, 1, 0, 2, 0, '[HH:mm]', 0, 'TwentyFourHourClock'],
119
'Flip 24h' => ['API Flip clock 24h', 5, 1, 0, 3, 0, '', 1, 'TwentyFourHourClock'],
120
'Flip counter' => ['API Flip clock Minute counter', 50, 1, 0, 3, 0, '', 1, 'MinuteCounter']
124
public function testEdit()
127
$layout = (new XiboLayout($this->getEntityProvider()))->create('Clock edit Layout', 'phpunit description', '', 9);
128
# Add region to our layout
129
$region = (new XiboRegion($this->getEntityProvider()))->create($layout->layoutId, 1000,1000,200,200);
130
# Create a clock with wrapper
131
$clock = (new XiboClock($this->getEntityProvider()))->create('Api Analogue clock', 20, 1, 1, 1, NULL, NULL, NULL, NULL, $region->playlists[0]['playlistId']);
132
$nameNew = 'Edited Name';
135
$response = $this->client->put('/playlist/widget/' . $clock->widgetId, [
137
'duration' => $durationNew,
138
'themeId' => $clock->theme,
139
'clockTypeId' => $clockTypeIdNew,
140
'offset' => $clock->offset,
141
'format' => $clock->format,
142
'showSeconds' => $clock->showSeconds,
143
'clockFace' => $clock->clockFace
144
], ['CONTENT_TYPE' => 'application/x-www-form-urlencoded']);
145
$this->assertSame(200, $this->client->response->status());
146
$this->assertNotEmpty($this->client->response->body());
147
$object = json_decode($this->client->response->body());
148
$this->assertObjectHasAttribute('data', $object, $this->client->response->body());
149
$clockOptions = (new XiboClock($this->getEntityProvider()))->getById($region->playlists[0]['playlistId']);
150
$this->assertSame($nameNew, $clockOptions->name);
151
$this->assertSame($durationNew, $clockOptions->duration);
152
foreach ($clockOptions->widgetOptions as $option) {
153
if ($option['option'] == 'clockTypeId') {
154
$this->assertSame($clockTypeIdNew, intval($option['value']));
158
public function testDelete()
161
$layout = (new XiboLayout($this->getEntityProvider()))->create('Clock delete Layout', 'phpunit description', '', 9);
162
# Add region to our layout
163
$region = (new XiboRegion($this->getEntityProvider()))->create($layout->layoutId, 1000,1000,200,200);
164
# Create a clock with wrapper
165
$clock = (new XiboClock($this->getEntityProvider()))->create('Api Analogue clock', 20, 1, 1, 1, NULL, NULL, NULL, NULL, $region->playlists[0]['playlistId']);
167
$this->client->delete('/playlist/widget/' . $clock->widgetId);
168
$response = json_decode($this->client->response->body());
169
$this->assertSame(200, $response->status, $this->client->response->body());