1
|
|
|
<?php |
2
|
|
|
namespace SilverStripe\ElementalBannerBlock\Tests\Behat\Context; |
3
|
|
|
|
4
|
|
|
use Behat\Mink\Element\DocumentElement; |
|
|
|
|
5
|
|
|
use Behat\Mink\Element\NodeElement; |
|
|
|
|
6
|
|
|
use SilverStripe\Assets\Image; |
7
|
|
|
use SilverStripe\BehatExtension\Context\FixtureContext as BaseFixtureContext; |
|
|
|
|
8
|
|
|
use SilverStripe\ElementalBannerBlock\Block\BannerBlock; |
9
|
|
|
|
10
|
|
|
if (!class_exists(BaseFixtureContext::class)) { |
11
|
|
|
return; |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Context used to create fixtures in the SilverStripe ORM. |
16
|
|
|
*/ |
17
|
|
|
class FixtureContext extends BaseFixtureContext |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @Given /(?:the|a) "([^"]+)" "([^"]+)" (?:with|has) a "([^"]+)" banner element with "([^"]+)" content/ |
21
|
|
|
* |
22
|
|
|
* @Example Given a "page" "Blocks Page" with a "Alice's Block" banner element with "Some content" content |
23
|
|
|
* |
24
|
|
|
* @param string $pageTitle |
25
|
|
|
* @param string $type |
26
|
|
|
* @param string $elementTitle |
27
|
|
|
* @param string $elementContent |
28
|
|
|
* @param string $file |
29
|
|
|
* @param string $elementLink |
30
|
|
|
*/ |
31
|
|
|
public function aWithABannerElementWithContentAndAFileAndALink($type, $pageTitle, $elementTitle, $elementContent) |
32
|
|
|
{ |
33
|
|
|
// Create the page (ElementalArea is created on write and attached to it) |
34
|
|
|
$targetClass = $this->convertTypeToClass($type); |
35
|
|
|
|
36
|
|
|
$page = $this->getFixtureFactory()->get($targetClass, $pageTitle); |
37
|
|
|
if (!$page) { |
38
|
|
|
$page = $this->getFixtureFactory()->createObject($targetClass, $pageTitle); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
$element = $this->getFixtureFactory()->get(BannerBlock::class, $elementTitle); |
42
|
|
|
|
43
|
|
|
if (!$element) { |
44
|
|
|
$elementalArea = $page->ElementalArea(); |
45
|
|
|
$elementalArea |
46
|
|
|
->Elements() |
47
|
|
|
->add($this->getFixtureFactory()->createObject(BannerBlock::class, $elementTitle)); |
48
|
|
|
$element = $this->getFixtureFactory()->get(BannerBlock::class, $elementTitle); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$file = $this->getFixtureFactory()->get(Image::class, 'Uploads/folder1/file1.jpg'); |
52
|
|
|
|
53
|
|
|
$element->Content = $elementContent; |
54
|
|
|
$element->CallToActionLink = '{"PageID":1,"Text":"Link to home page","Description":"","TargetBlank":false}'; |
55
|
|
|
$element->FileID = $file->ID; |
56
|
|
|
$element->write(); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @Given content blocks are not in-line editable |
62
|
|
|
* |
63
|
|
|
* @param $elementTitle |
64
|
|
|
*/ |
65
|
|
|
public function contentBlocksAreNotInLineEditable() |
66
|
|
|
{ |
67
|
|
|
$contentBlockClass = BannerBlock::class; |
68
|
|
|
$config = <<<YAML |
69
|
|
|
--- |
70
|
|
|
Name: testonly-content-blocks-not-inline-editable |
71
|
|
|
--- |
72
|
|
|
$contentBlockClass: |
73
|
|
|
inline_editable: false |
74
|
|
|
YAML; |
75
|
|
|
|
76
|
|
|
$file = 'content-blocks-not-inline-editable.yml'; |
77
|
|
|
$path = $this->getDestinationConfigFolder($file); |
78
|
|
|
file_put_contents($path, $config); |
79
|
|
|
|
80
|
|
|
$this->activatedConfigFiles[] = $path; |
|
|
|
|
81
|
|
|
|
82
|
|
|
$this->getMainContext()->visit('/?flush'); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
// --------------------- The below is copied from asset admin ------------------------------- |
86
|
|
|
/** |
87
|
|
|
* Select a gallery item by type and name |
88
|
|
|
* |
89
|
|
|
* @Given /^I (?:(?:click on)|(?:select)) the (?:file|folder) named "([^"]+)" in the gallery$/ |
90
|
|
|
* @param string $name |
91
|
|
|
*/ |
92
|
|
|
public function stepISelectGalleryItem($name) |
93
|
|
|
{ |
94
|
|
|
$item = $this->getGalleryItem($name); |
95
|
|
|
assertNotNull($item, "File named $name could not be found"); |
96
|
|
|
$item->click(); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Helper for finding items in the visible gallery view |
101
|
|
|
* |
102
|
|
|
* @param string $name Title of item |
103
|
|
|
* @param int $timeout |
104
|
|
|
* @return NodeElement |
105
|
|
|
*/ |
106
|
|
|
protected function getGalleryItem($name, $timeout = 3) |
107
|
|
|
{ |
108
|
|
|
/** @var DocumentElement $page */ |
109
|
|
|
$page = $this->getMainContext()->getSession()->getPage(); |
110
|
|
|
// Find by cell |
111
|
|
|
$cell = $page->find( |
112
|
|
|
'xpath', |
113
|
|
|
"//div[contains(@class, 'gallery-item')]//div[contains(text(), '{$name}')]" |
114
|
|
|
); |
115
|
|
|
if ($cell) { |
116
|
|
|
return $cell; |
117
|
|
|
} |
118
|
|
|
// Find by row |
119
|
|
|
$row = $page->find( |
120
|
|
|
'xpath', |
121
|
|
|
"//tr[contains(@class, 'gallery__table-row')]//div[contains(text(), '{$name}')]" |
122
|
|
|
); |
123
|
|
|
if ($row) { |
124
|
|
|
return $row; |
125
|
|
|
} |
126
|
|
|
return null; |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths