~xibo-maintainers/xibo/tempel

« back to all changes in this revision

Viewing changes to tests/integration/Widget/PdfWidgetTest.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
 
 * (PdfWidgetTest.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\XiboLibrary;
13
 
use Xibo\OAuth2\Client\Entity\XiboPdf;
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 PdfWidgetTest 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('PDF 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 PDF', PROJECT_ROOT . '/tests/resources/sampleDocument.pdf');
85
 
        # Assign media to a playlist
86
 
        $playlist = (new XiboPlaylist($this->getEntityProvider()))->assign([$media->mediaId], 10, $region->playlists[0]['playlistId']);
87
 
        $name = 'Edited Name';
88
 
        $duration = 80;
89
 
        $widget = $playlist->widgets[0];
90
 
        $response = $this->client->put('/playlist/widget/' . $widget->widgetId, [
91
 
            'name' => $name,
92
 
            'duration' => $duration,
93
 
            ], ['CONTENT_TYPE' => 'application/x-www-form-urlencoded']);
94
 
        $this->assertSame(200, $this->client->response->status());
95
 
        $this->assertNotEmpty($this->client->response->body());
96
 
        $object = json_decode($this->client->response->body());
97
 
        $this->assertObjectHasAttribute('data', $object, $this->client->response->body());
98
 
        $widgetOptions = (new XiboPdf($this->getEntityProvider()))->getById($region->playlists[0]['playlistId']);
99
 
        $this->assertSame($name, $widgetOptions->name);
100
 
        $this->assertSame($duration, $widgetOptions->duration);
101
 
        $this->assertSame($media->mediaId, intval($widgetOptions->mediaIds[0]));
102
 
    }
103
 
 
104
 
    public function testDelete()
105
 
    {
106
 
        # Create layout 
107
 
        $layout = (new XiboLayout($this->getEntityProvider()))->create('PDF delete Layout', 'phpunit description', '', 9);
108
 
        # Add region to our layout
109
 
        $region = (new XiboRegion($this->getEntityProvider()))->create($layout->layoutId, 1000,1000,200,200);
110
 
        # Upload new media
111
 
        $media = (new XiboLibrary($this->getEntityProvider()))->create('API video', PROJECT_ROOT . '/tests/resources/sampleDocument.pdf');
112
 
        # Assign media to a region
113
 
        $playlist = (new XiboPlaylist($this->getEntityProvider()))->assign([$media->mediaId], 10, $region->playlists[0]['playlistId']);
114
 
        $widget = $playlist->widgets[0];
115
 
        # Delete it
116
 
        $this->client->delete('/playlist/widget/' . $widget->widgetId);
117
 
        $response = json_decode($this->client->response->body());
118
 
        $this->assertSame(200, $response->status, $this->client->response->body());
119
 
    }
120
 
}