3
* Spring Signage Ltd - http://www.springsignage.com
4
* Copyright (C) 2015 Spring Signage Ltd
5
* (DataSetViewWidgetTest.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;
19
class DataSetViewWidgetTest extends LocalWebTestCase
22
protected $startLayouts;
23
protected $startDataSets;
26
* setUp - called before every test automatically
28
public function setup()
31
$this->startLayouts = (new XiboLayout($this->getEntityProvider()))->get(['start' => 0, 'length' => 10000]);
32
$this->startDataSets = (new XiboDataSet($this->getEntityProvider()))->get(['start' => 0, 'length' => 10000]);
36
* tearDown - called after every test automatically
38
public function tearDown()
40
// tearDown all layouts that weren't there initially
41
$finalLayouts = (new XiboLayout($this->getEntityProvider()))->get(['start' => 0, 'length' => 10000]);
42
# Loop over any remaining layouts and nuke them
43
foreach ($finalLayouts as $layout) {
44
/** @var XiboLayout $layout */
46
foreach ($this->startLayouts as $startLayout) {
47
if ($startLayout->layoutId == $layout->layoutId) {
54
} catch (\Exception $e) {
55
fwrite(STDERR, 'Unable to delete ' . $layout->layoutId . '. E:' . $e->getMessage());
59
// tearDown all datasets that weren't there initially
60
$finalDataSets = (new XiboDataSet($this->getEntityProvider()))->get(['start' => 0, 'length' => 10000]);
62
$difference = array_udiff($finalDataSets, $this->startDataSets, function ($a, $b) {
63
/** @var XiboDataSet $a */
64
/** @var XiboDataSet $b */
65
return $a->dataSetId - $b->dataSetId;
68
# Loop over any remaining datasets and nuke them
69
foreach ($difference as $dataSet) {
70
/** @var XiboDataSet $dataSet */
72
$dataSet->deleteWData();
73
} catch (\Exception $e) {
74
fwrite(STDERR, 'Unable to delete ' . $dataSet->dataSetId . '. E: ' . $e->getMessage() . PHP_EOL);
80
public function testAdd()
83
$layout = (new XiboLayout($this->getEntityProvider()))->create('DataSetView add', 'phpunit description', '', 9);
84
# Add region to our layout
85
$region = (new XiboRegion($this->getEntityProvider()))->create($layout->layoutId, 1000,1000,200,200);
86
# Create a new dataset
87
$dataSet = (new XiboDataSet($this->getEntityProvider()))->create('phpunit dataset', 'phpunit description');
89
$response = $this->client->post('/playlist/widget/dataSetView/' . $region->playlists[0]['playlistId'], [
90
'name' => 'API dataSetView',
91
'dataSetId' => $dataSet->dataSetId
94
$this->assertSame(200, $this->client->response->status(), "Not successful: " . $response);
95
$object = json_decode($this->client->response->body());
96
$this->assertObjectHasAttribute('data', $object);
97
$widgetOptions = (new XiboDataSetView($this->getEntityProvider()))->getById($region->playlists[0]['playlistId']);
98
$this->assertSame('API dataSetView', $widgetOptions->name);
99
$this->assertSame(60, $widgetOptions->duration);
102
public function testEdit()
105
$layout = (new XiboLayout($this->getEntityProvider()))->create('DataSetView edit', 'phpunit description', '', 9);
106
# Add region to our layout
107
$region = (new XiboRegion($this->getEntityProvider()))->create($layout->layoutId, 1000,1000,200,200);
108
# Create a new dataset
109
$dataSet = (new XiboDataSet($this->getEntityProvider()))->create('phpunit dataset', 'phpunit description');
110
# Create dataSetView widget
111
$dataSetView = (new XiboDataSetView($this->getEntityProvider()))->create('API dataSetView', $dataSet->dataSetId, $region->playlists[0]['playlistId']);
112
$nameCol = Random::generateString(8, 'phpunit');
113
$nameCol2 = Random::generateString(8, 'phpunit');
114
$column = (new XiboDataSetColumn($this->getEntityProvider()))->create($dataSet->dataSetId, $nameCol,'', 2, 1, 1, '');
115
$column2 = (new XiboDataSetColumn($this->getEntityProvider()))->create($dataSet->dataSetId, $nameCol2,'', 2, 1, 1, '');
116
$nameNew = 'Edited Name';
118
$response = $this->client->put('/playlist/widget/' . $dataSetView->widgetId, [
119
'dataSetColumnId' => [$column->dataSetColumnId, $column2->dataSetColumnId],
121
'duration' => $durationNew,
122
'updateInterval' => 100,
129
'templateId' => 'light-green',
130
'overrideTemplate' => 0,
131
'useOrderingClause' => 0,
132
'useFilteringClause' => 0,
133
'noDataMessage' => 'No Data returned',
134
], ['CONTENT_TYPE' => 'application/x-www-form-urlencoded']);
135
$this->assertSame(200, $this->client->response->status());
136
$this->assertNotEmpty($this->client->response->body());
137
$object = json_decode($this->client->response->body());
138
$this->assertObjectHasAttribute('data', $object, $this->client->response->body());
139
$widgetOptions = (new XiboDataSetView($this->getEntityProvider()))->getById($region->playlists[0]['playlistId']);
140
$this->assertSame($nameNew, $widgetOptions->name);
141
$this->assertSame($durationNew, $widgetOptions->duration);
142
foreach ($widgetOptions->widgetOptions as $option) {
143
if ($option['option'] == 'templateId') {
144
$this->assertSame('light-green', $option['value']);
146
if ($option['option'] == 'updateInterval') {
147
$this->assertSame(100, intval($option['value']));
152
public function testDelete()
155
$layout = (new XiboLayout($this->getEntityProvider()))->create('DataSetView delete Layout', 'phpunit description', '', 9);
156
# Add region to our layout
157
$region = (new XiboRegion($this->getEntityProvider()))->create($layout->layoutId, 1000,1000,200,200);
158
# Create a new dataset
159
$dataSet = (new XiboDataSet($this->getEntityProvider()))->create('phpunit dataset', 'phpunit description');
160
# Create dataSetView widget
161
$dataSetView = (new XiboDataSetView($this->getEntityProvider()))->create('API dataSetView', $dataSet->dataSetId, $region->playlists[0]['playlistId']);
163
$this->client->delete('/playlist/widget/' . $dataSetView->widgetId);
164
$response = json_decode($this->client->response->body());
165
$this->assertSame(200, $response->status, $this->client->response->body());