Completed
Pull Request — master (#315)
by
unknown
01:59
created

BlockContext::getTranslationResources()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Drupal\DrupalExtension\Context;
4
5
use Behat\MinkExtension\Context\RawMinkContext;
6
use Behat\Behat\Context\TranslatableContext;
7
8
/**
9
 * Extensions to the Mink Extension.
10
 */
11
class BlockContext extends RawDrupalContext implements TranslatableContext {
12
13
  /**
14
   * Returns list of definition translation resources paths.
15
   *
16
   * @return array
17
   */
18
  public static function getTranslationResources() {
19
    return glob(__DIR__ . '/../../../../i18n/*.xliff');
20
  }
21
22
  /**
23
   * @Given I place block :block in :region with weight :weight
24
   */
25
  public function assertPlaceBlock($block, $region, $weight) {
26
    // Perform the whole operation as an administrator.
27
    $role = 'administrator';
28
    $user = (object) array(
29
      'name' => $this->getRandom()->name(8),
30
      'pass' => $this->getRandom()->name(16),
31
      'role' => $role,
32
    );
33
    $user->mail = "{$user->name}@example.com";
34
    $this->userCreate($user);
35
    $roles = explode(',', $role);
36
    $roles = array_map('trim', $roles);
37 View Code Duplication
    foreach ($roles as $role) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
38
      if (!in_array(strtolower($role), array('authenticated', 'authenticated user'))) {
39
        $this->getDriver()->userAddRole($user, $role);
40
      }
41
    }
42
    $this->login($user);
43
44
    // Go to "admin/structure/blocks".
45
    $this->getSession()->visit($this->locatePath('admin/structure/block'));
46
    $page = $this->getSession()->getPage();
47
48
    // We do this so that we can set the weight.
49
    $page->clickLink('Show row weights');
50
51
    $page->find('named', array('select', $this->getSession()->getSelectorsHandler()->xpathLiteral("Region for $block block")))->selectOption($region);
0 ignored issues
show
Deprecated Code introduced by
The method Behat\Mink\Selector\Sele...Handler::xpathLiteral() has been deprecated with message: since Mink 1.7. Use \Behat\Mink\Selector\Xpath\Escaper::escapeLiteral when building Xpath or pass the unescaped value when using the named selector.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
52
53
    $page->find('named', array('select', $this->getSession()->getSelectorsHandler()->xpathLiteral("Weight for $block block")))->selectOption($weight);
0 ignored issues
show
Deprecated Code introduced by
The method Behat\Mink\Selector\Sele...Handler::xpathLiteral() has been deprecated with message: since Mink 1.7. Use \Behat\Mink\Selector\Xpath\Escaper::escapeLiteral when building Xpath or pass the unescaped value when using the named selector.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
54
55
    $page->pressButton('Save blocks');
56
57
    // @TODO Assert that the block indeed appears in that region.
58
  }
59
60
}
61