~xibo-maintainers/xibo/tempel

« back to all changes in this revision

Viewing changes to tests/integration/Widget/ImageWidgetTest.php

  • Committer: Dan Garner
  • Date: 2016-02-18 16:07:16 UTC
  • mfrom: (454.4.137)
  • Revision ID: git-v1:8867f12675bc9e0e67e7e622c80da7471b9f294a
Merge pull request #139 from dasgarner/feature/nested-display-groups

Feature/nested display groups

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/*
3
 
 * Spring Signage Ltd - http://www.springsignage.com
4
 
 * Copyright (C) 2015 Spring Signage Ltd
5
 
 * (ImageWidgetTest.php)
6
 
 */
7
 
 
8
 
namespace Xibo\Tests\Integration\Widget;
9
 
 
10
 
use Xibo\Helper\Random;
11
 
use Xibo\OAuth2\Client\Entity\XiboImage;
12
 
use Xibo\OAuth2\Client\Entity\XiboLayout;
13
 
use Xibo\OAuth2\Client\Entity\XiboLibrary;
14
 
use Xibo\OAuth2\Client\Entity\XiboPlaylist;
15
 
use Xibo\OAuth2\Client\Entity\XiboRegion;
16
 
use Xibo\OAuth2\Client\Entity\XiboWidget;
17
 
use Xibo\Tests\LocalWebTestCase;
18
 
 
19
 
class ImageWidgetTest extends LocalWebTestCase
20
 
