|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class AttachedGalleryExtensionTest extends TestWithImage { |
|
|
|
|
|
|
4
|
|
|
protected static $fixture_file = 'ss3gallery/tests/ss3gallery.yml'; |
|
5
|
|
|
|
|
6
|
|
|
/* |
|
7
|
|
|
Check for the attached gallery tab, and that a gallery can be attached |
|
8
|
|
|
*/ |
|
9
|
|
|
public function testGetCMSFields() |
|
10
|
|
|
{ |
|
11
|
|
|
Page::add_extension('AttachedGalleryExtension'); |
|
12
|
|
|
$page = new Page(); |
|
13
|
|
|
|
|
14
|
|
|
$tab = $page->getCMSFields()->fieldByName('Root.AttachedGallery'); |
|
15
|
|
|
$fields = $tab->FieldList(); |
|
16
|
|
|
$names = array(); |
|
17
|
|
|
foreach ($fields as $field) { |
|
18
|
|
|
array_push($names, $field->getName()); |
|
19
|
|
|
} |
|
20
|
|
|
$expected = array('AttachedGalleryID'); |
|
21
|
|
|
$this->assertEquals($expected, $names); |
|
|
|
|
|
|
22
|
|
|
Page::remove_extension('AttachedGalleryExtension'); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function testInlineGalleries() { |
|
26
|
|
|
Page::add_extension('AttachedGalleryExtension'); |
|
27
|
|
|
// this page is alone at the top level |
|
28
|
|
|
$page = $this->objFromFixture('Page', 'page02'); |
|
29
|
|
|
$this->assertEquals(0, $page->InlineGalleries()->count()); |
|
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
// Check for an attached gallery |
|
32
|
|
|
$gallery1 = $this->objFromFixture('GalleryPage', 'gp01'); |
|
33
|
|
|
$page->AttachedGalleryID = $gallery1->ID; |
|
34
|
|
|
$page->write(); |
|
35
|
|
|
$expected = array($page); |
|
|
|
|
|
|
36
|
|
|
$this->assertEquals('Test Gallery 1', $page->InlineGalleries()->first()->Title); |
|
|
|
|
|
|
37
|
|
|
$this->assertEquals(1, $page->InlineGalleries()->count()); |
|
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
// Now add child galleries as well |
|
40
|
|
|
$gallery2 = $this->objFromFixture('GalleryPage', 'gp02'); |
|
41
|
|
|
$gallery2->ParentID = $page->ID; |
|
42
|
|
|
$gallery2->write(); |
|
43
|
|
|
|
|
44
|
|
|
$gallery3 = $this->objFromFixture('GalleryPage', 'gp03'); |
|
45
|
|
|
$gallery3->ParentID = $page->ID; |
|
46
|
|
|
$gallery3->write(); |
|
47
|
|
|
|
|
48
|
|
|
$this->assertEquals(3, $page->InlineGalleries()->count()); |
|
|
|
|
|
|
49
|
|
|
$titles = array(); |
|
50
|
|
|
foreach ($page->InlineGalleries() as $gallery) { |
|
51
|
|
|
array_push($titles, $gallery->Title); |
|
52
|
|
|
} |
|
53
|
|
|
$expected = array('Test Gallery 2', 'Test Gallery 3', 'Test Gallery 1'); |
|
54
|
|
|
$this->assertEquals($expected, $titles); |
|
|
|
|
|
|
55
|
|
|
Page::remove_extension('AttachedGalleryExtension'); |
|
56
|
|
|
|
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.