Skip to content

Commit 5435cae

Browse files
committed
Add Behat tests and Contexts
1 parent 2070c86 commit 5435cae

File tree

4 files changed

+130
-13
lines changed

4 files changed

+130
-13
lines changed

Tests/Context/WidgetContext.php

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
namespace Victoire\Widget\TitleBundle\Tests\Context;
4+
5+
use Knp\FriendlyContexts\Context\RawMinkContext;
6+
7+
class WidgetContext extends RawMinkContext
8+
{
9+
/**
10+
* @Then /^I should see a button "(.+)" with class "(.+)"$/
11+
*/
12+
public function iShouldSeeButtonWithClass($text, $class)
13+
{
14+
$page = $this->getSession()->getPage();
15+
16+
$button = $page->find('xpath', sprintf(
17+
'descendant-or-self::a[contains(@class, "%s") and contains(normalize-space(.), "%s")]',
18+
$class,
19+
$text
20+
));
21+
if (null === $button) {
22+
$message = sprintf(
23+
'Button with text "%s" and class "%s" not found.',
24+
$text,
25+
$class
26+
);
27+
throw new \Behat\Mink\Exception\ResponseTextException($message, $this->getSession());
28+
}
29+
}
30+
31+
/**
32+
* @Then /^I should see a button "(.+)" with hover title "(.+)"$/
33+
*/
34+
public function iShouldSeeButtonWithHoverTitle($text, $hoverTitle)
35+
{
36+
$page = $this->getSession()->getPage();
37+
38+
$button = $page->find('xpath', sprintf(
39+
'descendant-or-self::a[contains(@title, "%s") and contains(normalize-space(.), "%s")]',
40+
$hoverTitle,
41+
$text
42+
));
43+
if (null === $button) {
44+
$message = sprintf(
45+
'Button with text "%s" and hover title "%s" not found.',
46+
$text,
47+
$hoverTitle
48+
);
49+
throw new \Behat\Mink\Exception\ResponseTextException($message, $this->getSession());
50+
}
51+
}
52+
53+
/**
54+
* @Then /^I should see a button "(.+)" with a "(.+)" icon$/
55+
*/
56+
public function iShouldSeeButtonWithIcon($text, $icon)
57+
{
58+
$page = $this->getSession()->getPage();
59+
60+
$button = $page->find('xpath', sprintf(
61+
'descendant-or-self::a[contains(normalize-space(.), "%s")]/i[contains(@class, "%s")]',
62+
$text,
63+
$icon
64+
));
65+
if (null === $button) {
66+
$message = sprintf(
67+
'Button with text "%s" and icon "%s" not found.',
68+
$text,
69+
$icon
70+
);
71+
throw new \Behat\Mink\Exception\ResponseTextException($message, $this->getSession());
72+
}
73+
}
74+
}

Tests/Features/create.feature

-12
This file was deleted.

Tests/Features/manage.feature

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
@mink:selenium2 @alice(Page) @reset-schema
2+
Feature: Manage a Button widget
3+
4+
Background:
5+
Given I am on homepage
6+
7+
Scenario: I can create a new Button widget
8+
When I switch to "layout" mode
9+
Then I should see "New content"
10+
When I select "Button" from the "1" select of "main_content" slot
11+
Then I should see "Widget (Button)"
12+
And I should see "1" quantum
13+
When I fill in "_a_static_widget_button[title]" with "My Button Widget title"
14+
And I fill in "_a_static_widget_button[icon]" with "fa-calendar"
15+
And I fill in "_a_static_widget_button[hoverTitle]" with "My Button Widget hover"
16+
And I select "Large" from "_a_static_widget_button[size]"
17+
And I select "Warning" from "_a_static_widget_button[style]"
18+
And I submit the widget
19+
Then I should see the success message for Widget edit
20+
When I reload the page
21+
Then I should see "My Button Widget title"
22+
And I should see a button "My Button Widget title" with class "btn-lg"
23+
And I should see a button "My Button Widget title" with class "btn-warning"
24+
And I should see a button "My Button Widget title" with hover title "My Button Widget hover"
25+
And I should see a button "My Button Widget title" with a "fa-calendar" icon
26+
27+
Scenario: I can update a Button widget
28+
Given the following WidgetMap:
29+
| view | action | slot |
30+
| home | create | main_content |
31+
And the following WidgetButton:
32+
| widgetMap | title | icon | hoverTitle | size | style |
33+
| home | Button Widget to edit | fa-truck | Button Widget to edit hover | md | danger |
34+
When I reload the page
35+
Then I should see "Button Widget to edit"
36+
And I should see a button "Button Widget to edit" with class "btn-md"
37+
And I should see a button "Button Widget to edit" with class "btn-danger"
38+
And I should see a button "Button Widget to edit" with hover title "Button Widget to edit hover"
39+
And I should see a button "Button Widget to edit" with a "fa-truck" icon
40+
When I switch to "edit" mode
41+
And I edit the "Button" widget
42+
And I should see "1" quantum
43+
When I fill in "_a_static_widget_button[title]" with "Button Widget modified"
44+
And I fill in "_a_static_widget_button[icon]" with "fa-pencil"
45+
And I fill in "_a_static_widget_button[hoverTitle]" with "Button Widget modified hover"
46+
And I select "Tiny" from "_a_static_widget_button[size]"
47+
And I select "Success" from "_a_static_widget_button[style]"
48+
And I submit the widget
49+
Then I should see the success message for Widget edit
50+
When I reload the page
51+
Then I should see "Button Widget modified"
52+
And I should see a button "Button Widget modified" with class "btn-sm"
53+
And I should see a button "Button Widget modified" with class "btn-success"
54+
And I should see a button "Button Widget modified" with hover title "Button Widget modified hover"
55+
And I should see a button "Button Widget modified" with a "fa-pencil" icon

victoire-test-suite

0 commit comments

Comments
 (0)