|
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) { |
|
|
|
|
|
|
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); |
|
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
$page->find('named', array('select', $this->getSession()->getSelectorsHandler()->xpathLiteral("Weight for $block block")))->selectOption($weight); |
|
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
$page->pressButton('Save blocks'); |
|
56
|
|
|
|
|
57
|
|
|
// @TODO Assert that the block indeed appears in that region. |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|
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.