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

NodeContext   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 1 Features 2
Metric Value
wmc 6
c 2
b 1
f 2
lcom 1
cbo 2
dl 0
loc 27
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A visitNode() 0 8 2
A editNode() 0 9 4
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