3
* Spring Signage Ltd - http://www.springsignage.com
4
* Copyright (C) 2015 Spring Signage Ltd
5
* (DisplayGroupTest.php)
8
namespace Xibo\Tests\Integration;
10
use Xibo\Helper\Random;
11
use Xibo\OAuth2\Client\Entity\XiboCommand;
12
use Xibo\OAuth2\Client\Entity\XiboDisplay;
13
use Xibo\OAuth2\Client\Entity\XiboDisplayGroup;
14
use Xibo\OAuth2\Client\Entity\XiboLayout;
15
use Xibo\OAuth2\Client\Entity\XiboLibrary;
16
use Xibo\Tests\LocalWebTestCase;
19
* Class DisplayGroupTest
20
* @package Xibo\Tests\Integration
22
class DisplayGroupTest extends LocalWebTestCase
24
protected $startDisplayGroups;
25
protected $startDisplays;
28
* setUp - called before every test automatically
30
public function setup()
33
$this->startDisplayGroups = (new XiboDisplayGroup($this->getEntityProvider()))->get(['start' => 0, 'length' => 10000]);
34
$this->startDisplays = (new XiboDisplay($this->getEntityProvider()))->get(['start' => 0, 'length' => 10000]);
35
$this->startLayouts = (new XiboLayout($this->getEntityProvider()))->get(['start' => 0, 'length' => 10000]);
36
$this->startCommands = (new XiboCommand($this->getEntityProvider()))->get(['start' => 0, 'length' => 10000]);
40
* tearDown - called after every test automatically
42
public function tearDown()
44
// tearDown all display groups that weren't there initially
45
$finalDisplayGroups = (new XiboDisplayGroup($this->getEntityProvider()))->get(['start' => 0, 'length' => 10000]);
47
# Loop over any remaining display groups and nuke them
48
foreach ($finalDisplayGroups as $displayGroup) {
49
/** @var XiboDisplayGroup $displayGroup */
53
foreach ($this->startDisplayGroups as $startGroup) {
54
if ($startGroup->displayGroupId == $displayGroup->displayGroupId) {
61
$displayGroup->delete();
62
} catch (\Exception $e) {
63
fwrite(STDERR, 'Unable to delete ' . $displayGroup->displayGroupId . '. E:' . $e->getMessage());
68
// Tear down any displays that weren't there before
69
$finalDisplays = (new XiboDisplay($this->getEntityProvider()))->get();
71
# Loop over any remaining displays and nuke them
72
foreach ($finalDisplays as $display) {
73
/** @var XiboDisplay $display */
77
foreach ($this->startDisplays as $startDisplay) {
78
if ($startDisplay->displayId == $display->displayId) {
86
} catch (\Exception $e) {
87
fwrite(STDERR, 'Unable to delete ' . $display->displayId . '. E:' . $e->getMessage());
92
// tearDown all layouts that weren't there initially
93
$finalLayouts = (new XiboLayout($this->getEntityProvider()))->get(['start' => 0, 'length' => 10000]);
94
# Loop over any remaining layouts and nuke them
95
foreach ($finalLayouts as $layout) {
96
/** @var XiboLayout $layout */
98
foreach ($this->startLayouts as $startLayout) {
99
if ($startLayout->layoutId == $layout->layoutId) {
106
} catch (\Exception $e) {
107
fwrite(STDERR, 'Unable to delete ' . $layout->layoutId . '. E:' . $e->getMessage());
112
// tearDown all commands that weren't there initially
113
$finalCommands = (new XiboCommand($this->getEntityProvider()))->get(['start' => 0, 'length' => 10000]);
114
# Loop over any remaining commands and nuke them
115
foreach ($finalCommands as $command) {
116
/** @var XiboCommand $command */
118
foreach ($this->startCommands as $startCom) {
119
if ($startCom->commandId == $command->commandId) {
126
} catch (\Exception $e) {
127
fwrite(STDERR, 'Unable to delete ' . $command->commandId . '. E:' . $e->getMessage());
136
* List all display groups known empty
140
public function testListEmpty()
142
if (count($this->startDisplayGroups) > 0) {
143
$this->skipTest("There are pre-existing DisplayGroups");
146
$this->client->get('/displaygroup');
147
$this->assertSame(200, $this->client->response->status());
148
$this->assertNotEmpty($this->client->response->body());
149
$object = json_decode($this->client->response->body());
150
$this->assertObjectHasAttribute('data', $object, $this->client->response->body());
151
# There should be no DisplayGroups in the system
152
$this->assertEquals(0, $object->data->recordsTotal);
156
* testAddSuccess - test adding various Display Groups that should be valid
157
* @dataProvider provideSuccessCases
160
public function testAddSuccess($groupName, $groupDescription, $isDynamic, $expectedDynamic, $dynamicCriteria, $expectedDynamicCriteria)
162
// Loop through any pre-existing DisplayGroups to make sure we're not
163
// going to get a clash
165
foreach ($this->startDisplayGroups as $tmpGroup) {
166
if ($tmpGroup->displayGroup == $groupName) {
167
$this->skipTest("There is a pre-existing DisplayGroup with this name");
172
$response = $this->client->post('/displaygroup', [
173
'displayGroup' => $groupName,
174
'description' => $groupDescription,
175
'isDynamic' => $isDynamic,
176
'dynamicCriteria' => $dynamicCriteria
179
$this->assertSame(200, $this->client->response->status(), "Not successful: " . $response);
181
$object = json_decode($this->client->response->body());
182
$this->assertObjectHasAttribute('data', $object);
183
$this->assertObjectHasAttribute('id', $object);
184
$this->assertSame($groupName, $object->data->displayGroup);
185
$this->assertSame($groupDescription, $object->data->description);
186
$this->assertSame($expectedDynamic, $object->data->isDynamic);
187
$this->assertSame($expectedDynamicCriteria, $object->data->dynamicCriteria);
188
# Check that the group was really added
189
$displayGroups = (new XiboDisplayGroup($this->getEntityProvider()))->get(['length' => 1000]);
190
$this->assertEquals(count($this->startDisplayGroups) + 1, count($displayGroups));
191
# Check that the group was added correctly
192
$displayGroup = (new XiboDisplayGroup($this->getEntityProvider()))->getById($object->id);
193
$this->assertSame($groupName, $displayGroup->displayGroup);
194
$this->assertSame($groupDescription, $displayGroup->description);
195
$this->assertSame($expectedDynamic, $displayGroup->isDynamic);
196
$this->assertSame($expectedDynamicCriteria, $displayGroup->dynamicCriteria);
197
# Clean up the DisplayGroup as we no longer need it
198
$this->assertTrue($displayGroup->delete(), 'Unable to delete ' . $displayGroup->displayGroupId);
202
* testAddFailure - test adding various Display Groups that should be invalid
203
* @dataProvider provideFailureCases
206
public function testAddFailure($groupName, $groupDescription, $isDynamic, $dynamicCriteria)
208
$response = $this->client->post('/displaygroup', [
209
'displayGroup' => $groupName,
210
'description' => $groupDescription,
211
'isDynamic' => $isDynamic,
212
'dynamicCriteria' => $dynamicCriteria
215
$this->assertSame(500, $this->client->response->status(), 'Expecting failure, received ' . $this->client->response->status());
219
* List all display groups known set
221
* @depends testAddSuccess
223
public function testListKnown()
225
# Load in a known set of display groups
226
# We can assume this works since we depend upon the test which
227
# has previously added and removed these without issue:
228
$cases = $this->provideSuccessCases();
230
// Check each possible case to ensure it's not pre-existing
231
// If it is, skip over it
232
foreach ($cases as $case) {
235
foreach ($this->startDisplayGroups as $tmpGroup) {
236
if ($case[0] == $tmpGroup->displayGroup) {
242
$displayGroups[] = (new XiboDisplayGroup($this->getEntityProvider()))->create($case[0],$case[1],$case[2],$case[3]);
246
$this->client->get('/displaygroup');
247
$this->assertSame(200, $this->client->response->status());
248
$this->assertNotEmpty($this->client->response->body());
249
$object = json_decode($this->client->response->body());
250
$this->assertObjectHasAttribute('data', $object, $this->client->response->body());
251
# There should be as many groups as we created plus the number we started with in the system
252
$this->assertEquals(count($displayGroups) + count($this->startDisplayGroups), $object->data->recordsTotal);
253
# Clean up the groups we created
254
foreach ($displayGroups as $group) {
260
* List specific display groups
263
* @depends testListKnown
264
* @depends testAddSuccess
265
* @dataProvider provideSuccessCases
267
public function testListFilter($groupName, $groupDescription, $isDynamic, $expectedDynamic, $dynamicCriteria, $expectedDynamicCriteria)
269
if (count($this->startDisplayGroups) > 0) {
270
$this->skipTest("There are pre-existing DisplayGroups");
273
# Load in a known set of display groups
274
# We can assume this works since we depend upon the test which
275
# has previously added and removed these without issue:
276
$cases = $this->provideSuccessCases();
278
foreach ($cases as $case) {
279
$displayGroups[] = (new XiboDisplayGroup($this->getEntityProvider()))->create($case[0], $case[1], $case[2], $case[3]);
281
$this->client->get('/displaygroup', [
282
'displayGroup' => $groupName
285
$this->assertSame(200, $this->client->response->status());
286
$this->assertNotEmpty($this->client->response->body());
288
$object = json_decode($this->client->response->body());
289
$this->assertObjectHasAttribute('data', $object, $this->client->response->body());
290
# There should be at least one match
291
$this->assertGreaterThanOrEqual(1, $object->data->recordsTotal);
293
# Check that for the records returned, $groupName is in the groups names
294
foreach ($object->data->data as $group) {
295
if (strpos($groupName, $group->displayGroup) == 0) {
299
// The object we got wasn't the exact one we searched for
300
// Make sure all the words we searched for are in the result
301
foreach (array_map('trim',explode(",",$groupName)) as $word) {
302
assertTrue((strpos($word, $group->displayGroup) !== false), 'Group returned did not match the query string: ' . $group->displayGroup);
307
$this->assertTrue($flag, 'Search term not found');
309
foreach ($displayGroups as $group) {
316
* Each array is a test run
318
* (Group Name, Group Description, isDynamic, Returned isDynamic (0 or 1),
319
* Criteria for Dynamic group, Returned Criteria for Dynamic group)
320
* For example, if you set isDynamic to 0 and send criteria, it will come back
321
* with criteria = null
322
* These are reused in other tests so please ensure Group Name is unique
323
* through the dataset
326
public function provideSuccessCases()
330
// Multi-language non-dynamic groups
331
'English 1' => ['phpunit test group', 'Api', 0, 0, '', null],
332
'English 2' => ['another phpunit test group', 'Api', 0, 0, '', null],
333
'French 1' => ['Test de Français 1', 'Bienvenue à la suite de tests Xibo', 0, 0, null, null],
334
'German 1' => ['Deutsch Prüfung 1', 'Weiß mit schwarzem Text', 0, 0, null, null],
335
'Simplified Chinese 1' => ['试验组', '测试组描述', 0, 0, null, null],
336
// Multi-language dynamic groups
337
'English Dynamic 1' => ['phpunit test dynamic group', 'Api', 1, 1, 'test', 'test'],
338
'French Dynamic 1' => ['Test de Français 2', 'Bienvenue à la suite de tests Xibo', 1, 1, 'test', 'test'],
339
'German Dynamic 1' => ['Deutsch Prüfung 2', 'Weiß mit schwarzem Text', 1, 1, 'test', 'test'],
340
// Tests for the various allowed values for isDynamic = 1
341
'isDynamic on' => ['phpunit group dynamic is on', 'Api', 'on', 1, 'test', 'test'],
342
'isDynamic true' => ['phpunit group dynamic is true', 'Api', 'true', 1, 'test', 'test'],
343
// Invalid isDynamic flag (the CMS sanitises these for us to false)
344
'isDynamic is 7 null criteria' => ['Invalid isDynamic flag 1', 'Invalid isDynamic flag', 7, 0, null, null],
345
'isDynamic is 7 with criteria' => ['Invalid isDynamic flag 2 ', 'Invalid isDynamic flag', 7, 0, 'criteria', 'criteria'],
346
'isDynamic is invalid null criteria' => ['Invalid isDynamic flag alpha 1', 'Invalid isDynamic flag alpha', 'invalid', 0, null, null],
347
'isDynamic is invalid with criteria' => ['Invalid isDynamic flag alpha 2', 'Invalid isDynamic flag alpha', 'invalid', 0, 'criteria', 'criteria']
352
* Each array is a test run
354
* (Group Name, Group Description, isDynamic, Criteria for Dynamic group)
357
public function provideFailureCases()
361
// Description is limited to 255 characters
362
'Description over 254 characters' => ['Too long description', Random::generateString(255), 0, null],
363
// If isDynamic = 1 then criteria must be set
364
'No dynamicCriteria on dynamic group' => ['No dynamic criteria', 'No dynamic criteria', 1, null],
365
// Missing group names
366
'Group name empty' => ['', 'Group name is empty', 0, null],
367
'Group name null' => [null, 'Group name is null', 0, null]
372
* Try and add two display groups with the same name
374
* @depends testAddSuccess
376
public function testAddDuplicate()
379
foreach ($this->startDisplayGroups as $group) {
380
if ($group->displayGroup == 'phpunit displaygroup') {
385
# Load in a known display group if it's not there already
387
$displayGroup = (new XiboDisplayGroup($this->getEntityProvider()))->create('phpunit displaygroup', 'phpunit displaygroup', 0, '');
390
$response = $this->client->post('/displaygroup', [
391
'displayGroup' => 'phpunit displaygroup',
392
'description' => 'phpunit displaygroup',
394
'dynamicCriteria' => ''
397
$this->assertSame(500, $this->client->response->status(), 'Expecting failure, received ' . $this->client->response->status());
398
$displayGroup->delete();
402
* Edit an existing display group
403
* @depends testAddSuccess
406
public function testEdit()
408
foreach ($this->startDisplayGroups as $group) {
409
if ($group->displayGroup == 'phpunit displaygroup') {
410
$this->skipTest('displayGroup already exists with that name');
414
# Load in a known display group
415
/** @var XiboDisplayGroup $displayGroup */
416
$displayGroup = (new XiboDisplayGroup($this->getEntityProvider()))->create('phpunit displaygroup', 'phpunit displaygroup', 0, '');
417
# Change the group name and description
418
# Change it to a dynamic group with a fixed criteria
419
$name = Random::generateString(8, 'phpunit');
420
$description = Random::generateString(8, 'description');
423
$this->client->put('/displaygroup/' . $displayGroup->displayGroupId, [
424
'displayGroup' => $name,
425
'description' => $description,
427
'dynamicCriteria' => $criteria
428
], ['CONTENT_TYPE' => 'application/x-www-form-urlencoded']);
430
$this->assertSame(200, $this->client->response->status(), 'Not successful: ' . $this->client->response->body());
431
$object = json_decode($this->client->response->body());
432
# Examine the returned object and check that it's what we expect
433
$this->assertObjectHasAttribute('data', $object);
434
$this->assertObjectHasAttribute('id', $object);
435
$this->assertSame($name, $object->data->displayGroup);
436
$this->assertSame($description, $object->data->description);
437
$this->assertSame(1, $object->data->isDynamic);
438
$this->assertSame($criteria, $object->data->dynamicCriteria);
439
# Check that the group was actually renamed
440
$displayGroup = (new XiboDisplayGroup($this->getEntityProvider()))->getById($object->id);
441
$this->assertSame($name, $displayGroup->displayGroup);
442
$this->assertSame($description, $displayGroup->description);
443
$this->assertSame(1, $displayGroup->isDynamic);
444
$this->assertSame($criteria, $displayGroup->dynamicCriteria);
445
# Clean up the DisplayGroup as we no longer need it
446
$displayGroup->delete();
451
* @depends testAddSuccess
454
public function testDelete()
456
$name1 = Random::generateString(8, 'phpunit');
457
$name2 = Random::generateString(8, 'phpunit');
458
# Load in a couple of known display groups
459
$displayGroup1 = (new XiboDisplayGroup($this->getEntityProvider()))->create($name1, 'phpunit description', 0, '');
460
$displayGroup2 = (new XiboDisplayGroup($this->getEntityProvider()))->create($name2, 'phpunit description', 0, '');
461
# Delete the one we created last
462
$this->client->delete('/displaygroup/' . $displayGroup2->displayGroupId);
463
# This should return 204 for success
464
$response = json_decode($this->client->response->body());
465
$this->assertSame(204, $response->status, $this->client->response->body());
466
# Check only one remains
467
$groups = (new XiboDisplayGroup($this->getEntityProvider()))->get();
468
$this->assertEquals(count($this->startDisplayGroups) + 1, count($groups));
471
foreach ($groups as $group) {
472
if ($group->displayGroupId == $displayGroup1->displayGroupId) {
477
$this->assertTrue($flag, 'DisplayGroup ID ' . $displayGroup1->displayGroupId . ' was not found after deleting a different DisplayGroup');
479
$displayGroup1->delete();
483
* Assign new displays Test
486
public function testAssignDisplay()
488
# Create a Display in the system
489
$hardwareId = Random::generateString(12, 'phpunit');
490
$response = $this->getXmdsWrapper()->RegisterDisplay($hardwareId, 'PHPUnit Test Display');
491
# Now find the Id of that Display
492
$displays = (new XiboDisplay($this->getEntityProvider()))->get();
495
foreach ($displays as $disp) {
496
if ($disp->license == $hardwareId) {
501
if ($display === null) {
502
$this->fail('Display was not added correctly');
504
# Create a DisplayGroup to add the display to
505
$name = Random::generateString(8, 'phpunit');
506
$displayGroup = (new XiboDisplayGroup($this->getEntityProvider()))->create($name, 'phpunit description', 0, '');
507
# Call assign display to display group
508
$this->client->post('/displaygroup/' . $displayGroup->displayGroupId . '/display/assign', [
509
'displayId' => [$display->displayId]
511
$response = json_decode($this->client->response->body());
512
$this->assertSame(204, $response->status, $this->client->response->body());
513
# Get a list of all Displays in the group
514
$displays = (new XiboDisplay($this->getEntityProvider()))->get(['displayGroupId' => $displayGroup->displayGroupId]);
515
# Check that there's only us in that group
516
$this->assertEquals(1, count($displays));
517
$this->assertEquals($display->displayId, $displays[0]->displayId);
519
$displayGroup->delete();
524
* Try to assign display to isDisplaySpecific displayGroupId
527
public function testAssignDisplayFailure()
529
# Create a Display in the system
530
$hardwareId = Random::generateString(12, 'phpunit');
531
$response = $this->getXmdsWrapper()->RegisterDisplay($hardwareId, 'PHPUnit Test Display');
532
# Now find the Id of that Display
533
$displays = (new XiboDisplay($this->getEntityProvider()))->get();
536
foreach ($displays as $disp) {
537
if ($disp->license == $hardwareId) {
542
if ($display === null) {
543
$this->fail('Display was not added correctly');
545
# Create a DisplayGroup to add the display to
546
$name = Random::generateString(8, 'phpunit');
547
$displayGroup = (new XiboDisplayGroup($this->getEntityProvider()))->create($name, 'phpunit description', 0, '');
548
# Call assign display to display group
549
$this->client->post('/displaygroup/' . $display->displayGroupId . '/display/assign', [
550
'displayId' => [$display->displayId]
552
$this->assertSame(500, $this->client->response->status(), 'Expecting failure, received ' . $this->client->response->status());
556
* Unassign displays Test
558
public function testUnassignDisplay()
560
# Create a Display in the system
561
$hardwareId = Random::generateString(12, 'phpunit');
562
$response = $this->getXmdsWrapper()->RegisterDisplay($hardwareId, 'PHPUnit Test Display');
563
# Now find the Id of that Display
564
$displays = (new XiboDisplay($this->getEntityProvider()))->get();
567
foreach ($displays as $disp) {
568
if ($disp->license == $hardwareId) {
573
if ($display === null) {
574
$this->fail('Display was not added correctly');
577
# Create display group
578
$name = Random::generateString(8, 'phpunit');
579
$displayGroup = (new XiboDisplayGroup($this->getEntityProvider()))->create($name, 'phpunit description', 0, '');
580
# Assign display to display group
581
$displayGroup->assignDisplay([$display->displayId]);
582
# Unassign display from display group
583
$this->client->post('/displaygroup/' . $displayGroup->displayGroupId . '/display/unassign', [
584
'displayId' => [$display->displayId]
587
$this->assertSame(200, $this->client->response->status());
588
$object = json_decode($this->client->response->body());
589
$this->assertObjectHasAttribute('data', $object);
590
$this->assertObjectHasAttribute('id', $object);
592
$displayGroup->delete();
597
* Try to unassign display from isDisplaySpecific displayGroupId
599
public function testUnassignDisplayFailure()
601
# Create a Display in the system
602
$hardwareId = Random::generateString(12, 'phpunit');
603
$response = $this->getXmdsWrapper()->RegisterDisplay($hardwareId, 'PHPUnit Test Display');
604
# Now find the Id of that Display
605
$displays = (new XiboDisplay($this->getEntityProvider()))->get();
608
foreach ($displays as $disp) {
609
if ($disp->license == $hardwareId) {
614
if ($display === null) {
615
$this->fail('Display was not added correctly');
618
# Create display group
619
$name = Random::generateString(8, 'phpunit');
620
$displayGroup = (new XiboDisplayGroup($this->getEntityProvider()))->create($name, 'phpunit description', 0, '');
621
# Assign display to display group - should be successful
622
$displayGroup->assignDisplay([$display->displayId]);
623
# Unassign display from isDisplaySpecific display group - should fail
624
$this->client->post('/displaygroup/' . $display->displayGroupId . '/display/unassign', [
625
'displayId' => [$display->displayId]
627
$this->assertSame(500, $this->client->response->status(), 'Expecting failure, received ' . $this->client->response->status());
631
* Assign new display group Test
634
public function testAssignGroup()
636
# Generate new random names
637
$name = Random::generateString(8, 'phpunit');
638
$name2 = Random::generateString(8, 'phpunit');
639
# Create new display group
640
$displayGroup = (new XiboDisplayGroup($this->getEntityProvider()))->create($name, 'phpunit description', 0, '');
641
$displayGroup2 = (new XiboDisplayGroup($this->getEntityProvider()))->create($name2, 'phpunit description', 0, '');
642
# Assign second display group to the first one
643
$this->client->post('/displaygroup/' . $displayGroup->displayGroupId . '/displayGroup/assign', [
644
'displayGroupId' => [$displayGroup2->displayGroupId]
646
# Check if call was successful
647
$this->assertSame(200, $this->client->response->status());
648
$object = json_decode($this->client->response->body());
650
$displayGroup->delete();
651
$displayGroup2->delete();
655
* Unassign displays group Test
657
public function testUnassignGroup()
659
# Generate new random names
660
$name = Random::generateString(8, 'PARENT');
661
$name2 = Random::generateString(8, 'CHILD');
662
# Create new display groups
663
$displayGroup = (new XiboDisplayGroup($this->getEntityProvider()))->create($name, 'phpunit description', 0, '');
664
$displayGroup2 = (new XiboDisplayGroup($this->getEntityProvider()))->create($name2, 'phpunit description', 0, '');
665
# Assign second display group to the first one
667
$displayGroup->assignDisplayGroup([$displayGroup2->displayGroupId]);
668
# Unassign second display group from the first one
669
$this->client->post('/displaygroup/' . $displayGroup->displayGroupId . '/displayGroup/unassign', [
670
'displayGroupId' => [$displayGroup2->displayGroupId]
672
# Check if call was successful
673
$this->assertSame(200, $this->client->response->status());
674
$object = json_decode($this->client->response->body());
676
$displayGroup->delete();
677
$displayGroup2->delete();
681
* Assign new media file to a group Test
683
public function testAssignMedia()
685
# Generate new random name
686
$name = Random::generateString(8, 'phpunit');
687
# Create new display group
688
$displayGroup = (new XiboDisplayGroup($this->getEntityProvider()))->create($name, 'phpunit description', 0, '');
689
# Upload a known files
690
$media = (new XiboLibrary($this->getEntityProvider()))->create('API video 12', PROJECT_ROOT . '/tests/resources/HLH264.mp4');
691
$media2 = (new XiboLibrary($this->getEntityProvider()))->create('API image 12', PROJECT_ROOT . '/tests/resources/xts-night-001.jpg');
692
# Assign two files o the display group and unassign one of them
693
$this->client->post('/displaygroup/' . $displayGroup->displayGroupId . '/media/assign', [
694
'mediaId' => [$media->mediaId, $media2->mediaId],
695
'unassignMediaId' => [$media2->mediaId]
698
$this->assertSame(200, $this->client->response->status());
699
$object = json_decode($this->client->response->body());
701
$displayGroup->delete();
707
* Unassign media files from a group Test
709
public function testUnassignMedia()
711
# Generate new random name
712
$name = Random::generateString(8, 'phpunit');
713
# Create new display group
714
$displayGroup = (new XiboDisplayGroup($this->getEntityProvider()))->create($name, 'phpunit description', 0, '');
715
# Upload a known file
716
$media = (new XiboLibrary($this->getEntityProvider()))->create('API image 29', PROJECT_ROOT . '/tests/resources/xts-night-001.jpg');
717
# Assign media to display Group
718
$displayGroup->assignMedia([$media->mediaId]);
719
# Unassign the media from the display group
720
$this->client->post('/displaygroup/' . $displayGroup->displayGroupId . '/media/unassign', [
721
'mediaId' => [$media->mediaId]
724
$this->assertSame(200, $this->client->response->status());
725
$object = json_decode($this->client->response->body());
727
$displayGroup->delete();
732
* Assign new layouts to a group Test
734
public function testAssignLayout()
736
# Create new random name
737
$name = Random::generateString(8, 'phpunit');
738
# Create new display group
739
$displayGroup = (new XiboDisplayGroup($this->getEntityProvider()))->create($name, 'phpunit description', 0, '');
741
$layout = (new XiboLayout($this->getEntityProvider()))->create('test layout', 'test description', '', 9);
742
$layout2 = (new XiboLayout($this->getEntityProvider()))->create('test layout 2', 'test description 2', '', 9);
743
# Assign both layouts to display group then unassign the second layout from it
744
$this->client->post('/displaygroup/' . $displayGroup->displayGroupId . '/layout/assign', [
745
'layoutId' => [$layout->layoutId, $layout2->layoutId],
746
'unassignLayoutsId' => [$layout2->layoutId]
748
# Check if call was successful
749
$this->assertSame(200, $this->client->response->status());
750
$object = json_decode($this->client->response->body());
752
$displayGroup->delete();
758
* Unassign layouts from a group Test
760
public function testUnassignLayout()
762
# Create new random name
763
$name = Random::generateString(8, 'phpunit');
764
# Create new display group
765
$displayGroup = (new XiboDisplayGroup($this->getEntityProvider()))->create($name, 'phpunit description', 0, '');
767
$layout = (new XiboLayout($this->getEntityProvider()))->create('test layout', 'test description', '', 9);
768
# assign layout to display group
769
$displayGroup->assignLayout([$layout->layoutId]);
770
# unassign layout from display group
771
$this->client->post('/displaygroup/' . $displayGroup->displayGroupId . '/layout/unassign', [
772
'layoutId' => [$layout->layoutId]
775
$this->assertSame(200, $this->client->response->status());
776
$object = json_decode($this->client->response->body());
778
$displayGroup->delete();
783
* Assign apk version to a group
785
public function testVersion()
787
# Create new random name
788
$name = Random::generateString(8, 'phpunit');
789
# Create new display group
790
$displayGroup = (new XiboDisplayGroup($this->getEntityProvider()))->create($name, 'phpunit description', 0, '');
791
# Upload a known apk file
792
$media = (new XiboLibrary($this->getEntityProvider()))->create('API imagee', PROJECT_ROOT . '/tests/resources/Xibo_for_Android_v1.7_R61.apk');
793
# Asign apk to the display group
794
$this->client->post('/displaygroup/' . $displayGroup->displayGroupId . '/version', [
795
'mediaId' => $media->mediaId
798
$this->assertSame(200, $this->client->response->status());
799
$object = json_decode($this->client->response->body());
801
$displayGroup->delete();
806
* Collect now action test
808
public function testCollectNow()
810
# Generate random name
811
$name = Random::generateString(8, 'phpunit');
812
# Create new display group
813
$displayGroup = (new XiboDisplayGroup($this->getEntityProvider()))->create($name, 'phpunit description', 0, '');
815
$this->client->post('/displaygroup/' . $displayGroup->displayGroupId . '/action/collectNow');
816
# Check if call was successful
817
$this->assertSame(200, $this->client->response->status(), $this->client->response->body());
818
$object = json_decode($this->client->response->body());
820
$displayGroup->delete();
824
* Change Layout action test
826
public function testChangeLayout()
828
# Generate random name
829
$name = Random::generateString(8, 'phpunit');
830
# Create new display group
831
$displayGroup = (new XiboDisplayGroup($this->getEntityProvider()))->create($name, 'phpunit description', 0, '');
833
$layout = (new XiboLayout($this->getEntityProvider()))->create('test layout', 'test description', '', 9);
835
$this->client->post('/displaygroup/' . $displayGroup->displayGroupId . '/action/changeLayout', [
836
'layoutId' => $layout->layoutId,
838
'downloadRequired' => 1,
839
'changeMode' => 'queue'
841
# Check if successful
842
$this->assertSame(200, $this->client->response->status(), $this->client->response->body());
843
$object = json_decode($this->client->response->body());
845
$displayGroup->delete();
850
* Revert to Schedule action test
852
public function testRevertToSchedule()
854
# Generate random name and create new display group
855
$name = Random::generateString(8, 'phpunit');
856
$displayGroup = (new XiboDisplayGroup($this->getEntityProvider()))->create($name, 'phpunit description', 0, '');
857
# Call RevertToSchedule
858
$this->client->post('/displaygroup/' . $displayGroup->displayGroupId . '/action/revertToSchedule');
859
# Check if successful
860
$this->assertSame(200, $this->client->response->status(), $this->client->response->body());
861
$object = json_decode($this->client->response->body());
863
$displayGroup->delete();
867
* Send command action test
869
public function testCommand()
871
# Generate random name and create new display group
872
$name = Random::generateString(8, 'phpunit');
873
$displayGroup = (new XiboDisplayGroup($this->getEntityProvider()))->create($name, 'phpunit description', 0, '');
875
$command = (new XiboCommand($this->getEntityProvider()))->create('phpunit command', 'phpunit description', 'phpunitcode');
876
# Send command to display group
877
$this->client->post('/displaygroup/' . $displayGroup->displayGroupId . '/action/command' , [
878
'commandId' => $command->commandId
880
# Check if successful
881
$this->assertSame(200, $this->client->response->status(), $this->client->response->body());
882
$object = json_decode($this->client->response->body());
884
$displayGroup->delete();