Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Behat tests and Contexts #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions Tests/Context/WidgetContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace Victoire\Widget\LocaleSwitcherBundle\Tests\Context;

use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Knp\FriendlyContexts\Context\RawMinkContext;

class WidgetContext extends RawMinkContext
{
/**
* @When /^I change locale to "(.+)" in LocaleSwitcher$/
*/
public function iChangeLocaleToInLocaleSwitcher($locale)
{
$page = $this->getSession()->getPage();

$button = $page->find('xpath', sprintf(
'descendant-or-self::div[contains(@class, "localeSwitcher")]/button[@data-toggle="dropdown"]',
$locale
));

$button->click();

$link = $page->find('xpath', sprintf(
'descendant-or-self::div[contains(@class, "localeSwitcher")]/ul[@class="dropdown-menu"]//a[@lang="%s"]',
$locale
));

if (!$link) {
throw new \RuntimeException(sprintf(
'Link for LocalSwitcher locale "%s" could not be found.',
$locale
));
}

$link->click();
}

/**
* @Then /^I should see "(.+)" current locale in LocaleSwitcher$/
*/
public function iShouldSeeCurrentLocaleInLocaleSwitcher($locale)
{
$page = $this->getSession()->getPage();

$flag = $page->find('xpath', sprintf(
'descendant-or-self::button[@data-toggle="dropdown"]/img[@class="localeSwitcher-flag" and @src="/bundles/victoirewidgetlocaleswitcher/images/flags/%s.png"]',
$locale
));

if (!$flag) {
throw new \RuntimeException(sprintf(
'It seems that current locale is not "%s" in LocaleSwitcher or element could not be found.',
$locale
));
}
}
}
12 changes: 0 additions & 12 deletions Tests/Features/create.feature

This file was deleted.

22 changes: 22 additions & 0 deletions Tests/Features/manage.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@mink:selenium2 @alice(Page) @reset-schema
Feature: Manage a Language selector widget

Background:
Given I am on homepage

Scenario: I can create a new Language selector widget
When I switch to "layout" mode
Then I should see "New content"
When I select "Language selector" from the "1" select of "main_content" slot
Then I should see "Widget (Language selector)"
And I should see "1" quantum
When I submit the widget
Then I should see the success message for Widget edit
When I reload the page
And I switch to "readonly" mode
Then I should see "en" current locale in LocaleSwitcher
Given I change locale to "fr" in LocaleSwitcher
Then I should be on "/fr"
And I should see "fr" current locale in LocaleSwitcher
Given I change locale to "en" in LocaleSwitcher
Then I should be on "/en"
2 changes: 1 addition & 1 deletion victoire-test-suite