@@ -91,13 +91,87 @@ public function testCreateUpdateGetAndDeleteDocumentThroughCreateFromArray()
91
91
$ this ->assertTrue (true === ($ resultingDocument ->someAttribute == 'someValue2 ' ));
92
92
$ this ->assertTrue (true === ($ resultingDocument ->someOtherAttribute == 'someOtherValue2 ' ));
93
93
94
+ $ response = $ documentHandler ->delete ($ document );
95
+ $ this ->assertTrue (true === $ response , 'Delete should return true! ' );
96
+ }
97
+
98
+ /**
99
+ * test for creation, update, get, and delete of a document given its settings through createFromArray()
100
+ */
101
+ public function testCreateUpdateGetAndDeleteDocumentWithRevisionCheck ()
102
+ {
103
+ $ documentHandler = $ this ->documentHandler ;
104
+
105
+ $ document = Document::createFromArray (array ('someAttribute ' => 'someValue ' , 'someOtherAttribute ' => 'someOtherValue ' ));
106
+ $ documentId = $ documentHandler ->add ($ this ->collection ->getId (), $ document );
107
+
108
+ $ this ->assertTrue (is_numeric ($ documentId ), 'Did not return an id! ' );
109
+
110
+ $ resultingDocument = $ documentHandler ->get ($ this ->collection ->getId (), $ documentId );
111
+
112
+ $ this ->assertObjectHasAttribute ('_id ' , $ resultingDocument , '_id field should exist, empty or with an id ' );
113
+
114
+
115
+ // Set some new values on the attributes and include the revision in the _rev attribute
116
+ // This should result in a successfull update
117
+ $ document ->set ('someAttribute ' ,'someValue2 ' );
118
+ $ document ->set ('someOtherAttribute ' ,'someOtherValue2 ' );
119
+ $ document ->set ('_rev ' ,$ resultingDocument ->getRevision ());
120
+
121
+ $ result = $ documentHandler ->update ($ document , 'error ' );
122
+
123
+ $ this ->assertTrue ($ result );
124
+ $ resultingDocument = $ documentHandler ->get ($ this ->collection ->getId (), $ documentId );
125
+
126
+ $ this ->assertTrue (true === ($ resultingDocument ->someAttribute == 'someValue2 ' ));
127
+ $ this ->assertTrue (true === ($ resultingDocument ->someOtherAttribute == 'someOtherValue2 ' ));
128
+
129
+ // Set some new values on the attributes and include a fake revision in the _rev attribute
130
+ // This should result in a successfull update
131
+ $ document ->set ('someAttribute ' ,'someValue3 ' );
132
+ $ document ->set ('someOtherAttribute ' ,'someOtherValue3 ' );
133
+ $ document ->set ('_rev ' ,$ resultingDocument ->getRevision ()-1000 );
134
+
135
+ try {
136
+ $ result = $ documentHandler ->update ($ document , 'error ' );
137
+ } catch (\Exception $ e ) {
138
+ // don't bother us... just give us the $e
139
+ }
140
+
141
+ $ this ->assertInstanceOf ('Exception ' , $ e );
142
+ $ this ->assertTrue ($ e ->getMessage () == 'HTTP/1.1 412 Precondition Failed ' );
143
+ $ resultingDocument = $ documentHandler ->get ($ this ->collection ->getId (), $ documentId );
144
+
145
+ $ this ->assertTrue (true === ($ resultingDocument ->someAttribute == 'someValue2 ' ));
146
+ $ this ->assertTrue (true === ($ resultingDocument ->someOtherAttribute == 'someOtherValue2 ' ));
147
+ unset ($ e );
148
+
149
+ $ document = Document::createFromArray (array ('someAttribute ' => 'someValue3 ' , 'someOtherAttribute ' => 'someOtherValue3 ' ));
150
+ $ document ->setInternalId ($ this ->collection ->getId ().'/ ' .$ documentId );
151
+ // Set some new values on the attributes and _rev attribute to NULL
152
+ // This should result in a successfull update
153
+ try {
154
+ $ result = $ documentHandler ->update ($ document , 'error ' );
155
+ } catch (\Exception $ e ) {
156
+ // don't bother us... just give us the $e
157
+ }
158
+ $ resultingDocument = $ documentHandler ->get ($ this ->collection ->getId (), $ documentId );
159
+
160
+ $ this ->assertTrue (true === ($ resultingDocument ->someAttribute == 'someValue3 ' ));
161
+ $ this ->assertTrue (true === ($ resultingDocument ->someOtherAttribute == 'someOtherValue3 ' ));
162
+
163
+
164
+
165
+
166
+
94
167
$ response = $ documentHandler ->delete ($ document );
95
168
$ this ->assertTrue (true === $ response , 'Delete should return true! ' );
96
169
}
97
170
98
171
99
172
/**
100
173
* test to set some attributes and get all attributes of the document through getAll()
174
+ * Also testing to optionally get internal attributes _id and _rev
101
175
*/
102
176
public function testGetAll ()
103
177
{
@@ -110,6 +184,10 @@ public function testGetAll()
110
184
111
185
$ this ->assertTrue (true === ($ result ['someAttribute ' ] == 'someValue ' ));
112
186
$ this ->assertTrue (true === ($ result ['someOtherAttribute ' ] == 'someOtherValue ' ));
187
+
188
+ $ result = $ document ->getAll (true );
189
+ $ this ->assertArrayHasKey ('_id ' , $ result );
190
+ $ this ->assertArrayHasKey ('_rev ' , $ result );
113
191
}
114
192
115
193
public function tearDown ()
0 commit comments