|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverStripe\CampaignAdmin\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\CampaignAdmin\SiteTreeExtension; |
|
6
|
|
|
use SilverStripe\CMS\Model\SiteTree; |
|
7
|
|
|
use SilverStripe\Dev\SapphireTest; |
|
8
|
|
|
use SilverStripe\Versioned\Versioned; |
|
9
|
|
|
|
|
10
|
|
|
class SiteTreeExtensionTest extends SapphireTest |
|
11
|
|
|
{ |
|
12
|
|
|
protected $usesDatabase = true; |
|
13
|
|
|
|
|
14
|
|
|
protected static $required_extensions = [ |
|
15
|
|
|
SiteTree::class => [ |
|
16
|
|
|
SiteTreeExtension::class, |
|
17
|
|
|
], |
|
18
|
|
|
]; |
|
19
|
|
|
|
|
20
|
|
|
public function testAddToCampaignButtonIsAdded() |
|
21
|
|
|
{ |
|
22
|
|
|
$this->logInWithPermission(); |
|
23
|
|
|
|
|
24
|
|
|
$page = new SiteTree(); |
|
25
|
|
|
$page->CanEditType = 'LoggedInUsers'; |
|
26
|
|
|
$page->write(); |
|
27
|
|
|
$page->publishRecursive(); |
|
28
|
|
|
$actions = $page->getCMSActions(); |
|
29
|
|
|
|
|
30
|
|
|
$addToCampaignAction = $actions->dataFieldByName('action_addtocampaign'); |
|
31
|
|
|
$this->assertNotNull($addToCampaignAction, 'Add To Campaign button should have been added'); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function testAddToCampaignButtonIsNotAddedWhenUserDoesNotHavePermission() |
|
35
|
|
|
{ |
|
36
|
|
|
$this->logInWithPermission('EDIT_PERMISSIONS'); |
|
37
|
|
|
|
|
38
|
|
|
$page = new SiteTree(); |
|
39
|
|
|
$page->CanEditType = 'LoggedInUsers'; |
|
40
|
|
|
$page->write(); |
|
41
|
|
|
$page->publishRecursive(); |
|
42
|
|
|
$actions = $page->getCMSActions(); |
|
43
|
|
|
|
|
44
|
|
|
$addToCampaignAction = $actions->dataFieldByName('action_addtocampaign'); |
|
45
|
|
|
$this->assertNull( |
|
46
|
|
|
$addToCampaignAction, |
|
47
|
|
|
'Add To Campaign button should not be shown to users without permission' |
|
48
|
|
|
); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function testActionsDeletedFromStageRecord() |
|
52
|
|
|
{ |
|
53
|
|
|
$this->logInWithPermission(); |
|
54
|
|
|
|
|
55
|
|
|
$page = new SiteTree(); |
|
56
|
|
|
$page->CanEditType = 'LoggedInUsers'; |
|
57
|
|
|
$pageID = $page->write(); |
|
58
|
|
|
$page->publishRecursive(); |
|
59
|
|
|
$page->deleteFromStage('Stage'); |
|
60
|
|
|
|
|
61
|
|
|
// Get the live version of the page |
|
62
|
|
|
$page = Versioned::get_one_by_stage(SiteTree::class, "Live", "\"SiteTree\".\"ID\" = $pageID"); |
|
63
|
|
|
$this->assertInstanceOf(SiteTree::class, $page); |
|
64
|
|
|
|
|
65
|
|
|
$actions = $page->getCMSActions(); |
|
66
|
|
|
|
|
67
|
|
|
// Theoretically allow deletions to be staged via add to campaign |
|
68
|
|
|
$this->assertNotNull($actions->dataFieldByName('action_addtocampaign')); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function testActionsChangedOnStageRecord() |
|
72
|
|
|
{ |
|
73
|
|
|
$this->logInWithPermission(); |
|
74
|
|
|
|
|
75
|
|
|
$page = new SiteTree(); |
|
76
|
|
|
$page->CanEditType = 'LoggedInUsers'; |
|
77
|
|
|
$page->write(); |
|
78
|
|
|
$page->publishRecursive(); |
|
79
|
|
|
$page->Content = 'Changed on Stage'; |
|
80
|
|
|
$page->write(); |
|
81
|
|
|
$page->flushCache(); |
|
82
|
|
|
|
|
83
|
|
|
// Reload latest version |
|
84
|
|
|
$page = SiteTree::get()->byID($page->ID); |
|
85
|
|
|
|
|
86
|
|
|
$actions = $page->getCMSActions(); |
|
87
|
|
|
$this->assertNotNull($actions->dataFieldByName('action_addtocampaign')); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|