Skip to content

Commit

Permalink
Js validation: added support for multiple option of Flag and Brand items
Browse files Browse the repository at this point in the history
  • Loading branch information
Boris Brtáň committed Jun 19, 2018
1 parent b9d633e commit d04c194
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -61,6 +61,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- [#260 - Admin: Js validation: dynamically added parameters are now validated](https://github.com/shopsys/shopsys/pull/260)
- validation is evaluated after dynamic parameters are added
- jQuery migration console error logging is no more
- support for multiple option of Flag and Brand items were added for form to be validated and not submitted if it is invalid

### [shopsys/project-base]
#### Changed
Expand Down
Expand Up @@ -3,6 +3,8 @@
namespace Shopsys\FrameworkBundle\Component\Validator;

use Fp\JsFormValidatorBundle\Factory\JsFormValidatorFactory as BaseJsFormValidatorFactory;
use Shopsys\FrameworkBundle\Model\Product\Brand\Brand;
use Shopsys\FrameworkBundle\Model\Product\Flag\Flag;
use Shopsys\FrameworkBundle\Model\Product\Parameter\ParameterValue;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormInterface;
Expand Down Expand Up @@ -47,18 +49,21 @@ protected function normalizeViewTransformers(FormInterface $form, array $viewTra
: ['name' => $namespace . 'ChoiceToBooleanArrayTransformer'];

$transformer['choiceList'] = [];
$optionsItemsThatAreNotInstanceOfParameterValue = [];
foreach ($config->getOption('choices') as $formOptionChoiceItem) {
if ($formOptionChoiceItem instanceof ParameterValue) {
if (preg_match('#^/admin/#', $this->router->getContext()->getPathInfo()) !== 1
&& (
$formOptionChoiceItem instanceof ParameterValue
|| $formOptionChoiceItem instanceof Flag
|| $formOptionChoiceItem instanceof Brand
)
) {
$optionItemId = $formOptionChoiceItem->getId();
$transformer['choiceList'][$optionItemId] = $formOptionChoiceItem;
} else {
$optionsItemsThatAreNotInstanceOfParameterValue[] = $formOptionChoiceItem;
$transformer['choiceList'][] = $formOptionChoiceItem;
}
}

array_push($transformer['choiceList'], $optionsItemsThatAreNotInstanceOfParameterValue);

array_unshift($viewTransformers, $transformer);
}

Expand Down
@@ -0,0 +1,24 @@
<?php

namespace Tests\ShopBundle\Acceptance\acceptance;

use Tests\ShopBundle\Acceptance\acceptance\PageObject\Admin\LoginPage;
use Tests\ShopBundle\Acceptance\acceptance\PageObject\Admin\ProductEditPage;
use Tests\ShopBundle\Test\Codeception\AcceptanceTester;

class php
{
public function testSaveForm(
AcceptanceTester $me,
LoginPage $loginPage,
ProductEditPage $productEditPage
) {
$me->wantTo('not able to save invalid form');
$loginPage->loginAsAdmin();

$productEditPage->saveInvalidForm(5);
$productEditPage->assertSaveFormErrorBoxVisible();

$productEditPage->cleanUpWorkspaceAfterChanges();
}
}
@@ -0,0 +1,33 @@
<?php

namespace Tests\ShopBundle\Acceptance\acceptance\PageObject\Admin;

use Facebook\WebDriver\WebDriverBy;
use Tests\ShopBundle\Acceptance\acceptance\PageObject\AbstractPage;

class ProductEditPage extends AbstractPage
{
/**
* @param int $productId
*/
public function saveInvalidForm($productId)
{
$this->tester->amOnPage('/admin/product/edit/' . $productId);
// scroll to have the button visible because of the fixed bars
$this->tester->scrollTo(['css' => '.js-parameters-item-add'], null, -300);
$this->tester->clickByCss('.js-parameters-item-add');
$this->tester->clickByText('Save changes');
}

public function cleanUpWorkspaceAfterChanges()
{
$this->tester->amOnPage('/admin/');
$this->tester->acceptPopup();
}

public function assertSaveFormErrorBoxVisible()
{
$this->tester->see('Please check the entered values.');
}

}

0 comments on commit d04c194

Please sign in to comment.