3
* Spring Signage Ltd - http://www.springsignage.com
4
* Copyright (C) 2015 Spring Signage Ltd
5
* (WebpageWidgetTest.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\XiboWebpage;
14
use Xibo\OAuth2\Client\Entity\XiboWidget;
15
use Xibo\Tests\LocalWebTestCase;
17
class WebpageWidgetTest extends LocalWebTestCase
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, $transparency, $uri, $scaling, $offsetLeft, $offsetTop, $pageWidth, $pageHeight, $modeId)
64
$layout = (new XiboLayout($this->getEntityProvider()))->create('Webpage add', 'phpunit description', '', 9);
65
# Add region to our layout
66
$region = (new XiboRegion($this->getEntityProvider()))->create($layout->layoutId, 1000,1000,200,200);
68
$response = $this->client->post('/playlist/widget/webpage/' . $region->playlists[0]['playlistId'], [
70
'duration' => $duration,
71
'useDuration' => $useDuration,
72
'transparency' => $transparency,
74
'scaling' => $scaling,
75
'offsetLeft' => $offsetLeft,
76
'offsetTop' => $offsetTop,
77
'pageWidth' => $pageWidth,
78
'pageHeight' => $pageHeight,
81
$this->assertSame(200, $this->client->response->status());
82
$this->assertNotEmpty($this->client->response->body());
83
$object = json_decode($this->client->response->body());
84
$this->assertObjectHasAttribute('data', $object, $this->client->response->body());
85
$webpageOptions = (new XiboWebpage($this->getEntityProvider()))->getById($region->playlists[0]['playlistId']);
86
$this->assertSame($name, $webpageOptions->name);
87
$this->assertSame($duration, $webpageOptions->duration);
88
foreach ($webpageOptions->widgetOptions as $option) {
89
if ($option['option'] == 'uri') {
90
$this->assertSame($uri, urldecode($option['value']));
92
if ($option['option'] == 'modeId') {
93
$this->assertSame($modeId, intval($option['value']));
99
* Each array is a test run
100
* Format (($name, $duration, $useDuration, $transparency, $uri, $scaling, $offsetLeft, $offsetTop, $pageWidth, $pageHeight, $modeId)
103
public function provideSuccessCases()
105
# Sets of data used in testAdd
107
'Open natively' => ['Open natively webpage widget', 60, 1, NULL, 'http://xibo.org.uk/', NULL, NULL, NULL, NULL, NULL, 1],
108
'Manual Position default' => ['Manual Position default values', 10, 1, NULL, 'http://xibo.org.uk/', NULL, NULL, NULL, NULL, NULL, 2],
109
'Manual Position custom' => ['Manual Position custom values', 100, 1, 1, 'http://xibo.org.uk/', 100, 200, 100, 1600, 900, 2],
110
'Best Fit default' => ['Best Fit webpage widget', 10, 1, NULL, 'http://xibo.org.uk/', NULL, NULL, NULL, NULL, NULL, 3],
111
'Best Fit custom' => ['Best Fit webpage widget', 150, 1, NULL, 'http://xibo.org.uk/', NULL, NULL, 1920, 1080, NULL, 3],
115
public function testEdit()
118
$layout = (new XiboLayout($this->getEntityProvider()))->create('Webpage edit', 'phpunit description', '', 9);
119
# Add region to our layout
120
$region = (new XiboRegion($this->getEntityProvider()))->create($layout->layoutId, 1000,1000,200,200);
121
# Create a webpage with wrapper
122
$webpage = (new XiboWebpage($this->getEntityProvider()))->create('Open natively webpage widget', 60, 1, NULL, 'http://xibo.org.uk/', NULL, NULL, NULL, NULL, NULL, 1, $region->playlists[0]['playlistId']);
123
$nameNew = 'Edited Name';
126
$uriNew = 'http://xibo.org.uk/about/';
127
$response = $this->client->put('/playlist/widget/' . $webpage->widgetId, [
129
'duration' => $durationNew,
131
'transparency' => $webpage->transparency,
133
'scaling' => $webpage->scaling,
134
'offsetLeft' => $webpage->offsetLeft,
135
'offsetTop' => $webpage->offsetTop,
136
'pageWidth' => $webpage->pageWidth,
137
'pageHeight' => $webpage->pageHeight,
138
'modeId' => $modeIdNew
139
], ['CONTENT_TYPE' => 'application/x-www-form-urlencoded']);
140
$this->assertSame(200, $this->client->response->status());
141
$this->assertNotEmpty($this->client->response->body());
142
$object = json_decode($this->client->response->body());
143
$this->assertObjectHasAttribute('data', $object, $this->client->response->body());
144
$webpageOptions = (new XiboWebpage($this->getEntityProvider()))->getById($region->playlists[0]['playlistId']);
145
$this->assertSame($nameNew, $webpageOptions->name);
146
$this->assertSame($durationNew, $webpageOptions->duration);
147
foreach ($webpageOptions->widgetOptions as $option) {
148
if ($option['option'] == 'uri') {
149
$this->assertSame($uriNew, urldecode($option['value']));
151
if ($option['option'] == 'modeId') {
152
$this->assertSame($modeIdNew, intval($option['value']));
157
public function testDelete()
160
$name = Random::generateString(8, 'phpunit');
161
$layout = (new XiboLayout($this->getEntityProvider()))->create($name, '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
$webpage = (new XiboWebpage($this->getEntityProvider()))->create('Open natively webpage widget', 60, 1, NULL, 'http://xibo.org.uk/', NULL, NULL, NULL, NULL, NULL, 1, $region->playlists[0]['playlistId']);
167
$this->client->delete('/playlist/widget/' . $webpage->widgetId);
168
# This should return 204 for success
169
$response = json_decode($this->client->response->body());
170
$this->assertSame(200, $response->status, $this->client->response->body());