~ubuntu-branches/ubuntu/vivid/php-opencloud/vivid

« back to all changes in this revision

Viewing changes to tests/OpenCloud/Tests/Image/Resource/ImageTest.php

  • Committer: Package Import Robot
  • Author(s): David Prévot
  • Date: 2014-07-20 13:48:45 UTC
  • mfrom: (2.1.7 experimental)
  • Revision ID: package-import@ubuntu.com-20140720134845-0dsedgwivztyrjow
Tags: 1.10.0-2
* Make dir_to_symlink Wheezy-compatible
* Upload to unstable as needed by latest owncloud version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Copyright 2012-2014 Rackspace US, Inc.
 
4
 *
 
5
 * Licensed under the Apache License, Version 2.0 (the "License");
 
6
 * you may not use this file except in compliance with the License.
 
7
 * You may obtain a copy of the License at
 
8
 *
 
9
 * http://www.apache.org/licenses/LICENSE-2.0
 
10
 *
 
11
 * Unless required by applicable law or agreed to in writing, software
 
12
 * distributed under the License is distributed on an "AS IS" BASIS,
 
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
14
 * See the License for the specific language governing permissions and
 
15
 * limitations under the License.
 
16
 */
 
17
 
 
18
namespace OpenCloud\Tests\Image\Resource;
 
19
 
 
20
use Guzzle\Http\Message\Response;
 
21
use OpenCloud\Image\Resource\Image;
 
22
use OpenCloud\Image\Resource\Schema\Schema;
 
23
use OpenCloud\Tests\OpenCloudTestCase;
 
24
 
 
25
class ImageTest extends OpenCloudTestCase
 
26
{
 
27
    public function setupObjects()
 
28
    {
 
29
        $this->image = new Image($this->getClient()->imageService('cloudImages', 'IAD'));
 
30
    }
 
31
 
 
32
    protected function getSchemaData()
 
33
    {
 
34
        return json_decode(file_get_contents(__DIR__ . '/Schema/image.json'), true);
 
35
    }
 
36
 
 
37
    public function test_Update()
 
38
    {
 
39
        $schema = Schema::factory($this->getSchemaData());
 
40
        $config = array(
 
41
            'visibility' => 'private',
 
42
            'name'       => 'FOOBAR'
 
43
        );
 
44
 
 
45
        $response = $this->image->update($config, $schema);
 
46
 
 
47
        $this->assertInstanceOf('Guzzle\Http\Message\Response', $response);
 
48
    }
 
49
 
 
50
    public function test_Updating_AddProperty()
 
51
    {
 
52
        $schema = Schema::factory($this->getSchemaData());
 
53
        $config = array(
 
54
            'foo' => 'bar'
 
55
        );
 
56
 
 
57
        $response = $this->image->update($config, $schema);
 
58
 
 
59
        $this->assertInstanceOf('Guzzle\Http\Message\Response', $response);
 
60
    }
 
61
 
 
62
    /**
 
63
     * @expectedException \RuntimeException
 
64
     */
 
65
    public function test_Update_Fails_With_AddProperties()
 
66
    {
 
67
        $data = $this->getSchemaData();
 
68
        unset($data['additionalProperties']);
 
69
 
 
70
        $schema = Schema::factory($data);
 
71
        $config = array(
 
72
            'foo' => 'bar'
 
73
        );
 
74
 
 
75
        $response = $this->image->update($config, $schema);
 
76
 
 
77
        $this->assertInstanceOf('Guzzle\Http\Message\Response', $response);
 
78
    }
 
79
 
 
80
    public function test_Refresh()
 
81
    {
 
82
        $this->addMockSubscriber($this->makeResponse('{"id":"da3b75d9-3f4a-40e7-8a2c-bfab23927dea","name":"cirros-0.3.0-x86_64-uec-ramdisk","status":"active","visibility":"public","size":2254249,"checksum":"2cec138d7dae2aa59038ef8c9aec2390","tags":["ping","pong"],"created_at":"2012-08-10T19:23:50Z","updated_at":"2012-08-10T19:23:50Z","self":"/v2/images/da3b75d9-3f4a-40e7-8a2c-bfab23927dea","file":"/v2/images/da3b75d9-3f4a-40e7-8a2c-bfab23927dea/file","schema":"/v2/schemas/image"}'));
 
83
 
 
84
        $this->assertInstanceOf('Guzzle\Http\Message\Response', $this->image->refresh());
 
85
    }
 
86
 
 
87
    public function test_Delete()
 
88
    {
 
89
        $this->addMockSubscriber(new Response(204));
 
90
 
 
91
        $this->assertInstanceOf('Guzzle\Http\Message\Response', $this->image->delete());
 
92
    }
 
93
 
 
94
    public function test_List_Members()
 
95
    {
 
96
        $json = <<<EOT
 
97
{"members":[{"created_at":"2013-10-07T17:58:03Z","image_id":"dbc999e3-c52f-4200-bedd-3b18fe7f87fe","member_id":"123456789","schema":"/v2/schemas/member","status":"pending","updated_at":"2013-10-07T17:58:03Z"},{"created_at":"2013-10-07T17:58:55Z","image_id":"dbc999e3-c52f-4200-bedd-3b18fe7f87fe","member_id":"987654321","schema":"/v2/schemas/member","status":"accepted","updated_at":"2013-10-08T12:08:55Z"}],"schema":"/v2/schemas/members"}
 
98
EOT;
 
99
 
 
100
        $this->addMockSubscriber($this->makeResponse($json));
 
101
 
 
102
        $members = $this->image->listMembers();
 
103
 
 
104
        $this->assertInstanceOf('OpenCloud\Common\Collection\PaginatedIterator', $members);
 
105
        $this->assertInstanceOf('OpenCloud\Image\Resource\Member', $members->getElement(0));
 
106
    }
 
107
 
 
108
    public function test_Get_Member()
 
109
    {
 
110
        $this->addMockSubscriber(new Response(200));
 
111
 
 
112
        $this->assertInstanceOf('OpenCloud\Image\Resource\Member', $this->image->getMember('foo'));
 
113
    }
 
114
 
 
115
    public function test_Create_Member()
 
116
    {
 
117
        $this->addMockSubscriber(new Response(201));
 
118
 
 
119
        $this->assertInstanceOf('Guzzle\Http\Message\Response', $this->image->createMember(12345));
 
120
    }
 
121
 
 
122
    public function test_Delete_Member()
 
123
    {
 
124
        $this->addMockSubscriber(new Response(201));
 
125
 
 
126
        $this->assertInstanceOf('Guzzle\Http\Message\Response', $this->image->deleteMember(12345));
 
127
    }
 
128
 
 
129
    public function test_Create_Tag()
 
130
    {
 
131
        $this->addMockSubscriber(new Response(201));
 
132
 
 
133
        $this->assertInstanceOf('Guzzle\Http\Message\Response', $this->image->addTag(12345));
 
134
    }
 
135
 
 
136
    public function test_Delete_Tag()
 
137
    {
 
138
        $this->addMockSubscriber(new Response(204));
 
139
 
 
140
        $this->assertInstanceOf('Guzzle\Http\Message\Response', $this->image->deleteTag(12345));
 
141
    }
 
142
 
 
b'\\ No newline at end of file'