~xibo-maintainers/xibo/tempel

« back to all changes in this revision

Viewing changes to tests/integration/LibraryTest.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
 
 * (LibraryTest.php)
6
 
 */
7
 
 
8
 
namespace Xibo\Tests\Integration;
9
 
 
10
 
use Xibo\Helper\Random;
11
 
use Xibo\OAuth2\Client\Entity\XiboLibrary;
12
 
use Xibo\Tests\LocalWebTestCase;
13
 
 
14
 
class LibraryTest extends LocalWebTestCase
15
 
{
16
 
    protected $startMedias;
17
 
    /**
18
 
     * setUp - called before every test automatically
19
 
     */
20
 
    public function setup()
21
 
    {  
22
 
        parent::setup();
23
 
        $this->startMedias = (new XiboLibrary($this->getEntityProvider()))->get(['start' => 0, 'length' => 10000]);
24
 
    }
25
 
    /**
26
 
     * tearDown - called after every test automatically
27
 
     */
28
 
    public function tearDown()
29
 
    {
30
 
        // tearDown all media files that weren't there initially
31
 
        $finalMedias = (new XiboLibrary($this->getEntityProvider()))->get(['start' => 0, 'length' => 10000]);
32
 
        # Loop over any remaining media files and nuke them
33
 
        foreach ($finalMedias as $media) {
34
 
            /** @var XiboLibrary $media */
35
 
            $flag = true;
36
 
            foreach ($this->startMedias as $startMedia) {
37
 
               if ($startMedia->mediaId == $media->mediaId) {
38
 
                   $flag = false;
39
 
               }
40
 
            }
41
 
            if ($flag) {
42
 
                try {
43
 
                    $media->deleteAssigned();
44
 
                } catch (\Exception $e) {
45
 
                    fwrite(STDERR, 'Unable to delete ' . $media->mediaId . '. E:' . $e->getMessage());
46
 
                }
47
 
            }
48
 
        }
49
 
        parent::tearDown();
50
 
    }
51
 
 
52
 
    /**
53
 
     * List all file in library
54
 
     */
55
 
    public function testListAll()
56
 
    {
57
 
        # Get all library items
58
 
        $this->client->get('/library');
59
 
 
60
 
        $this->assertSame(200, $this->client->response->status());
61
 
        $this->assertNotEmpty($this->client->response->body());
62
 
        $object = json_decode($this->client->response->body());
63
 
        $this->assertObjectHasAttribute('data', $object, $this->client->response->body());
64
 
    }
65
 
 
66
 
    /**
67
 
     * Add new file to library
68
 
     */
69
 
    public function testAdd()
70
 
    {
71
 
        # Using XiboLibrary wrapper to upload new file to the CMS, need to provide (name, file location)
72
 
        $media = (new XiboLibrary($this->getEntityProvider()))->create('API video test', PROJECT_ROOT . '/tests/resources/HLH264.mp4');
73
 
 
74
 
        $media->delete();
75
 
    }
76
 
 
77
 
    /**
78
 
     * Add new file to library and replace old one in all layouts
79
 
     */
80
 
    public function testReplace()
81
 
    {
82
 
        # Using XiboLibrary wrapper to upload new file to the CMS, need to provide (name, file location)
83
 
        $media = (new XiboLibrary($this->getEntityProvider()))->create('flowers', PROJECT_ROOT . '/tests/resources/xts-flowers-001.jpg');
84
 
        # Replace the image and update it in all layouts (name, file location, old media id, replace in all layouts flag, delete old revision flag)
85
 
        $media2 = (new XiboLibrary($this->getEntityProvider()))->create('API replace image', PROJECT_ROOT . '/tests/resources/xts-flowers-002.jpg',  $media->mediaId, 1, 1);
86
 
    }
87
 
 
88
 
    /**
89
 
     * try to add not allowed filetype
90
 
     */
91
 
    public function testAddEmpty()
92
 
    {
93
 
        # Using XiboLibrary wrapper to upload new file to the CMS, need to provide (name, file location)
94
 
        $this->setExpectedException('\Xibo\OAuth2\Client\Exception\XiboApiException');
95
 
 
96
 
        $media = (new XiboLibrary($this->getEntityProvider()))->create('API incorrect file 2', PROJECT_ROOT . '/tests/resources/empty.txt');
97
 
    }
98
 
 
99
 
    /**
100
 
     * Add tags to media
101
 
     */
102
 
    public function testAddTag()
103
 
    {
104
 
        # Using XiboLibrary wrapper to upload new file to the CMS, need to provide (name, file location)
105
 
        $media = (new XiboLibrary($this->getEntityProvider()))->create('flowers 2', PROJECT_ROOT . '/tests/resources/xts-flowers-001.jpg');
106
 
 
107
 
        $this->client->post('/library/' . $media->mediaId . '/tag', [
108
 
            'tag' => ['API']
109
 
            ]);
110
 
        $media = (new XiboLibrary($this->getEntityProvider()))->getById($media->mediaId);
111
 
        $this->assertSame(200, $this->client->response->status(), 'Not successful: ' . $this->client->response->body());
112
 
        $object = json_decode($this->client->response->body());
113
 
        $this->assertObjectHasAttribute('data', $object);
114
 
        $this->assertSame('API', $media->tags);
115
 
        $media->delete();
116
 
    }
117
 
 
118
 
    /**
119
 
     * Delete tags from media
120
 
     * @group broken
121
 
     */
122
 
    public function testDeleteTag()
123
 
    {
124
 
        # Using XiboLibrary wrapper to upload new file to the CMS, need to provide (name, file location)
125
 
        $media = (new XiboLibrary($this->getEntityProvider()))->create('flowers', PROJECT_ROOT . '/tests/resources/xts-flowers-001.jpg');
126
 
        $media->AddTag('API');
127
 
        $media = (new XiboLibrary($this->getEntityProvider()))->getById($media->mediaId);
128
 
        $this->assertSame('API', $media->tags);
129
 
         print_r($media->tags);
130
 
        $this->client->delete('/library/' . $media->mediaId . '/untag', [
131
 
            'tag' => ['API']
132
 
            ]);
133
 
        $media = (new XiboLibrary($this->getEntityProvider()))->getById($media->mediaId);
134
 
         print_r($media->tags);
135
 
        $this->assertSame(200, $this->client->response->status(), 'Not successful: ' . $this->client->response->body());
136
 
        $media->delete();
137
 
    }
138
 
 
139
 
    /**
140
 
     * Edit media file
141
 
     */
142
 
    public function testEdit()
143
 
    {
144
 
        # Using XiboLibrary wrapper to upload new file to the CMS, need to provide (name, file location)
145
 
        $media = (new XiboLibrary($this->getEntityProvider()))->create('API video 4', PROJECT_ROOT . '/tests/resources/HLH264.mp4');
146
 
        # Generate new random name
147
 
        $name = Random::generateString(8, 'phpunit');
148
 
        # Edit media file, change the name
149
 
        $this->client->put('/library/' . $media->mediaId, [
150
 
            'name' => $name,
151
 
            'duration' => 50,
152
 
            'retired' => $media->retired,
153
 
            'tags' => $media->tags,
154
 
            'updateInLayouts' => 1
155
 
        ], ['CONTENT_TYPE' => 'application/x-www-form-urlencoded']);
156
 
 
157
 
        $this->assertSame(200, $this->client->response->status(), 'Not successful: ' . $this->client->response->body());
158
 
        $object = json_decode($this->client->response->body());
159
 
        $this->assertObjectHasAttribute('data', $object);
160
 
        $this->assertSame($name, $object->data->name);
161
 
        $media = (new XiboLibrary($this->getEntityProvider()))->getById($media->mediaId);
162
 
        $this->assertSame($name, $media->name);
163
 
        $media->delete();
164
 
    }
165
 
 
166
 
    /**
167
 
     * Test delete added media
168
 
     */
169
 
    public function testDelete()
170
 
    {
171
 
        # Using XiboLibrary wrapper to upload new file to the CMS, need to provide (name, file location)
172
 
        $media = (new XiboLibrary($this->getEntityProvider()))->create('API video 4', PROJECT_ROOT . '/tests/resources/HLH264.mp4');
173
 
        # Delete added media file
174
 
        $this->client->delete('/library/' . $media->mediaId);
175
 
        $this->assertSame(200, $this->client->response->status(), $this->client->response->body());
176
 
    }
177
 
 
178
 
    /**
179
 
    * Library tidy
180
 
    */
181
 
    public function testTidy()
182
 
    {
183
 
        $this->client->delete('/library/tidy');
184
 
        $this->assertSame(200, $this->client->response->status(), $this->client->response->body());
185
 
    }
186
 
}