@@ -76,11 +76,17 @@ public function test_tag_sources_identifier(tag_source $source) {
76
76
* @dataProvider tag_source_provider
77
77
*/
78
78
public function test_tag_sources_value (tag_source $ source ) {
79
- // Ensure tag value is < 256 chars, to fit AWS & Azure spec.
79
+ // Ensure tag value is < 128 chars, AWS & Azure spec allow for 256, but we reserve 128 for future use .
80
80
$ file = $ this ->create_duplicated_object ();
81
81
$ value = $ source ->get_value_for_contenthash ($ file ->contenthash );
82
+
83
+ // Null value - allowed, but means we cannot test.
84
+ if (is_null ($ value )) {
85
+ return ;
86
+ }
87
+
82
88
$ count = strlen ($ value );
83
- $ this ->assertLessThan (256 , $ count );
89
+ $ this ->assertLessThan (128 , $ count );
84
90
$ this ->assertGreaterThan (0 , $ count );
85
91
}
86
92
@@ -135,66 +141,43 @@ public function test_is_tagging_enabled_and_supported(bool $enabledinconfig, boo
135
141
$ this ->assertEquals ($ expected , tag_manager::is_tagging_enabled_and_supported ());
136
142
}
137
143
138
- /**
139
- * Tests query_local_tags
140
- * @covers \tool_objectfs\local\tag_manager::query_local_tags
141
- */
142
- public function test_query_local_tags () {
143
- global $ DB ;
144
+ public function test_gather_object_tags_for_upload () {
145
+ $ object = $ this ->create_duplicated_object ();
146
+ $ tags = tag_manager::gather_object_tags_for_upload ($ object ->contenthash );
144
147
145
- // Setup some fake tag data.
146
- $ DB ->insert_records ('tool_objectfs_object_tags ' , [
147
- [
148
- 'contenthash ' => 'abc123 ' ,
149
- 'tagkey ' => 'test ' ,
150
- 'tagvalue ' => 'test ' ,
151
- 'timemodified ' => time ()
152
- ],
153
- [
154
- 'contenthash ' => 'abc123 ' ,
155
- 'tagkey ' => 'test2 ' ,
156
- 'tagvalue ' => 'test2 ' ,
157
- 'timemodified ' => time ()
158
- ]
159
- ]);
160
-
161
- $ this ->assertCount (2 , tag_manager::query_local_tags ('abc123 ' ));
162
- $ this ->assertCount (0 , tag_manager::query_local_tags ('doesnotexist ' ));
148
+ $ this ->assertArrayHasKey ('mimetype ' , $ tags );
149
+ $ this ->assertArrayHasKey ('environment ' , $ tags );
150
+ $ this ->assertEquals ('text ' , $ tags ['mimetype ' ]);
151
+ $ this ->assertEquals ('test ' , $ tags ['environment ' ]);
163
152
}
164
153
165
- /**
166
- * Tests update_tags_if_necessary
167
- * @covers \tool_objectfs\local\tag_manager::update_tags_if_necessary
168
- */
169
- public function test_update_tags_if_necessary () {
154
+ public function test_store_tags_locally () {
170
155
global $ DB ;
171
156
172
- // There should be no existing tags to begin with.
173
- $ this -> assertEmpty (tag_manager:: query_local_tags ( ' test ' ));
174
-
175
- // Update tags if necessary - should update the tags.
176
- tag_manager:: update_tags_if_necessary ( ' test ' ) ;
157
+ $ tags = [
158
+ ' test1 ' => ' abc ' ,
159
+ ' test2 ' => ' xyz '
160
+ ];
161
+ $ hash = ' thisisatest ' ;
177
162
178
- // Query tags - should be equal to number defined by the manager.
179
- $ expectedcount = count (tag_manager::get_defined_tag_sources ());
180
- $ this ->assertCount ($ expectedcount , tag_manager::query_local_tags ('test ' ), 'Tags created match the number defined by manager ' );
163
+ // Ensure no tags for hash intially.
164
+ $ this ->assertEmpty ($ DB ->get_records ('tool_objectfs_object_tags ' , ['contenthash ' => $ hash ]));
181
165
182
- // Note the timemodified of one of the tags.
183
- $ timemodified = $ DB ->get_field ('tool_objectfs_object_tags ' , 'timemodified ' , ['contenthash ' => 'test ' , 'tagkey ' => tag_manager::get_defined_tag_sources ()[0 ]->get_identifier ()]);
184
-
185
- // Running again, timemodified should not change.
186
- $ this ->waitForSecond ();
187
- tag_manager::update_tags_if_necessary ('test ' );
166
+ // Store.
167
+ tag_manager::store_tags_locally ($ hash , $ tags );
188
168
189
- $ newtimemodified = $ DB ->get_field ('tool_objectfs_object_tags ' , 'timemodified ' , ['contenthash ' => 'test ' , 'tagkey ' => tag_manager::get_defined_tag_sources ()[0 ]->get_identifier ()]);
190
- $ this ->assertEquals ($ timemodified , $ newtimemodified , 'Tags timemodified must not change if not forced and values are not different ' );
169
+ // Confirm they are stored.
170
+ $ queriedtags = $ DB ->get_records ('tool_objectfs_object_tags ' , ['contenthash ' => $ hash ]);
171
+ $ this ->assertCount (2 , $ queriedtags );
172
+ $ tagtimebefore = current ($ queriedtags )->timemodified ;
191
173
192
- // Except if it is forced .
174
+ // Re-store, confirm times changed .
193
175
$ this ->waitForSecond ();
194
- tag_manager::update_tags_if_necessary ('test ' , true );
195
-
196
- $ timemodifiedafterforce = $ DB ->get_field ('tool_objectfs_object_tags ' , 'timemodified ' , ['contenthash ' => 'test ' , 'tagkey ' => tag_manager::get_defined_tag_sources ()[0 ]->get_identifier ()]);
197
- $ this ->assertNotEquals ($ timemodified , $ timemodifiedafterforce , 'Forced tag update changed time modified ' );
176
+ tag_manager::store_tags_locally ($ hash , $ tags );
177
+ $ queriedtags = $ DB ->get_records ('tool_objectfs_object_tags ' , ['contenthash ' => $ hash ]);
178
+ $ tagtimeafter = current ($ queriedtags )->timemodified ;
179
+
180
+ $ this ->assertNotSame ($ tagtimebefore , $ tagtimeafter );
198
181
}
199
182
200
183
/**
@@ -288,27 +271,9 @@ public function test_get_objects_needing_sync_limit() {
288
271
$ this ->assertCount (1 , tag_manager::get_objects_needing_sync (1 ));
289
272
}
290
273
291
- /**
292
- * Tests replicate_local_to_external_tags_for_object
293
- * @covers \tool_objectfs\local\tag_manager::replicate_local_to_external_tags_for_object
294
- */
295
- public function test_replicate_local_to_external_tags_for_object () {
296
- global $ DB ;
297
-
298
- // Enable tagging, setup test fs.
299
- $ config = manager::get_objectfs_config ();
300
- $ config ->taggingenabled = true ;
301
- $ config ->enabletasks = true ;
302
- $ config ->filesystem = '\\tool_objectfs \\tests \\test_file_system ' ;
303
- manager::set_objectfs_config ($ config );
304
-
305
- // Setup object, mark as needing sync.
306
- $ object = $ this ->create_remote_object ();
307
- $ DB ->set_field ('tool_objectfs_objects ' , 'tagsyncstatus ' , tag_manager::SYNC_STATUS_NEEDS_SYNC , ['id ' => $ object ->id ]);
308
- tag_manager::replicate_local_to_external_tags_for_object ($ object ->contenthash );
309
-
310
- // Ensure status is now set as not needing sync.
311
- $ status = $ DB ->get_field ('tool_objectfs_objects ' , 'tagsyncstatus ' , ['id ' => $ object ->id ]);
312
- $ this ->assertEquals (tag_manager::SYNC_STATUS_SYNC_NOT_REQUIRED , $ status );
274
+ public function test_get_tag_summary_html () {
275
+ // Quick test just to ensure it generates and nothing explodes.
276
+ $ html = tag_manager::get_tag_summary_html ();
277
+ $ this ->assertIsString ($ html );
313
278
}
314
279
}
0 commit comments