~xibo-maintainers/xibo/tempel

« back to all changes in this revision

Viewing changes to tests/integration/Widget/TextWidgetTest.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
 
 * (TextWidgetTest.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\XiboText;
14
 
use Xibo\OAuth2\Client\Entity\XiboWidget;
15
 
use Xibo\Tests\LocalWebTestCase;
16
 
 
17
 
class TextWidgetTest extends LocalWebTestCase
18
 
{
19
 
        protected $startLayouts;
20
 
    /**
21
 
     * setUp - called before every test automatically
22
 
     */
23
 
    public function setup()
24
 
    {  
25
 
        parent::setup();
26
 
        $this->startLayouts = (new XiboLayout($this->getEntityProvider()))->get(['start' => 0, 'length' => 10000]);
27
 
    }
28
 
    /**
29
 
     * tearDown - called after every test automatically
30
 
     */
31
 
    public function tearDown()
32
 
    {
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 */
38
 
            $flag = true;
39
 
            foreach ($this->startLayouts as $startLayout) {
40
 
               if ($startLayout->layoutId == $layout->layoutId) {
41
 
                   $flag = false;
42
 
               }
43
 
            }
44
 
            if ($flag) {
45
 
                try {
46
 
                    $layout->delete();
47
 
                } catch (\Exception $e) {
48
 
                    fwrite(STDERR, 'Unable to delete ' . $layout->layoutId . '. E:' . $e->getMessage());
49
 
                }
50
 
            }
51
 
        }
52
 
        parent::tearDown();
53
 
    }
54
 
        /**
55
 
     * @group add
56
 
     * @dataProvider provideSuccessCases
57
 
     */
58
 
    public function testAdd($name, $duration, $useDuration, $effect, $speed, $backgroundColor, $marqueeInlineSelector, $text, $javaScript)
59
 
    {
60
 
        //parent::setupEnv();
61
 
        # Create layout 
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);
65
 
 
66
 
        $response = $this->client->post('/playlist/widget/text/' . $region->playlists[0]['playlistId'], [
67
 
            'name' => $name,
68
 
            'duration' => $duration,
69
 
            'useDuration' => $useDuration,
70
 
            'effect' => $effect,
71
 
            'speed' => $speed,
72
 
            'backgroundColor' => $backgroundColor,
73
 
            'marqueeInlineSelector' => $marqueeInlineSelector,
74
 
            'text' => $text,
75
 
            'javaScript' => $javaScript
76
 
            ]);
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']);
87
 
            }
88
 
            if ($option['option'] == 'speed') {
89
 
                $this->assertSame($speed, intval($option['value']));
90
 
            }
91
 
            if ($option['option'] == 'text') {
92
 
                $this->assertSame($text, $option['value']);
93
 
            }
94
 
        }
95
 
    }
96
 
 
97
 
    /**
98
 
     * Each array is a test run
99
 
     * Format ($name, $duration, $useDuration, $effect, $speed, $backgroundColor, $marqueeInlineSelector, $text, $javaScript)
100
 
     * @return array
101
 
     */
102
 
    public function provideSuccessCases()
103
 
    {
104
 
        # Sets of data used in testAdd
105
 
        return [
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]
109
 
        ];
110
 
    }
111
 
    public function testEdit()
112
 
    {
113
 
        # Create layout 
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';
120
 
        $durationNew = 80;
121
 
        $textNew = 'Edited Text';
122
 
        $response = $this->client->put('/playlist/widget/' . $text->widgetId, [
123
 
            'name' => $nameNew,
124
 
            'duration' => $durationNew,
125
 
            'useDuration' => 1,
126
 
            'effect' => $text->effect,
127
 
            'speed' => $text->speed,
128
 
            'backgroundColor' => null,
129
 
            'marqueeInlineSelector' => null,
130
 
            'text' => $textNew,
131
 
            'javaScript' => 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']);
143
 
            }
144
 
        }
145
 
    }
146
 
 
147
 
    public function testDelete()
148
 
    {
149
 
        # Create layout 
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']);
155
 
        # Delete it
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());
159
 
    }
160
 
}