{
21
 
        protected $startLayouts;
22
 
    /**
23
 
     * setUp - called before every test automatically
24
 
     */
25
 
    public function setup()
26
 
    {  
27
 
        parent::setup();
28
 
        $this->startLayouts = (new XiboLayout($this->getEntityProvider()))->get(['start' => 0, 'length' => 10000]);
29
 
        $this->startMedias = (new XiboLibrary($this->getEntityProvider()))->get(['start' => 0, 'length' => 10000]);
30
 
    }
31
 
    /**
32
 
     * tearDown - called after every test automatically
33
 
     */
34
 
    public function tearDown()
35
 
    {
36
 
        // tearDown all layouts that weren't there initially
37
 
        $finalLayouts = (new XiboLayout($this->getEntityProvider()))->get(['start' => 0, 'length' => 10000]);
38
 
        # Loop over any remaining layouts and nuke them
39
 
        foreach ($finalLayouts as $layout) {
40
 
            /** @var XiboLayout $layout */
41
 
            $flag = true;
42
 
            foreach ($this->startLayouts as $startLayout) {
43
 
               if ($startLayout->layoutId == $layout->layoutId) {
44
 
                   $flag = false;
45
 
               }
46
 
            }
47
 
            if ($flag) {
48
 
                try {
49
 
                    $layout->delete();
50
 
                } catch (\Exception $e) {
51
 
                    fwrite(STDERR, 'Unable to delete ' . $layout->layoutId . '. E:' . $e->getMessage());
52
 
                }
53
 
            }
54
 
        }
55
 
        // tearDown all media files that weren't there initially
56
 
        $finalMedias = (new XiboLibrary($this->getEntityProvider()))->get(['start' => 0, 'length' => 10000]);
57
 
        # Loop over any remaining media files and nuke them
58
 
        foreach ($finalMedias as $media) {
59
 
            /** @var XiboLibrary $media */
60
 
            $flag = true;
61
 
            foreach ($this->startMedias as $startMedia) {
62
 
               if ($startMedia->mediaId == $media->mediaId) {
63
 
                   $flag = false;
64
 
               }
65
 
            }
66
 
            if ($flag) {
67
 
                try {
68
 
                    $media->deleteAssigned();
69
 
                } catch (\Exception $e) {
70
 
                    fwrite(STDERR, 'Unable to delete ' . $media->mediaId . '. E:' . $e->getMessage());
71
 
                }
72
 
            }
73
 
        }
74
 
        parent::tearDown();
75
 
    }
76
 
 
77
 
    public function testEdit()
78
 
    {
79
 
        # Create layout 
80
 
        $layout = (new XiboLayout($this->getEntityProvider()))->create('Image edit Layout', 'phpunit description', '', 9);
81
 
        # Add region to our layout
82
 
        $region = (new XiboRegion($this->getEntityProvider()))->create($layout->layoutId, 1000,1000,200,200);
83
 
        # Upload new media
84
 
        $media = (new XiboLibrary($this->getEntityProvider()))->create('API image', PROJECT_ROOT . '/tests/resources/xts-night-001.jpg');
85
 
        # Assign media to a playlist
86
 
        $playlist = (new XiboPlaylist($this->getEntityProvider()))->assign([$media->mediaId], 10, $region->playlists[0]['playlistId']);
87
 
        $nameNew = 'Edited Name';
88
 
        $durationNew = 80;
89
 
        $scaleTypeIdNew = 'stretch';
90
 
        $alignIdNew = 'center';
91
 
        $valignIdNew = 'top';
92
 
        $widget = $playlist->widgets[0];
93
 
        $response = $this->client->put('/playlist/widget/' . $widget->widgetId, [
94
 
            'name' => $nameNew,
95
 
            'duration' => $durationNew,
96
 
            'useDuration' => 1,
97
 
            'scaleTypeId' => $scaleTypeIdNew,
98
 
            'alignId' => $alignIdNew,
99
 
            'valignId' => $valignIdNew,
100
 
            ], ['CONTENT_TYPE' => 'application/x-www-form-urlencoded']);
101
 
        $this->assertSame(200, $this->client->response->status());
102
 
        $this->assertNotEmpty($this->client->response->body());
103
 
        $object = json_decode($this->client->response->body());
104
 
        $this->assertObjectHasAttribute('data', $object, $this->client->response->body());
105
 
        $widgetOptions = (new XiboImage($this->getEntityProvider()))->getById($region->playlists[0]['playlistId']);
106
 
        $this->assertSame($nameNew, $widgetOptions->name);
107
 
        $this->assertSame($durationNew, $widgetOptions->duration);
108
 
        $this->assertSame($media->mediaId, intval($widgetOptions->mediaIds[0]));
109
 
        foreach ($widgetOptions->widgetOptions as $option) {
110
 
            if ($option['option'] == 'scaleTypeId') {
111
 
                $this->assertSame($scaleTypeIdNew, $option['value']);
112
 
            }
113
 
            if ($option['option'] == 'alignId') {
114
 
                $this->assertSame($alignIdNew, $option['value']);
115
 
            }
116
 
            if ($option['option'] == 'valignId') {
117
 
                $this->assertSame($valignIdNew, $option['value']);
118
 
            }
119
 
        }
120
 
    }
121
 
 
122
 
    public function testDelete()
123
 
    {
124
 
        # Create layout 
125
 
        $layout = (new XiboLayout($this->getEntityProvider()))->create('Image delete Layout', 'phpunit description', '', 9);
126
 
        # Add region to our layout
127
 
        $region = (new XiboRegion($this->getEntityProvider()))->create($layout->layoutId, 1000,1000,200,200);
128
 
        # Upload new media
129
 
        $media = (new XiboLibrary($this->getEntityProvider()))->create('API image', PROJECT_ROOT . '/tests/resources/xts-night-001.jpg');
130
 
        # Assign media to a region
131
 
        $playlist = (new XiboPlaylist($this->getEntityProvider()))->assign([$media->mediaId], 10, $region->playlists[0]['playlistId']);
132
 
        $widget = $playlist->widgets[0];
133
 
        # Delete it
134
 
        $this->client->delete('/playlist/widget/' . $widget->widgetId);
135
 
        $response = json_decode($this->client->response->body());
136
 
        $this->assertSame(200, $response->status, $this->client->response->body());
137
 
    }
138
 
}