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
|
|
|
$this->assertEquals('Test Gallery 1', $page->InlineGalleries()->first()->Title); |
36
|
|
|
$this->assertEquals(1, $page->InlineGalleries()->count()); |
37
|
|
|
|
38
|
|
|
// Now add child galleries as well |
39
|
|
|
$gallery2 = $this->objFromFixture('GalleryPage', 'gp02'); |
40
|
|
|
$gallery2->ParentID = $page->ID; |
41
|
|
|
$gallery2->write(); |
42
|
|
|
|
43
|
|
|
$gallery3 = $this->objFromFixture('GalleryPage', 'gp03'); |
44
|
|
|
$gallery3->ParentID = $page->ID; |
45
|
|
|
$gallery3->write(); |
46
|
|
|
|
47
|
|
|
$this->assertEquals(3, $page->InlineGalleries()->count()); |
48
|
|
|
$titles = array(); |
49
|
|
|
foreach ($page->InlineGalleries() as $gallery) { |
50
|
|
|
array_push($titles, $gallery->Title); |
51
|
|
|
} |
52
|
|
|
$expected = array('Test Gallery 2', 'Test Gallery 3', 'Test Gallery 1'); |
53
|
|
|
$this->assertEquals($expected, $titles); |
54
|
|
|
Page::remove_extension('AttachedGalleryExtension'); |
55
|
|
|
|
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
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.