Completed
Pull Request — master (#6)
by
unknown
02:17
created

NodeContext::editNode()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
c 1
b 1
f 1
dl 0
loc 9
rs 9.2
cc 4
eloc 5
nc 2
nop 0
1
<?php
2
/**
3
 * @author Cristina Eftimita, <[email protected]>
4
 */
5
namespace Drupal\TqExtension\Context\Node;
6
7
class NodeContext extends RawNodeContext
8
{
9
    /**
10
     * @When /^I (visit|view|edit) "([^"]+)" node of type "([^"]+)"$/
11
     */
12
    public function visitNode($operation, $title, $type) {
13
        if ('visit' === $operation) {
14
             $operation = 'view';
15
        }
16
        $nid = $this->getNodeIdByTitle($title, $type);
17
18
        $this->getRedirectContext()->visitPage("node/$nid/$operation");
19
    }
20
21
    /**
22
     * @When /^(?:|I )edit (?:this|current|the) node$/
23
     */
24
    public function editNode()
25
    {
26
        $args = arg();
27
        if (count($args) < 2 || ('node' !== $args[0] || $args[1] <= 0)) {
28
            throw new \RuntimeException(sprintf('Page "%s" is not a node. Unable to edit.', static::$pageUrl));
29
        }
30
31
        $this->getRedirectContext()->visitPage('node/' . $args[1] . '/edit');
32
    }
33
}
34