1+ <?php
2+
3+ namespace SheaDawson \Blocks \Test ;
4+
5+ use SheaDawson \Blocks \Model \BlockSet ;
6+ use SilverStripe \Dev \SapphireTest ;
7+ use SilverStripe \Forms \FieldList ;
8+ use SilverStripe \Security \Member ;
9+
10+ class BlockSetTest extends SapphireTest
11+ {
12+ /**
13+ * @var string
14+ */
15+ protected static $ fixture_file = 'fixtures.yml ' ;
16+
17+ /**
18+ *
19+ */
20+ public function testGetCMSFields ()
21+ {
22+ $ object = $ this ->objFromFixture (BlockSet::class, 'default ' );
23+ $ fields = $ object ->getCMSFields ();
24+ $ this ->assertInstanceOf (FieldList::class, $ fields );
25+ }
26+
27+ /**
28+ *
29+ */
30+ public function testCanView ()
31+ {
32+ $ object = $ this ->objFromFixture (BlockSet::class, 'default ' );
33+ $ admin = $ this ->objFromFixture (Member::class, 'admin ' );
34+ $ this ->assertTrue ($ object ->canView ($ admin ));
35+ $ member = $ this ->objFromFixture (Member::class, 'default ' );
36+ $ this ->assertTrue ($ object ->canView ($ member ));
37+ }
38+
39+ /**
40+ *
41+ */
42+ public function testCanEdit ()
43+ {
44+ $ object = $ this ->objFromFixture (BlockSet::class, 'default ' );
45+ $ admin = $ this ->objFromFixture (Member::class, 'admin ' );
46+ $ this ->assertTrue ($ object ->canEdit ($ admin ));
47+ $ member = $ this ->objFromFixture (Member::class, 'default ' );
48+ $ this ->assertFalse ($ object ->canEdit ($ member ));
49+ }
50+
51+ /**
52+ *
53+ */
54+ public function testCanDelete ()
55+ {
56+ $ object = $ this ->objFromFixture (BlockSet::class, 'default ' );
57+ $ admin = $ this ->objFromFixture (Member::class, 'admin ' );
58+ $ this ->assertTrue ($ object ->canDelete ($ admin ));
59+ $ member = $ this ->objFromFixture (Member::class, 'default ' );
60+ $ this ->assertFalse ($ object ->canDelete ($ member ));
61+ }
62+
63+ /**
64+ *
65+ */
66+ public function testCanCreate ()
67+ {
68+ $ object = $ this ->objFromFixture (BlockSet::class, 'default ' );
69+ $ admin = $ this ->objFromFixture (Member::class, 'admin ' );
70+ $ this ->assertTrue ($ object ->canCreate ($ admin ));
71+ $ member = $ this ->objFromFixture (Member::class, 'default ' );
72+ $ this ->assertFalse ($ object ->canCreate ($ member ));
73+ }
74+
75+ /**
76+ *
77+ */
78+ public function testProvidePermissions ()
79+ {
80+ $ object = singleton (BlockSet::class);
81+ $ expected = [
82+ 'BLOCKSET_EDIT ' => [
83+ 'name ' => _t ('BlockSet.EditBlockSet ' ,'Edit a Block Set ' ),
84+ 'category ' => _t ('Block.PermissionCategory ' , 'Blocks ' ),
85+ ],
86+ 'BLOCKSET_DELETE ' => [
87+ 'name ' => _t ('BlockSet.DeleteBlockSet ' ,'Delete a Block Set ' ),
88+ 'category ' => _t ('Block.PermissionCategory ' , 'Blocks ' ),
89+ ],
90+ 'BLOCKSET_CREATE ' => [
91+ 'name ' => _t ('BlockSet.CreateBlockSet ' ,'Create a Block Set ' ),
92+ 'category ' => _t ('Block.PermissionCategory ' , 'Blocks ' ),
93+ ],
94+ ];
95+
96+ $ this ->assertEquals ($ expected , $ object ->providePermissions ());
97+ }
98+ }
0 commit comments