~xibo-maintainers/xibo/tempel

« back to all changes in this revision

Viewing changes to tests/integration/Widget/DataSetViewWidgetTest.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
 
 * (DataSetViewWidgetTest.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\XiboDataSet;
14
 
use Xibo\OAuth2\Client\Entity\XiboDataSetColumn;
15
 
use Xibo\OAuth2\Client\Entity\XiboDataSetView;
16
 
use Xibo\OAuth2\Client\Entity\XiboWidget;
17
 
use Xibo\Tests\LocalWebTestCase;
18
 
 
19
 
class DataSetViewWidgetTest extends LocalWebTestCase
20
 
{
21
 
 
22
 
        protected $startLayouts;
23
 
    protected $startDataSets;
24
 
 
25
 
    /**
26
 
     * setUp - called before every test automatically
27
 
     */
28
 
    public function setup()
29
 
    {  
30
 
        parent::setup();
31
 
        $this->startLayouts = (new XiboLayout($this->getEntityProvider()))->get(['start' => 0, 'length' => 10000]);
32
 
        $this->startDataSets = (new XiboDataSet($this->getEntityProvider()))->get(['start' => 0, 'length' => 10000]);
33
 
    }
34
 
 
35
 
    /**
36
 
     * tearDown - called after every test automatically
37
 
     */
38
 
    public function tearDown()
39
 
    {
40
 
        // tearDown all layouts that weren't there initially
41
 
        $finalLayouts = (new XiboLayout($this->getEntityProvider()))->get(['start' => 0, 'length' => 10000]);
42
 
        # Loop over any remaining layouts and nuke them
43
 
        foreach ($finalLayouts as $layout) {
44
 
            /** @var XiboLayout $layout */
45
 
            $flag = true;
46
 
            foreach ($this->startLayouts as $startLayout) {
47
 
               if ($startLayout->layoutId == $layout->layoutId) {
48
 
                   $flag = false;
49
 
               }
50
 
            }
51
 
            if ($flag) {
52
 
                try {
53
 
                    $layout->delete();
54
 
                } catch (\Exception $e) {
55
 
                    fwrite(STDERR, 'Unable to delete ' . $layout->layoutId . '. E:' . $e->getMessage());
56
 
                }
57
 
            }
58
 
        }
59
 
        // tearDown all datasets that weren't there initially
60
 
        $finalDataSets = (new XiboDataSet($this->getEntityProvider()))->get(['start' => 0, 'length' => 10000]);
61
 
 
62
 
        $difference = array_udiff($finalDataSets, $this->startDataSets, function ($a, $b) {
63
 
            /** @var XiboDataSet $a */
64
 
            /** @var XiboDataSet $b */
65
 
            return $a->dataSetId - $b->dataSetId;
66
 
        });
67
 
 
68
 
        # Loop over any remaining datasets and nuke them
69
 
        foreach ($difference as $dataSet) {
70
 
            /** @var XiboDataSet $dataSet */
71
 
            try {
72
 
                $dataSet->deleteWData();
73
 
            } catch (\Exception $e) {
74
 
                fwrite(STDERR, 'Unable to delete ' . $dataSet->dataSetId . '. E: ' . $e->getMessage() . PHP_EOL);
75
 
            }
76
 
        }
77
 
        parent::tearDown();
78
 
    }
79
 
 
80
 
    public function testAdd()
81
 
    {
82
 
        # Create layout
83
 
        $layout = (new XiboLayout($this->getEntityProvider()))->create('DataSetView add', 'phpunit description', '', 9);
84
 
        # Add region to our layout
85
 
        $region = (new XiboRegion($this->getEntityProvider()))->create($layout->layoutId, 1000,1000,200,200);
86
 
        # Create a new dataset
87
 
        $dataSet = (new XiboDataSet($this->getEntityProvider()))->create('phpunit dataset', 'phpunit description');
88
 
 
89
 
        $response = $this->client->post('/playlist/widget/dataSetView/' . $region->playlists[0]['playlistId'], [
90
 
            'name' => 'API dataSetView',
91
 
            'dataSetId' => $dataSet->dataSetId
92
 
            ]);
93
 
 
94
 
        $this->assertSame(200, $this->client->response->status(), "Not successful: " . $response);
95
 
        $object = json_decode($this->client->response->body());
96
 
        $this->assertObjectHasAttribute('data', $object);
97
 
        $widgetOptions = (new XiboDataSetView($this->getEntityProvider()))->getById($region->playlists[0]['playlistId']);
98
 
        $this->assertSame('API dataSetView', $widgetOptions->name);
99
 
        $this->assertSame(60, $widgetOptions->duration);
100
 
    }
101
 
 
102
 
    public function testEdit()
103
 
    {
104
 
        # Create layout
105
 
        $layout = (new XiboLayout($this->getEntityProvider()))->create('DataSetView edit', 'phpunit description', '', 9);
106
 
        # Add region to our layout
107
 
        $region = (new XiboRegion($this->getEntityProvider()))->create($layout->layoutId, 1000,1000,200,200);
108
 
        # Create a new dataset
109
 
        $dataSet = (new XiboDataSet($this->getEntityProvider()))->create('phpunit dataset', 'phpunit description');
110
 
        # Create dataSetView widget
111
 
        $dataSetView = (new XiboDataSetView($this->getEntityProvider()))->create('API dataSetView', $dataSet->dataSetId, $region->playlists[0]['playlistId']);
112
 
        $nameCol = Random::generateString(8, 'phpunit');
113
 
        $nameCol2 = Random::generateString(8, 'phpunit');
114
 
        $column = (new XiboDataSetColumn($this->getEntityProvider()))->create($dataSet->dataSetId, $nameCol,'', 2, 1, 1, '');
115
 
        $column2 = (new XiboDataSetColumn($this->getEntityProvider()))->create($dataSet->dataSetId, $nameCol2,'', 2, 1, 1, '');
116
 
        $nameNew = 'Edited Name';
117
 
        $durationNew = 80;
118
 
        $response = $this->client->put('/playlist/widget/' . $dataSetView->widgetId, [
119
 
            'dataSetColumnId' => [$column->dataSetColumnId, $column2->dataSetColumnId],
120
 
            'name' => $nameNew,
121
 
            'duration' => $durationNew,
122
 
            'updateInterval' => 100,
123
 
            'rowsPerPage' => 2,
124
 
            'showHeadings' =>0,
125
 
            'upperLimit' => 0,
126
 
            'lowerLimit' => 0,
127
 
            'filter' => null,
128
 
            'ordering' => null,
129
 
            'templateId' => 'light-green',
130
 
            'overrideTemplate' => 0,
131
 
            'useOrderingClause' => 0,
132
 
            'useFilteringClause' => 0,
133
 
            'noDataMessage' => 'No Data returned',
134
 
            ], ['CONTENT_TYPE' => 'application/x-www-form-urlencoded']);
135
 
        $this->assertSame(200, $this->client->response->status());
136
 
        $this->assertNotEmpty($this->client->response->body());
137
 
        $object = json_decode($this->client->response->body());
138
 
        $this->assertObjectHasAttribute('data', $object, $this->client->response->body());
139
 
        $widgetOptions = (new XiboDataSetView($this->getEntityProvider()))->getById($region->playlists[0]['playlistId']);
140
 
        $this->assertSame($nameNew, $widgetOptions->name);
141
 
        $this->assertSame($durationNew, $widgetOptions->duration);
142
 
        foreach ($widgetOptions->widgetOptions as $option) {
143
 
            if ($option['option'] == 'templateId') {
144
 
                $this->assertSame('light-green', $option['value']);
145
 
            }
146
 
            if ($option['option'] == 'updateInterval') {
147
 
                $this->assertSame(100, intval($option['value']));
148
 
            }
149
 
        }
150
 
    }
151
 
 
152
 
        public function testDelete()
153
 
    {
154
 
        # Create layout
155
 
        $layout = (new XiboLayout($this->getEntityProvider()))->create('DataSetView delete Layout', 'phpunit description', '', 9);
156
 
        # Add region to our layout
157
 
        $region = (new XiboRegion($this->getEntityProvider()))->create($layout->layoutId, 1000,1000,200,200);
158
 
        # Create a new dataset
159
 
        $dataSet = (new XiboDataSet($this->getEntityProvider()))->create('phpunit dataset', 'phpunit description');
160
 
        # Create dataSetView widget
161
 
        $dataSetView = (new XiboDataSetView($this->getEntityProvider()))->create('API dataSetView', $dataSet->dataSetId, $region->playlists[0]['playlistId']);
162
 
        # Delete it
163
 
        $this->client->delete('/playlist/widget/' . $dataSetView->widgetId);
164
 
        $response = json_decode($this->client->response->body());
165
 
        $this->assertSame(200, $response->status, $this->client->response->body());
166
 
    }
167
 
}