3
* Spring Signage Ltd - http://www.springsignage.com
4
* Copyright (C) 2015 Spring Signage Ltd
5
* (DataSetViewWidgetTestCase.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\XiboDataSet;
14
use Xibo\OAuth2\Client\Entity\XiboDataSetColumn;
15
use Xibo\OAuth2\Client\Entity\XiboDataSetView;
16
use Xibo\OAuth2\Client\Entity\XiboWidget;
17
use Xibo\Tests\LocalWebTestCase;
18
use Xibo\Tests\Integration\Widget\WidgetTestCase;
20
class DataSetViewWidgetTestCase extends WidgetTestCase
23
protected $startLayouts;
24
protected $startDataSets;
27
* setUp - called before every test automatically
29
public function setup()
32
$this->startLayouts = (new XiboLayout($this->getEntityProvider()))->get(['start' => 0, 'length' => 10000]);
33
$this->startDataSets = (new XiboDataSet($this->getEntityProvider()))->get(['start' => 0, 'length' => 10000]);
37
* tearDown - called after every test automatically
39
public function tearDown()
41
// tearDown all layouts that weren't there initially
42
$finalLayouts = (new XiboLayout($this->getEntityProvider()))->get(['start' => 0, 'length' => 10000]);
43
# Loop over any remaining layouts and nuke them
44
foreach ($finalLayouts as $layout) {
45
/** @var XiboLayout $layout */
47
foreach ($this->startLayouts as $startLayout) {
48
if ($startLayout->layoutId == $layout->layoutId) {
55
} catch (\Exception $e) {
56
fwrite(STDERR, 'Unable to delete ' . $layout->layoutId . '. E:' . $e->getMessage());
60
// tearDown all datasets that weren't there initially
61
$finalDataSets = (new XiboDataSet($this->getEntityProvider()))->get(['start' => 0, 'length' => 10000]);
63
$difference = array_udiff($finalDataSets, $this->startDataSets, function ($a, $b) {
64
/** @var XiboDataSet $a */
65
/** @var XiboDataSet $b */
66
return $a->dataSetId - $b->dataSetId;
69
# Loop over any remaining datasets and nuke them
70
foreach ($difference as $dataSet) {
71
/** @var XiboDataSet $dataSet */
73
$dataSet->deleteWData();
74
} catch (\Exception $e) {
75
fwrite(STDERR, 'Unable to delete ' . $dataSet->dataSetId . '. E: ' . $e->getMessage() . PHP_EOL);
81
public function testAdd()
84
$layout = (new XiboLayout($this->getEntityProvider()))->create('DataSetView add', 'phpunit description', '', 9);
85
# Add region to our layout
86
$region = (new XiboRegion($this->getEntityProvider()))->create($layout->layoutId, 1000,1000,200,200);
87
# Create a new dataset
88
$dataSet = (new XiboDataSet($this->getEntityProvider()))->create('phpunit dataset', 'phpunit description');
90
$response = $this->client->post('/playlist/widget/dataSetView/' . $region->playlists[0]['playlistId'], [
91
'name' => 'API dataSetView',
92
'dataSetId' => $dataSet->dataSetId
95
$this->assertSame(200, $this->client->response->status(), "Not successful: " . $response);
96
$object = json_decode($this->client->response->body());
97
$this->assertObjectHasAttribute('data', $object);
98
$widgetOptions = (new XiboDataSetView($this->getEntityProvider()))->getById($region->playlists[0]['playlistId']);
99
$this->assertSame('API dataSetView', $widgetOptions->name);
100
$this->assertSame(60, $widgetOptions->duration);
103
public function testEdit()
106
$layout = (new XiboLayout($this->getEntityProvider()))->create('DataSetView edit', 'phpunit description', '', 9);
107
# Add region to our layout
108
$region = (new XiboRegion($this->getEntityProvider()))->create($layout->layoutId, 1000,1000,200,200);
109
# Create a new dataset
110
$dataSet = (new XiboDataSet($this->getEntityProvider()))->create('phpunit dataset', 'phpunit description');
111
# Create dataSetView widget
112
$dataSetView = (new XiboDataSetView($this->getEntityProvider()))->create('API dataSetView', $dataSet->dataSetId, $region->playlists[0]['playlistId']);
113
$nameCol = Random::generateString(8, 'phpunit');
114
$nameCol2 = Random::generateString(8, 'phpunit');
115
$column = (new XiboDataSetColumn($this->getEntityProvider()))->create($dataSet->dataSetId, $nameCol,'', 2, 1, 1, '');
116
$column2 = (new XiboDataSetColumn($this->getEntityProvider()))->create($dataSet->dataSetId, $nameCol2,'', 2, 1, 1, '');
117
$nameNew = 'Edited Name';
119
$response = $this->client->put('/playlist/widget/' . $dataSetView->widgetId, [
120
'dataSetColumnId' => [$column->dataSetColumnId, $column2->dataSetColumnId],
122
'duration' => $durationNew,
123
'updateInterval' => 100,
130
'templateId' => 'light-green',
131
'overrideTemplate' => 0,
132
'useOrderingClause' => 0,
133
'useFilteringClause' => 0,
134
'noDataMessage' => 'No Data returned',
135
], ['CONTENT_TYPE' => 'application/x-www-form-urlencoded']);
136
$this->assertSame(200, $this->client->response->status());
137
$this->assertNotEmpty($this->client->response->body());
138
$object = json_decode($this->client->response->body());
139
$this->assertObjectHasAttribute('data', $object, $this->client->response->body());
140
$widgetOptions = (new XiboDataSetView($this->getEntityProvider()))->getById($region->playlists[0]['playlistId']);
141
$this->assertSame($nameNew, $widgetOptions->name);
142
$this->assertSame($durationNew, $widgetOptions->duration);
143
foreach ($widgetOptions->widgetOptions as $option) {
144
if ($option['option'] == 'templateId') {
145
$this->assertSame('light-green', $option['value']);
147
if ($option['option'] == 'updateInterval') {
148
$this->assertSame(100, intval($option['value']));
153
public function testDelete()
156
$layout = (new XiboLayout($this->getEntityProvider()))->create('DataSetView delete Layout', 'phpunit description', '', 9);
157
# Add region to our layout
158
$region = (new XiboRegion($this->getEntityProvider()))->create($layout->layoutId, 1000,1000,200,200);
159
# Create a new dataset
160
$dataSet = (new XiboDataSet($this->getEntityProvider()))->create('phpunit dataset', 'phpunit description');
161
# Create dataSetView widget
162
$dataSetView = (new XiboDataSetView($this->getEntityProvider()))->create('API dataSetView', $dataSet->dataSetId, $region->playlists[0]['playlistId']);
164
$this->client->delete('/playlist/widget/' . $dataSetView->widgetId);
165
$response = json_decode($this->client->response->body());
166
$this->assertSame(200, $response->status, $this->client->response->body());