Completed
Push — 1.0.x ( 0a17d9...7f19ee )
by Antonio
06:30
created

Generic::iShouldSeeTheField()   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 17
Code Lines 9

Duplication

Lines 17
Ratio 100 %

Importance

Changes 0
Metric Value
dl 17
loc 17
c 0
b 0
f 0
rs 8.8571
cc 5
eloc 9
nc 6
nop 1
1
<?php
2
3
namespace NuvoleWeb\Drupal\DrupalExtension\Traits;
4
5
use Behat\Mink\Exception\ExpectationException;
6
7
/**
8
 * Trait Generic.
9
 *
10
 * @package Nuvole\Drupal\Behat\Traits
11
 */
12
trait Generic {
13
14
  /**
15
   * Visit taxonomy term page given its type and name.
16
   *
17
   * @Given I am visiting the :type term :title
18
   * @Given I visit the :type term :title
19
   */
20
  public function iAmViewingTheTerm($type, $title) {
21
    $this->visitTermPage('view', $type, $title);
22
  }
23
24
  /**
25
   * Visit taxonomy term edit page given its type and name.
26
   *
27
   * @Given I am editing the :type term :title
28
   * @Given I edit the :type term :title
29
   */
30
  public function iAmEditingTheTerm($type, $title) {
31
    $this->visitTermPage('edit', $type, $title);
32
  }
33
34
  /**
35
   * Provides a common step definition callback for node pages.
36
   *
37
   * @param string $op
38
   *   The operation being performed: 'view', 'edit', 'delete'.
39
   * @param string $type
40
   *   The node type either as id or as label.
41
   * @param string $title
42
   *   The node title.
43
   *
44
   * @throws ExpectationException
45
   *   When the node does not exist.
46
   */
47
  protected function visitTermPage($op, $type, $title) {
48
    $type = $this->convertLabelToTermTypeId($type);
0 ignored issues
show
Bug introduced by
It seems like convertLabelToTermTypeId() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
49
    $result = \Drupal::entityQuery('taxonomy_term')
50
      ->condition('vid', $type)
51
      ->condition('name', $title)
52
      ->execute();
53
54
    if (!empty($result)) {
55
      $tid = array_shift($result);
56
      $path = [
57
        'view' => "taxonomy/term/$tid",
58
        'edit' => "taxonomy/term/$tid/edit",
59
        'delete' => "taxonomy/term/$tid/delete",
60
      ];
61
      $this->visitPath($path[$op]);
0 ignored issues
show
Bug introduced by
It seems like visitPath() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
62
    }
63
    else {
64
      throw new ExpectationException("No term with vocabulary '$type' and title '$title' has been found.", $this->getSession());
0 ignored issues
show
Bug introduced by
It seems like getSession() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
65
    }
66
  }
67
68
}
69