11
11
12
12
namespace PHPCR \Tests \Versioning ;
13
13
14
+ use Jackalope \Property ;
15
+ use PHPCR \PathNotFoundException ;
14
16
use PHPCR \Util \PathHelper ;
15
17
use PHPCR \Version \VersionHistoryInterface ;
16
18
use PHPCR \Version \VersionManagerInterface ;
@@ -123,7 +125,6 @@ public function testGetAllLinearVersions()
123
125
$ this ->assertCount (1 , $ lastVersion ->getPredecessors ());
124
126
$ this ->assertCount (0 , $ lastVersion ->getSuccessors ());
125
127
}
126
-
127
128
public function testGetAllVersions ()
128
129
{
129
130
// TODO: have non linear version history
@@ -148,7 +149,6 @@ public function testGetAllVersions()
148
149
$ this ->assertCount (1 , $ lastVersion ->getPredecessors ());
149
150
$ this ->assertCount (0 , $ lastVersion ->getSuccessors ());
150
151
}
151
-
152
152
/**
153
153
* Check version history (allVersions), add more versions, then check the history updates correctly.
154
154
*/
@@ -310,6 +310,125 @@ public function testDeleteUnexistingVersion()
310
310
$ history ->removeVersion ('unexisting ' );
311
311
}
312
312
313
+ /**
314
+ * Try to load Version by unexisting label
315
+ * @expectedException \PHPCR\Version\VersionException
316
+ */
317
+ public function testUnexistingGetVersionByLabel ()
318
+ {
319
+ $ history = $ this ->vm ->getVersionHistory ('/tests_version_base/versioned ' );
320
+
321
+ $ history ->getVersionByLabel ('definitlyNotSetLabel ' );
322
+ }
323
+
324
+ /**
325
+ * Try to add label to a version
326
+ */
327
+ public function testAddLabel ()
328
+ {
329
+ $ history = $ this ->vm ->getVersionHistory ('/tests_version_base/versioned ' );
330
+ $ history ->addVersionLabel ('1.0 ' , 'stable ' , false );
331
+ $ history ->setChildrenDirty ();
332
+
333
+ $ node = $ history ->getNode ('jcr:versionLabels ' );
334
+ try {
335
+ $ property = $ node ->getProperty ('stable ' );
336
+ } catch (PathNotFoundException $ e ) {
337
+ $ this ->fail ('the path "stable" should be found ' );
338
+ }
339
+ }
340
+
341
+ /**
342
+ * Load Version by label
343
+ *
344
+ * @depends testAddLabel
345
+ */
346
+ public function testGetVersionByLabel ()
347
+ {
348
+ $ history = $ this ->vm ->getVersionHistory ('/tests_version_base/versioned ' );
349
+ $ history ->addVersionLabel ('1.0 ' , 'stable ' , false );
350
+
351
+ $ expectedVersion = $ history ->getVersion ('1.0 ' );
352
+ $ actualVersion = $ history ->getVersionByLabel ('stable ' );
353
+
354
+ $ this ->assertEquals ($ expectedVersion ->getIdentifier (), $ actualVersion ->getIdentifier ());
355
+ }
356
+
357
+ /**
358
+ * Try to check, if version has label
359
+ *
360
+ * @depends testAddLabel
361
+ */
362
+ public function testHasVersionLabel ()
363
+ {
364
+ $ history = $ this ->vm ->getVersionHistory ('/tests_version_base/versioned ' );
365
+ $ history ->addVersionLabel ('1.0 ' , 'stable ' , false );
366
+ $ history ->addVersionLabel ('1.0 ' , 'labelname ' , false );
367
+ $ history ->addVersionLabel ('1.1 ' , 'anotherlabelname ' , false );
368
+
369
+ $ version = $ history ->getVersion ('1.0 ' );
370
+
371
+ $ this ->assertFalse ($ history ->hasVersionLabel ('unsetlabel ' ));
372
+ $ this ->assertFalse ($ history ->hasVersionLabel ('unsetlabel ' , $ version ));
373
+
374
+ $ this ->assertTrue ($ history ->hasVersionLabel ('stable ' ));
375
+ $ this ->assertTrue ($ history ->hasVersionLabel ('stable ' , $ version ));
376
+
377
+ $ this ->assertFalse ($ history ->hasVersionLabel ('anotherlabelname ' , $ version ));
378
+ $ this ->assertFalse ($ history ->hasVersionLabel ('unsetlabel ' , $ version ));
379
+ }
380
+
381
+ /**
382
+ * Try to get labels from version history
383
+ *
384
+ * @depends testAddLabel
385
+ */
386
+ public function testGetVersionLabels ()
387
+ {
388
+ $ history = $ this ->vm ->getVersionHistory ('/tests_version_base/versioned ' );
389
+ $ history ->addVersionLabel ('1.0 ' , 'stable ' , false );
390
+ $ history ->addVersionLabel ('1.0 ' , 'labelname ' , false );
391
+ $ history ->addVersionLabel ('1.1 ' , 'anotherlabelname ' , false );
392
+
393
+ $ version = $ history ->getVersion ('1.0 ' );
394
+
395
+ $ labels = $ history ->getVersionLabels ($ version );
396
+ $ this ->assertEquals (2 , count ($ labels ));
397
+ $ this ->assertTrue (in_array ('stable ' , $ labels ));
398
+ $ this ->assertTrue (in_array ('labelname ' , $ labels ));
399
+
400
+ $ labels = $ history ->getVersionLabels ();
401
+ $ this ->assertEquals (3 , count ($ labels ));
402
+ $ this ->assertTrue (in_array ('stable ' , $ labels ));
403
+ $ this ->assertTrue (in_array ('labelname ' , $ labels ));
404
+ $ this ->assertTrue (in_array ('anotherlabelname ' , $ labels ));
405
+ }
406
+
407
+ /**
408
+ * removes label from a version
409
+ *
410
+ * @depends testAddLabel
411
+ */
412
+ public function testRemoveLabel ()
413
+ {
414
+ $ history = $ this ->vm ->getVersionHistory ('/tests_version_base/versioned ' );
415
+ $ history ->addVersionLabel ('1.0 ' , 'toremove ' , false );
416
+
417
+ $ history ->removeVersionLabel ('toremove ' );
418
+
419
+ $ this ->assertFalse ($ history ->hasVersionLabel ('toremove ' ));
420
+ }
421
+
422
+ /**
423
+ * Try to remove unset label from a version.
424
+ * @expectedException \PHPCR\Version\VersionException
425
+ */
426
+ public function testRemoveUnsetLabel ()
427
+ {
428
+ $ history = $ this ->vm ->getVersionHistory ('/tests_version_base/versioned ' );
429
+ $ history ->removeVersionLabel ('unsetLabel ' );
430
+ }
431
+
313
432
/**
314
433
* Check if a version node with the given name exists in the version history.
315
434
*
@@ -328,6 +447,4 @@ protected function versionExists($history, $versionName)
328
447
329
448
return false ;
330
449
}
331
-
332
- // TODO: missing addVersionlabel, getVersionByLabel, getVersionLabels, hasVersionLabel, removeVersionLabel
333
450
}
0 commit comments