5
5
use BadMethodCallException ;
6
6
use PHPUnit \Framework \ExpectationFailedException ;
7
7
use SebastianBergmann \Comparator \ComparisonFailure ;
8
+ use SilverStripe \CampaignAdmin \AddToCampaignHandler ;
8
9
use SilverStripe \Dev \SapphireTest ;
9
10
use SilverStripe \ORM \DataObject ;
10
11
use SilverStripe \Versioned \ChangeSet ;
@@ -351,6 +352,21 @@ public function testCanPublish()
351
352
$ this ->logInWithPermission ('PERM_canPublish ' );
352
353
$ this ->assertTrue ($ changeSet ->canPublish ());
353
354
355
+ if (class_exists (AddToCampaignHandler::class)) {
356
+ // Test user with the necessary minimum permissions can login
357
+ $ this ->logInWithPermission (
358
+ [
359
+ 'CMS_ACCESS_CampaignAdmin ' ,
360
+ 'PERM_canPublish '
361
+ ]
362
+ );
363
+ $ this ->assertTrue ($ changeSet ->canPublish ());
364
+
365
+ // campaign admin only permission doesn't grant publishing rights
366
+ $ this ->logInWithPermission ('CMS_ACCESS_CampaignAdmin ' );
367
+ $ this ->assertFalse ($ changeSet ->canPublish ());
368
+ }
369
+
354
370
// Test that you can still publish a changeset, even if canPublish()
355
371
// returns false (e.g. externally rather than internally enforced)
356
372
$ changeSet ->publish ();
@@ -435,6 +451,10 @@ public function testCanEdit()
435
451
$ this ->assertFalse ($ changeSet ->canEdit ());
436
452
$ this ->logInWithPermission ('SomeWrongPermission ' );
437
453
$ this ->assertFalse ($ changeSet ->canEdit ());
454
+ if (class_exists (AddToCampaignHandler::class)) {
455
+ $ this ->logInWithPermission ('CMS_ACCESS_CampaignAdmin ' );
456
+ $ this ->assertTrue ($ changeSet ->canEdit ());
457
+ }
438
458
}
439
459
440
460
public function testCanCreate ()
@@ -444,6 +464,10 @@ public function testCanCreate()
444
464
$ this ->assertFalse (ChangeSet::singleton ()->canCreate ());
445
465
$ this ->logInWithPermission ('SomeWrongPermission ' );
446
466
$ this ->assertFalse (ChangeSet::singleton ()->canCreate ());
467
+ if (class_exists (AddToCampaignHandler::class)) {
468
+ $ this ->logInWithPermission ('CMS_ACCESS_CampaignAdmin ' );
469
+ $ this ->assertTrue (ChangeSet::singleton ()->canCreate ());
470
+ }
447
471
}
448
472
449
473
public function testCanDelete ()
@@ -462,6 +486,10 @@ public function testCanDelete()
462
486
$ this ->assertFalse ($ changeSet ->canDelete ());
463
487
$ this ->logInWithPermission ('SomeWrongPermission ' );
464
488
$ this ->assertFalse ($ changeSet ->canDelete ());
489
+ if (class_exists (AddToCampaignHandler::class)) {
490
+ $ this ->logInWithPermission ('CMS_ACCESS_CampaignAdmin ' );
491
+ $ this ->assertTrue ($ changeSet ->canDelete ());
492
+ }
465
493
}
466
494
467
495
public function testCanView ()
@@ -480,6 +508,10 @@ public function testCanView()
480
508
$ this ->assertFalse ($ changeSet ->canView ());
481
509
$ this ->logInWithPermission ('SomeWrongPermission ' );
482
510
$ this ->assertFalse ($ changeSet ->canView ());
511
+ if (class_exists (AddToCampaignHandler::class)) {
512
+ $ this ->logInWithPermission ('CMS_ACCESS_CampaignAdmin ' );
513
+ $ this ->assertTrue ($ changeSet ->canView ());
514
+ }
483
515
}
484
516
485
517
public function testPublish ()
0 commit comments