1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dynamic\DynamicBlocks\Test; |
4
|
|
|
|
5
|
|
|
use Dynamic\DynamicBlocks\Block\AccordionBlock; |
6
|
|
|
use Dynamic\DynamicBlocks\Block\AccordionBlockController; |
7
|
|
|
use SilverStripe\Core\Config\Config; |
8
|
|
|
use SilverStripe\Dev\FunctionalTest; |
9
|
|
|
use SilverStripe\Dev\SapphireTest; |
10
|
|
|
use SilverStripe\Forms\FieldList; |
11
|
|
|
|
12
|
|
View Code Duplication |
class AccordionBlockTest extends SapphireTest |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
protected static $fixture_file = 'dynamic-blocks/tests/Fixtures.yml'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* |
21
|
|
|
*/ |
22
|
|
|
public function testGetPluralName() |
23
|
|
|
{ |
24
|
|
|
$object = singleton(AccordionBlock::class); |
25
|
|
|
$this->assertEquals('Accordion Blocks', $object->plural_name()); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* |
30
|
|
|
*/ |
31
|
|
|
public function testGetCMSFields() |
32
|
|
|
{ |
33
|
|
|
$object = $this->objFromFixture(AccordionBlock::class, 'one'); |
34
|
|
|
$fields = $object->getCMSFields(); |
35
|
|
|
$this->assertInstanceOf(FieldList::class, $fields); |
36
|
|
|
$this->assertNotNull($fields->dataFieldByName('Panels')); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* |
41
|
|
|
*/ |
42
|
|
|
public function testGetPanelList() |
43
|
|
|
{ |
44
|
|
|
$object = $this->objFromFixture(AccordionBlock::class, 'one'); |
45
|
|
|
$panels = $object->Panels()->sort('Sort'); |
46
|
|
|
$this->assertEquals($panels, $object->getPanelList()); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
class AccordionBlockControllerTest extends FunctionalTest |
|
|
|
|
51
|
|
|
{ |
52
|
|
|
/** |
53
|
|
|
* |
54
|
|
|
*/ |
55
|
|
|
public function testAccordionClass() |
56
|
|
|
{ |
57
|
|
|
$object = singleton(AccordionBlockController::class); |
58
|
|
|
$expected = Config::inst()->get(AccordionBlockController::class, 'accordion_class'); |
59
|
|
|
$this->assertEquals($object->AccordionClass(), $expected); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.