~xibo-maintainers/xibo/tempel

« back to all changes in this revision

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

  • Committer: Dan Garner
  • Date: 2015-03-26 14:08:33 UTC
  • Revision ID: git-v1:70d14044444f8dc5d602b99890d59dea46d9470c
Moved web servable files to web folder

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
 
 * (WebpageWidgetTest.php)
6
 
 */
7
 
 
8
 
namespace Xibo\Tests\Integration\Widget;
9
 
 
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;
16
 
 
17
 
class WebpageWidgetTest extends LocalWebTestCase
18
 
{
19
 
 
20
 
        protected $startLayouts;
21
 
    /**
22
 
     * setUp - called before every test automatically
23
 
     */
24
 
    public function setup()
25
 
    {  
26
 
        parent::setup();
27
 
        $this->startLayouts = (new XiboLayout($this->getEntityProvider()))->get(['start' => 0, 'length' => 10000]);
28
 
    }
29
 
    /**
30
 
     * tearDown - called after every test automatically
31
 
     */
32
 
    public function tearDown()
33
 
    {
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 */
39
 
            $flag = true;
40
 
            foreach ($this->startLayouts as $startLayout) {
41
 
               if ($startLayout->layoutId == $layout->layoutId) {
42
 
                   $flag = false;
43
 
               }
44
 
            }
45
 
            if ($flag) {
46
 
                try {
47
 
                    $layout->delete();
48
 
                } catch (\Exception $e) {
49
 
                    fwrite(STDERR, 'Unable to delete ' . $layout->layoutId . '. E:' . $e->getMessage());
50
 
                }
51
 
            }
52
 
        }
53
 
        parent::tearDown();
54
 
    }
55
 
 
56
 
        /**
57
 
         * @group add
58
 
     * @dataProvider provideSuccessCases
59
 
     */
60
 
        public function testAdd($name, $duration, $useDuration, $transparency, $uri, $scaling, $offsetLeft, $offsetTop, $pageWidth, $pageHeight, $modeId)
61
 
        {
62
 
                //parent::setupEnv();
63
 
                # Create layout
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);
67
 
 
68
 
                $response = $this->client->post('/playlist/widget/webpage/' . $region->playlists[0]['playlistId'], [
69
 
                'name' => $name,
70
 
                'duration' => $duration,
71
 
            'useDuration' => $useDuration,
72
 
                'transparency' => $transparency,
73
 
                'uri' => $uri,
74
 
                'scaling' => $scaling,
75
 
                'offsetLeft' => $offsetLeft,
76
 
                'offsetTop' => $offsetTop,
77
 
                'pageWidth' => $pageWidth,
78
 
                'pageHeight' => $pageHeight,
79
 
                'modeId' => $modeId
80
 
                ]);
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']));
91
 
            }
92
 
            if ($option['option'] == 'modeId') {
93
 
                $this->assertSame($modeId, intval($option['value']));
94
 
            }
95
 
        }
96
 
        }
97
 
 
98
 
        /**
99
 
     * Each array is a test run
100
 
     * Format (($name, $duration, $useDuration, $transparency, $uri, $scaling, $offsetLeft, $offsetTop, $pageWidth, $pageHeight, $modeId)
101
 
     * @return array
102
 
     */
103
 
    public function provideSuccessCases()
104
 
    {
105
 
        # Sets of data used in testAdd
106
 
        return [
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],
112
 
        ];
113
 
    }
114
 
 
115
 
    public function testEdit()
116
 
    {
117
 
        # Create layout
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';
124
 
        $durationNew = 80;
125
 
        $modeIdNew = 3;
126
 
        $uriNew = 'http://xibo.org.uk/about/';
127
 
        $response = $this->client->put('/playlist/widget/' . $webpage->widgetId, [
128
 
                'name' => $nameNew,
129
 
                'duration' => $durationNew,
130
 
            'useDuration' => 1,
131
 
                'transparency' => $webpage->transparency,
132
 
                'uri' => $uriNew,
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']));
150
 
            }
151
 
            if ($option['option'] == 'modeId') {
152
 
                $this->assertSame($modeIdNew, intval($option['value']));
153
 
            }
154
 
        }
155
 
    }
156
 
 
157
 
    public function testDelete()
158
 
    {
159
 
        # Create layout
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']);
166
 
                # Delete it
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());
171
 
    }
172
 
}