Passed
Pull Request — master (#344)
by
unknown
03:08
created

FixtureContext::theHasAContentElementWithContent()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 15
nc 4
nop 4
dl 0
loc 25
rs 9.7666
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 13 and the first side effect is on line 8.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
namespace DNADesign\Elemental\Tests\Behat\Context;
3
4
use DNADesign\Elemental\Models\ElementContent;
5
use SilverStripe\BehatExtension\Context\FixtureContext as BaseFixtureContext;
6
7
if (!class_exists(BaseFixtureContext::class)) {
8
    return;
9
}
10
/**
11
 * Context used to create fixtures in the SilverStripe ORM.
12
 */
13
class FixtureContext extends BaseFixtureContext
14
{
15
    /**
16
     * @Given /(?:the|a) "([^"]+)" "([^"]+)" (?:with|has) a "([^"]+)" content element with "([^"]+)" content/
17
     *
18
     * @param string $pageTitle
19
     * @param string $type
20
     * @param string $elementTitle
21
     * @param string $elementContent
22
     */
23
    public function theHasAContentElementWithContent($type, $pageTitle, $elementTitle, $elementContent)
24
    {
25
        // Create the page (ElementalArea is created on write and attached to it)
26
        $targetClass = $this->convertTypeToClass($type);
27
28
        $page = $this->getFixtureFactory()->get($targetClass, $pageTitle);
29
        if (!$page) {
0 ignored issues
show
introduced by
$page is of type SilverStripe\ORM\DataObject, thus it always evaluated to true.
Loading history...
30
            $page = $this->getFixtureFactory()->createObject($targetClass, $pageTitle);
31
        }
32
33
        $elementalArea = $page->ElementalArea();
34
        $elementalArea->Elements()->add($this->getFixtureFactory()->createObject(ElementContent::class, $elementTitle));
35
36
        // Create element
37
        $element = $this->getFixtureFactory()->get(ElementContent::class, $elementTitle);
38
39
        if ($element) {
0 ignored issues
show
introduced by
$element is of type SilverStripe\ORM\DataObject, thus it always evaluated to true.
Loading history...
40
            $element->HTML = $elementContent;
41
            $element->write();
42
        } else {
43
            $element = $this->getFixtureFactory()->createObject(ElementContent::class, $elementTitle, [
44
                'Title' => $elementTitle,
45
                'HTML' => $elementContent
46
            ]);
47
            $element->write();
48
        }
49
    }
50
51
    /**
52
     * @Given content blocks are not in-line editable
53
     *
54
     * @param $elementTitle
55
     */
56
    public function contentBlocksAreNotInLineEditable()
57
    {
58
        $contentBlockClass = ElementContent::class;
59
        $config = <<<YAML
60
---
61
Name: testonly-content-blocks-not-inline-editable
62
---
63
$contentBlockClass:
64
  inline_editable: false
65
YAML;
66
67
        $file = 'content-blocks-not-inline-editable.yml';
68
        $path = $this->getDestinationConfigFolder($file);
0 ignored issues
show
Bug introduced by
The method getDestinationConfigFolder() does not exist on DNADesign\Elemental\Test...\Context\FixtureContext. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

68
        /** @scrutinizer ignore-call */ 
69
        $path = $this->getDestinationConfigFolder($file);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
69
        file_put_contents($path, $config);
70
71
        $this->activatedConfigFiles[] = $path;
0 ignored issues
show
Bug Best Practice introduced by
The property activatedConfigFiles does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
72
73
        $this->getMainContext()->visit('/?flush');
74
    }
75
76
77
}
78