Skip to content

Commit

Permalink
WIP Behat test
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Mar 10, 2025
1 parent b61dd6b commit d8d0548
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 0 deletions.
107 changes: 107 additions & 0 deletions demos/_unit-test/dropdown-html.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php

declare(strict_types=1);

namespace Atk4\Ui\Demos;

use Atk4\Data\Model;
use Atk4\Data\Persistence;
use Atk4\Ui\App;
use Atk4\Ui\Form;
use Atk4\Ui\Message;

/** @var App $app */
require_once __DIR__ . '/../init-app.php';

$makeTestStringFx = static fn ($v) => $v . ' <b> &lt;';
$htmlValues = [
$makeTestStringFx('d') => $makeTestStringFx('dTitle'),
$makeTestStringFx('u') => $makeTestStringFx('uTitle'),
];

$form = Form::addTo($app);

$form->addControl('dropdown_single', [
Form\Control\Dropdown::class,
'caption' => 'Dropdown single',
'values' => $htmlValues,
]);

$form->addControl('dropdown_single2', [
Form\Control\Dropdown::class,
'caption' => 'Dropdown single allow addition',
'values' => $htmlValues,
'dropdownOptions' => ['allowAdditions' => true],
]);

$form->addControl('dropdown_multi', [
Form\Control\Dropdown::class,
'caption' => 'Dropdown multiple',
'multiple' => true,
'values' => $htmlValues,
]);

$form->addControl('dropdown_multi2', [
Form\Control\Dropdown::class,
'caption' => 'Dropdown multiple allow addition',
'multiple' => true,
'values' => $htmlValues,
'dropdownOptions' => ['allowAdditions' => true],
]);

$lookupModel = new Model();
$lookupModel->addField('id', ['type' => 'string']);
$lookupModel->addField('name', ['type' => 'string']);
$lookupModel->setPersistence(new Persistence\Array_(array_combine(
array_keys($htmlValues),
array_map(fn ($v) => ['name' => $v], $htmlValues)
)));

/* $form->addControl('lookup_single', [
Form\Control\Lookup::class,
'caption' => 'Lookup single',
'model' => $lookupModel,
]);
$form->addControl('lookup_single2', [
Form\Control\Lookup::class,
'caption' => 'Lookup single allow addition',
'model' => $lookupModel,
'settings' => ['allowAdditions' => true],
]);
$form->addControl('lookup_multi', [
Form\Control\Lookup::class,
'caption' => 'Lookup multiple',
'multiple' => true,
'model' => $lookupModel,
]);
$form->addControl('lookup_multi2', [
Form\Control\Lookup::class,
'caption' => 'Lookup multiple allow addition',
'multiple' => true,
'model' => $lookupModel,
'settings' => ['allowAdditions' => true],
]); */

foreach (array_keys($form->entity->getFields()) as $k) {
$form->entity->set($k, $makeTestStringFx('d'));
}

$initData = $form->entity->get();

$form->onSubmit(static function (Form $form) use ($app, $initData, $makeTestStringFx) {
$message = $app->encodeJson($form->entity->get());

$view = new Message('Values:');
$view->setApp($form->getApp());
$view->invokeInit();
$view->text->addParagraph($message);
$view->text->addParagraph('match init: ' . ($form->entity->get() === $initData));
$view->text->addParagraph('match u add: ' . ($form->entity->get() === array_map(static fn ($k) => (str_contains($k, 'multi') ? $initData[$k] . ',' : '') . $makeTestStringFx('u'), array_combine(array_keys($initData), array_keys($initData)))));
$view->text->addParagraph('match empty: ' . ($form->entity->get() === array_map(static fn () => '', $initData)));
$view->text->addParagraph('match u only: ' . ($form->entity->get() === array_map(static fn () => $makeTestStringFx('u'), $initData)));

return $view;
});
26 changes: 26 additions & 0 deletions tests-behat/dropdown.feature
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,32 @@ Feature: Dropdown
When I select value "" in lookup "multi"
Then I check if input value for "input[name='multi']" match text ""

Scenario: dropdown with escaped HTML
Given I am on "_unit-test/dropdown-html.php"
When I press button "Save"
Then Modal is open with text "match init: 1"
When I click close modal
When I select value "uTitle <b> &lt;" in lookup "dropdown_single"
When I select value "uTitle <b> &lt;" in lookup "dropdown_single2"
When I select value "uTitle <b> &lt;" in lookup "dropdown_multi"
When I select value "uTitle <b> &lt;" in lookup "dropdown_multi2"
When I press button "Save"
Then Modal is open with text "match u add: 1"
When I click close modal
When I select value "" in lookup "dropdown_single"
When I select value "" in lookup "dropdown_single2"
When I select value "" in lookup "dropdown_multi"
When I select value "" in lookup "dropdown_multi2"
When I press button "Save"
Then Modal is open with text "match empty: 1"
When I click close modal
When I select value "uTitle <b> &lt;" in lookup "dropdown_single"
When I select value "uTitle <b> &lt;" in lookup "dropdown_single2"
When I select value "uTitle <b> &lt;" in lookup "dropdown_multi"
When I select value "uTitle <b> &lt;" in lookup "dropdown_multi2"
When I press button "Save"
Then Modal is open with text "match u only: 1"

Scenario: dropdown menu
Given I am on "basic/menu.php"
When I click using selector "//div.ui.dropdown[div[text()='With Callback']]"
Expand Down

0 comments on commit d8d0548

Please sign in to comment.