Skip to content

Commit 9ad03f5

Browse files
committed
Add Behat tests and Contexts
1 parent 7c61293 commit 9ad03f5

File tree

3 files changed

+66
-12
lines changed

3 files changed

+66
-12
lines changed

Tests/Context/WidgetContext.php

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Victoire\Widget\ImageBundle\Tests\Context;
4+
5+
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
6+
use Knp\FriendlyContexts\Context\RawMinkContext;
7+
8+
class WidgetContext extends RawMinkContext
9+
{
10+
/**
11+
* @Then /^I should see an image with url "(.+)" and alternative text "(.+)"$/
12+
*/
13+
public function iShouldSeeBackgroundImageWithRelativeUrl($url, $alt)
14+
{
15+
$page = $this->getSession()->getPage();
16+
17+
$img = $page->findAll('xpath', sprintf(
18+
'descendant-or-self::img[contains(@src, "%s") and @alt="%s"]',
19+
$url,
20+
$alt
21+
));
22+
23+
if (count($img) < 1) {
24+
throw new \RuntimeException('Image with url "'.$url.'" and alternative text "'.$url.'" could not be found.');
25+
}
26+
}
27+
}

Tests/Features/create.feature

-12
This file was deleted.

Tests/Features/manage.feature

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
@mink:selenium2 @alice(Page) @alice(MediaFile) @reset-schema
2+
Feature: Manage an Image widget
3+
4+
Background:
5+
Given I am on homepage
6+
7+
Scenario: I can create a new Image widget
8+
When I switch to "layout" mode
9+
Then I should see "New content"
10+
When I select "Image" from the "1" select of "main_content" slot
11+
Then I should see "Widget (Image)"
12+
And I should see "1" quantum
13+
When I attach image with id "1" to victoire field "a_static_widget_image_image_widget"
14+
And I fill in "_a_static_widget_image[alt]" with "My alternative text"
15+
And I fill in "_a_static_widget_image[legend]" with "My legend"
16+
And I submit the widget
17+
Then I should see "My legend"
18+
And I should see an image with url "/uploads/55953304833d5.jpg" and alternative text "My alternative text"
19+
20+
Scenario: I can update an Image widget
21+
Given the following WidgetMap:
22+
| view | action | slot |
23+
| home | create | main_content |
24+
And the following WidgetImage:
25+
| widgetMap | alt | image | legend |
26+
| home | Alternative text to modify | victoire | Legend to modify |
27+
When I reload the page
28+
Then I should see "Legend to modify"
29+
And I should see an image with url "/uploads/55dc8d8a4c9d3.jpg" and alternative text "Alternative text to modify"
30+
When I switch to "edit" mode
31+
And I edit the "Image" widget
32+
And I should see "Widget #1 (Image)"
33+
And I should see "1" quantum
34+
When I attach image with id "1" to victoire field "a_static_widget_image_image_widget"
35+
And I fill in "_a_static_widget_image[alt]" with "Alternative text modified"
36+
And I fill in "_a_static_widget_image[legend]" with "Legend modified"
37+
And I submit the widget
38+
Then I should see "Legend modified"
39+
And I should see an image with url "/uploads/55953304833d5.jpg" and alternative text "Alternative text modified"

0 commit comments

Comments
 (0)