3
* Spring Signage Ltd - http://www.springsignage.com
4
* Copyright (C) 2015 Spring Signage Ltd
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\XiboText;
14
use Xibo\OAuth2\Client\Entity\XiboWidget;
15
use Xibo\Tests\LocalWebTestCase;
17
class TextWidgetTest extends LocalWebTestCase
19
protected $startLayouts;
21
* setUp - called before every test automatically
23
public function setup()
26
$this->startLayouts = (new XiboLayout($this->getEntityProvider()))->get(['start' => 0, 'length' => 10000]);
29
* tearDown - called after every test automatically
31
public function tearDown()
33
// tearDown all layouts that weren't there initially
34
$finalLayouts = (new XiboLayout($this->getEntityProvider()))->get(['start' => 0, 'length' => 10000]);
35
# Loop over any remaining layouts and nuke them
36
foreach ($finalLayouts as $layout) {
37
/** @var XiboLayout $layout */
39
foreach ($this->startLayouts as $startLayout) {
40
if ($startLayout->layoutId == $layout->layoutId) {
47
} catch (\Exception $e) {
48
fwrite(STDERR, 'Unable to delete ' . $layout->layoutId . '. E:' . $e->getMessage());
56
* @dataProvider provideSuccessCases
58
public function testAdd($name, $duration, $useDuration, $effect, $speed, $backgroundColor, $marqueeInlineSelector, $text, $javaScript)
62
$layout = (new XiboLayout($this->getEntityProvider()))->create('Text add Layout', 'phpunit description', '', 9);
63
# Add region to our layout
64
$region = (new XiboRegion($this->getEntityProvider()))->create($layout->layoutId, 1000,1000,200,200);
66
$response = $this->client->post('/playlist/widget/text/' . $region->playlists[0]['playlistId'], [
68
'duration' => $duration,
69
'useDuration' => $useDuration,
72
'backgroundColor' => $backgroundColor,
73
'marqueeInlineSelector' => $marqueeInlineSelector,
75
'javaScript' => $javaScript
77
$this->assertSame(200, $this->client->response->status());
78
$this->assertNotEmpty($this->client->response->body());
79
$object = json_decode($this->client->response->body());
80
$this->assertObjectHasAttribute('data', $object, $this->client->response->body());
81
$textOptions = (new XiboText($this->getEntityProvider()))->getById($region->playlists[0]['playlistId']);
82
$this->assertSame($name, $textOptions->name);
83
$this->assertSame($duration, $textOptions->duration);
84
foreach ($textOptions->widgetOptions as $option) {
85
if ($option['option'] == 'effect') {
86
$this->assertSame($effect, $option['value']);
88
if ($option['option'] == 'speed') {
89
$this->assertSame($speed, intval($option['value']));
91
if ($option['option'] == 'text') {
92
$this->assertSame($text, $option['value']);
98
* Each array is a test run
99
* Format ($name, $duration, $useDuration, $effect, $speed, $backgroundColor, $marqueeInlineSelector, $text, $javaScript)
102
public function provideSuccessCases()
104
# Sets of data used in testAdd
106
'text 1' => ['Text item', 10, 1, 'marqueeRight', 5, null, null, 'TEST API TEXT', null],
107
'text with formatting' => ['Text item 2', 20, 1, 'marqueeLeft', 3, null, null, '<p><span style=color:#FFFFFF;><span style=font-size:48px;>TEST</span></span></p>', null],
108
'text with background Colour' => ['text item 3', 5, 1, null, 0, '#d900000', null, 'red background', null]
111
public function testEdit()
114
$layout = (new XiboLayout($this->getEntityProvider()))->create('Text edit Layout', 'phpunit description', '', 9);
115
# Add region to our layout
116
$region = (new XiboRegion($this->getEntityProvider()))->create($layout->layoutId, 1000,1000,200,200);
117
# Create a text widget with wrapper
118
$text = (new XiboText($this->getEntityProvider()))->create('Text item', 10, 1, 'marqueeRight', 5, null, null, 'TEST API TEXT', null, $region->playlists[0]['playlistId']);
119
$nameNew = 'Edited Name';
121
$textNew = 'Edited Text';
122
$response = $this->client->put('/playlist/widget/' . $text->widgetId, [
124
'duration' => $durationNew,
126
'effect' => $text->effect,
127
'speed' => $text->speed,
128
'backgroundColor' => null,
129
'marqueeInlineSelector' => null,
132
], ['CONTENT_TYPE' => 'application/x-www-form-urlencoded']);
133
$this->assertSame(200, $this->client->response->status());
134
$this->assertNotEmpty($this->client->response->body());
135
$object = json_decode($this->client->response->body());
136
$this->assertObjectHasAttribute('data', $object, $this->client->response->body());
137
$textOptions = (new XiboText($this->getEntityProvider()))->getById($region->playlists[0]['playlistId']);
138
$this->assertSame($nameNew, $textOptions->name);
139
$this->assertSame($durationNew, $textOptions->duration);
140
foreach ($textOptions->widgetOptions as $option) {
141
if ($option['option'] == 'text') {
142
$this->assertSame($textNew, $option['value']);
147
public function testDelete()
150
$layout = (new XiboLayout($this->getEntityProvider()))->create('text delete Layout', 'phpunit description', '', 9);
151
# Add region to our layout
152
$region = (new XiboRegion($this->getEntityProvider()))->create($layout->layoutId, 1000,1000,200,200);
153
# Create a text widget with wrapper
154
$text = (new XiboText($this->getEntityProvider()))->create('Text item', 10, 1, 'marqueeRight', 5, null, null, 'TEST API TEXT', null, $region->playlists[0]['playlistId']);
156
$this->client->delete('/playlist/widget/' . $text->widgetId);
157
$response = json_decode($this->client->response->body());
158
$this->assertSame(200, $response->status, $this->client->response->body());