@@ -104,6 +104,66 @@ public function testCreateAndDeleteDocumentUsingDefinedKey()
104
104
105
105
$ documentHandler ->delete ($ document );
106
106
}
107
+
108
+ /**
109
+ * Try to create and delete a document with several keys
110
+ */
111
+ public function testCreateAndDeleteDocumentWithSeveralKeys ()
112
+ {
113
+ $ connection = $ this ->connection ;
114
+ $ collection = $ this ->collection ;
115
+ $ documentHandler = new DocumentHandler ($ connection );
116
+
117
+ $ keys = array ("foo " , "bar " , "bar:bar " , "baz " , "1 " , "0 " , "a-b-c " , "a:b " , "this-is-a-test " , "FOO " , "BAR " , "Bar " , "bAr " );
118
+ foreach ($ keys as $ key ) {
119
+ $ document = new Document ();
120
+ $ document ->someAttribute = 'someValue ' ;
121
+ $ document ->set ('_key ' , $ key );
122
+ $ documentId = $ documentHandler ->add ($ collection ->getName (), $ document );
123
+
124
+ $ resultingDocument = $ documentHandler ->get ($ collection ->getName (), $ documentId );
125
+
126
+ $ resultingAttribute = $ resultingDocument ->someAttribute ;
127
+ $ resultingKey = $ resultingDocument ->getKey ();
128
+ $ this ->assertTrue (
129
+ $ resultingAttribute === 'someValue ' ,
130
+ 'Resulting Attribute should be "someValue". It \'s : ' . $ resultingAttribute
131
+ );
132
+ $ this ->assertTrue (
133
+ $ resultingKey === $ key ,
134
+ 'Resulting Attribute should be "someValue". It \'s : ' . $ resultingKey
135
+ );
136
+
137
+ $ documentHandler ->delete ($ document );
138
+ }
139
+ }
140
+
141
+
142
+ /**
143
+ * Try to create a document with invalid keys
144
+ */
145
+ public function testCreateDocumentWithInvalidKeys ()
146
+ {
147
+ $ connection = $ this ->connection ;
148
+ $ collection = $ this ->collection ;
149
+ $ documentHandler = new DocumentHandler ($ connection );
150
+
151
+ $ keys = array ("" , " " , " bar " , "bar " , "/ " , "? " , "abcdef gh " , "abcxde& " , "mötörhead " , "this-key-will-be-too-long-to-be-processed-successfully-would-you-agree-with-me-sure-you-will-because-there-is-a-limit-of-254-characters-per-key-which-this-string-will-not-conform-to-if-you-are-still-reading-this-you-should-probably-do-something-else-right-now-REALLY " );
152
+
153
+ foreach ($ keys as $ key ) {
154
+ $ document = new Document ();
155
+ $ document ->someAttribute = 'someValue ' ;
156
+
157
+ $ caught = false ;
158
+ try {
159
+ $ document ->set ('_key ' , $ key );
160
+ } catch (\triagens \ArangoDb \ClientException $ exception ) {
161
+ $ caught = true ;
162
+ }
163
+
164
+ $ this ->assertTrue ($ caught , "expecting exception to be thrown for key " . $ key );
165
+ }
166
+ }
107
167
108
168
109
169
/**
0 commit comments