Skip to content

Commit

Permalink
[ZF3][Behat,Settings] fixed all errors in /en/settings page
Browse files Browse the repository at this point in the history
  • Loading branch information
kilip committed Jul 2, 2017
1 parent cf14476 commit 11ccdc0
Show file tree
Hide file tree
Showing 22 changed files with 451 additions and 230 deletions.
3 changes: 2 additions & 1 deletion behat.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ default:
- Behat\MinkExtension\Context\MinkContext
- Yawik\Behat\CoreContext
- Yawik\Behat\OrganizationContext
- Yawik\Behat\UserContext
- Yawik\Behat\UserContext
- Yawik\Behat\SettingsContext
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions features/settings.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Feature: Update application settings
In order to use Yawik
As an administrator
I should able to update yawik settings

Background:
Given I am logged in as an administrator

@javascript @settings
Scenario: Successfully change settings
Given I go to settings page
When I select "German" from "choose your language"
And I select "Europe/Berlin" from "choose your timzone"
And I press "Save"
And I wait for the ajax response
Then I should see "Changes successfully saved"

@javascript @settings-email
Scenario: Successfully change E-Mail Notifications Settings
Given I go to email template settings page
When I check "receive E-Mail alert"
And I check "confirm application immidiatly after submit"
And I check "get blind carbon copy of all own mails"
And I wait for the ajax response
And I fill in the following:
| Mailtext | Some Mailtext |
| Confirmation mail text | Confirmation Mail |
| Invitation mail text | Invitation mail |
| Accept mail text | Accept mail text |
| Rejection mail text | Rejection mail text |
And I press "Save"
And I wait for the ajax response
Then I should see "Changes successfully saved"
17 changes: 10 additions & 7 deletions module/Applications/src/Applications/Form/SettingsFieldset.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
namespace Applications\Form;

use Settings\Entity\Hydrator\SettingsEntityHydrator;
use Zend\Form\Element\Checkbox;
use Zend\Form\Fieldset;
use Zend\Stdlib\InitializableInterface;

//use Zend\InputFilter\InputFilterProviderInterface;

