@@ -31,6 +31,16 @@ public function recursivelyAliasPropertyValue($propertyValue)
31
31
{
32
32
return parent ::recursivelyAliasPropertyValue ($ propertyValue );
33
33
}
34
+
35
+ public function getPropertiesAsArray ()
36
+ {
37
+ return parent ::getPropertiesAsArray ();
38
+ }
39
+
40
+ public function generateJsonPatch ($ updateParams )
41
+ {
42
+ return parent ::generateJsonPatch ($ updateParams );
43
+ }
34
44
}
35
45
36
46
class PersistentResourceTest extends OpenCloudTestCase
@@ -106,4 +116,68 @@ public function testRecursivelyAliasPropertyValueWithObjects()
106
116
$ this ->assertEquals ($ obj3Expected ,
107
117
$ this ->persistentResource ->recursivelyAliasPropertyValue ($ obj3 ));
108
118
}
119
+
120
+ public function testGetPropertiesAsArray ()
121
+ {
122
+ $ this ->persistentResource ->id = 17 ;
123
+ $ this ->persistentResource ->tags = array ('foo ' , 'bar ' );
124
+ $ this ->persistentResource ->domains = array (
125
+ (object ) array ('domain ' => 'foo.phpopencloud.com ' ),
126
+ array ('domain ' => 'bar.phpopencloud.com ' )
127
+ );
128
+ $ this ->persistentResource ->origins = array (
129
+ array ('origin ' => 'origin1.phpopencloud.com ' )
130
+ );
131
+ $ this ->persistentResource ->status = (object ) array ('message ' => 'Creation in progress ' );
132
+
133
+ $ expectedArray = array (
134
+ 'id ' => 17 ,
135
+ 'tags ' => array ('foo ' , 'bar ' ),
136
+ 'domains ' => array (
137
+ (object ) array ('domain ' => 'foo.phpopencloud.com ' ),
138
+ array ('domain ' => 'bar.phpopencloud.com ' )
139
+ ),
140
+ 'origins ' => array (
141
+ array ('origin ' => 'origin1.phpopencloud.com ' ),
142
+ ),
143
+ 'status ' => (object ) array ('message ' => 'Creation in progress ' ),
144
+ );
145
+
146
+ $ this ->assertEquals ($ expectedArray , $ this ->persistentResource ->getPropertiesAsArray ());
147
+ }
148
+
149
+ public function testGenerateJsonPatch ()
150
+ {
151
+ $ this ->persistentResource ->id = 17 ;
152
+ $ this ->persistentResource ->tags = array ('foo ' , 'bar ' );
153
+ $ this ->persistentResource ->domains = array (
154
+ array ('domain ' => 'foo.phpopencloud.com ' ),
155
+ array ('domain ' => 'bar.phpopencloud.com ' )
156
+ );
157
+ $ this ->persistentResource ->origins = array (
158
+ array ('origin ' => 'origin1.phpopencloud.com ' )
159
+ );
160
+ $ this ->persistentResource ->status = array ('message ' => 'Creation in progress ' );
161
+
162
+ $ updateParams = array (
163
+ 'tags ' => array ('foo ' , 'qux ' , 'baz ' ),
164
+ 'domains ' => array (
165
+ array ('domain ' => 'foo.phpopencloud.com ' )
166
+ ),
167
+ 'origins ' => array (
168
+ array ('origin ' => 'origin1.phpopencloud.com ' ),
169
+ array ('origin ' => 'origin2.phpopencloud.com ' )
170
+ )
171
+ );
172
+
173
+ $ expectedJsonPatch = json_encode (array (
174
+ array ('op ' => 'add ' , 'path ' => '/tags/2 ' , 'value ' => 'baz ' ),
175
+ array ('op ' => 'replace ' , 'path ' => '/tags/1 ' , 'value ' => 'qux ' ),
176
+ array ('op ' => 'remove ' , 'path ' => '/domains/1 ' ),
177
+ array ('op ' => 'add ' , 'path ' => '/origins/1 ' , 'value ' => array ("origin " => "origin2.phpopencloud.com " ))
178
+ ));
179
+
180
+ $ actualJsonPatch = $ this ->persistentResource ->generateJsonPatch ($ updateParams );
181
+ $ this ->assertEquals ($ expectedJsonPatch , $ actualJsonPatch );
182
+ }
109
183
}
0 commit comments