Expand Down Expand Up @@ -41,10 +43,11 @@ public function init()
{
$this->setName('emails')
->setLabel(/* @translate */ 'E-Mail Notifications');

$this->add(
array('type' => 'Zend\Form\Element\Checkbox',
array('type' => Checkbox::class,
'name' => 'mailAccess',
'label' => 'foo',
'options' => array('label' => /* @translate */ 'receive E-Mail alert',
'long_label' => /* @translate */ 'if checked, you\'ll be informed by mail about new applications.'),
)
Expand Down Expand Up @@ -114,11 +117,11 @@ public function init()

$this->add(
array(
'type' => 'Settings/DisableElementsCapableFormSettingsFieldset',
'name' => 'applyFormSettings',
'options' => array(

)
'type' => 'Settings/DisableElementsCapableFormSettingsFieldset',
'name' => 'applyFormSettings',
'options' => array(
)
)
);
}
Expand Down
54 changes: 54 additions & 0 deletions module/Behat/src/CommonContextTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/**
* YAWIK
*
* @filesource
* @license MIT
* @copyright 2013 - 2017 Cross Solution <http://cross-solution.de>
*/

namespace Yawik\Behat;


use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\MinkExtension\Context\MinkContext;

trait CommonContextTrait
{
/**
* @var MinkContext
*/
protected $minkContext;

/**
* @var CoreContext
*/
protected $coreContext;

/**
* @var UserContext
*/
protected $userContext;

/**
* @BeforeScenario
*
* @param BeforeScenarioScope $scope
*/
public function gatherContexts(BeforeScenarioScope $scope)
{
$this->minkContext = $scope->getEnvironment()->getContext(MinkContext::class);
$this->coreContext = $scope->getEnvironment()->getContext(CoreContext::class);
$this->userContext = $scope->getEnvironment()->getContext(UserContext::class);
}

public function generateUrl($url)
{
return $this->coreContext->generateUrl($url);
}

public function visit($url)
{
$this->coreContext->iVisit($this->generateUrl($url));
}
}
53 changes: 53 additions & 0 deletions module/Behat/src/CoreContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,57 @@ public function iVisit($url)
{
$this->minkContext->getSession()->visit($url);
}

/**
* @When I scroll :selector into view
*
* @param string $selector Allowed selectors: #id, .className, //xpath
*
* @throws \Exception
*/
public function scrollIntoView($selector)
{
$locator = substr($selector, 0, 1);

switch ($locator) {
case '/' : // XPath selector
$function = <<<JS
(function(){
var elem = document.evaluate($selector, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
elem.scrollIntoView(false);
})()
JS;
break;

case '#' : // ID selector
$selector = substr($selector, 1);
$function = <<<JS
(function(){
var elem = document.getElementById("$selector");
elem.scrollIntoView(false);
})()
JS;
break;

case '.' : // Class selector
$selector = substr($selector, 1);
$function = <<<JS
(function(){
var elem = document.getElementsByClassName("$selector");
elem[0].scrollIntoView(false);
})()
JS;
break;

default:
throw new \Exception(__METHOD__ . ' Couldn\'t find selector: ' . $selector . ' - Allowed selectors: #id, .className, //xpath');
break;
}

try {
$this->getSession()->executeScript($function);
} catch (Exception $e) {
throw new \Exception(__METHOD__ . ' failed');
}
}
}
34 changes: 34 additions & 0 deletions module/Behat/src/SettingsContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* YAWIK
*
* @filesource
* @license MIT
* @copyright 2013 - 2017 Cross Solution <http://cross-solution.de>
*/

namespace Yawik\Behat;


use Behat\Behat\Context\Context;

class SettingsContext implements Context
{
use CommonContextTrait;

/**
* @Given I go to settings page
*/
public function iGoToSettingsPage()
{
$this->visit('/en/settings');
}

/**
* @Given I go to email template settings page
*/
public function iGoToEmailTemplatePage()
{
$this->visit('/en/settings/Applications');
}
}
15 changes: 14 additions & 1 deletion module/Behat/src/UserContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,19 @@ public function iAmLoggedInAsARecruiter()
$this->iSpecifyThePasswordAs('test');
$this->iLogIn();
}

/**
* @Given I am logged in as an administrator
*/
public function iAmLoggedInAsAnAdmin()
{
$this->thereIsAUserIdentifiedBy('test@admin.com','test',User::ROLE_ADMIN);
$this->iWantToLogIn();
$this->iSpecifyTheUsernameAs('test@admin.com');
$this->iSpecifyThePasswordAs('test');
$this->iLogIn();
}

/**
* @return UserRepository
*/
Expand All @@ -132,7 +145,7 @@ public function getUserRepository()
/**
* @Given there is a user :email identified by :password
*/
public function thereIsAUserIdentifiedBy($email, $password)
public function thereIsAUserIdentifiedBy($email, $password,$role=User::ROLE_RECRUITER)
{
$repo = $this->getUserRepository();
if(!is_object($user=$repo->findByEmail($email))){
Expand Down
6 changes: 5 additions & 1 deletion module/Core/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@
),
'view_helpers' => array(
'invokables' => array(
'formElement' => 'Core\Form\View\Helper\FormElement',
'form_element' => 'Core\Form\View\Helper\FormElement',
'formLabel' => 'Core\Form\View\Helper\RequiredMarkInFormLabel',
'form' => 'Core\Form\View\Helper\Form',
'formSimple' => 'Core\Form\View\Helper\FormSimple',
Expand All @@ -372,7 +372,11 @@
'formRowCombined' => 'Core\Form\View\Helper\FormRowCombined',
'formFileUpload' => 'Core\Form\View\Helper\FormFileUpload',
'formImageUpload' => 'Core\Form\View\Helper\FormImageUpload',

/* @TODO: [ZF3] make this setting to be camel cased */
'formCheckBox' => 'Core\Form\View\Helper\FormCheckbox',
'formcheckbox' => 'Core\Form\View\Helper\FormCheckbox',

'formDatePicker' => 'Core\Form\View\Helper\FormDatePicker',
'formInfoCheckBox' => 'Core\Form\View\Helper\FormInfoCheckbox',
'formSelect' => 'Core\Form\View\Helper\FormSelect',
Expand Down
2 changes: 1 addition & 1 deletion module/Core/src/Core/Form/Element/Checkbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Checkbox extends ZfCheckbox implements ViewHelperProviderInterface
/**
* @var string
*/
protected $helper = 'formcheckbox';
protected $helper = 'formCheckBox';

/**
* @param string|\Zend\View\Helper\HelperInterface $helper
Expand Down
1 change: 0 additions & 1 deletion module/Core/src/Core/Form/View/Helper/FormElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

use Core\Form\ViewPartialProviderInterface;
use Zend\Form\View\Helper\FormElement as ZendFormElement;
use Zend\Form\Element;
use Zend\Form\ElementInterface;
use Core\Form\Element\ViewHelperProviderInterface as CoreElementInterface;
use Zend\View\Helper\HelperInterface;
Expand Down
2 changes: 1 addition & 1 deletion module/Core/test/CoreTest/Form/Element/CheckboxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function testConstructor()
{
$this->assertInstanceOf('Core\Form\Element\Checkbox', $this->target);
$this->assertInstanceOf('Zend\Form\Element', $this->target);
$this->assertAttributeSame('formcheckbox','helper',$this->target);
$this->assertAttributeSame('formCheckBox','helper',$this->target);
}

public function testSetGetViewHelper()
Expand Down
2 changes: 1 addition & 1 deletion module/Settings/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function onBootstrap(MvcEvent $e)
// we attach with wildcard events name
$events = $e->getApplication()->getEventManager();
$events->attach(
'render*',
MvcEvent::EVENT_RENDER,
new InjectSubNavigationListener(),
10
);
Expand Down
Loading

0 comments on commit 11ccdc0

Please sign in to comment.