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

Fix tests - do not rely on hardcoded/expected names #1245

Merged
merged 31 commits into from
Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b0ed358
init
ibelar Jun 5, 2020
ff3bd91
Apply fixes from StyleCI
ibelar Jun 5, 2020
3a9e2f0
wip
ibelar Jun 5, 2020
b2a5c41
Merge branch 'fix/unit-test-url' of https://github.com/atk4/ui into f…
ibelar Jun 5, 2020
aad6639
clean up unit test - add behat test
ibelar Jun 5, 2020
aafa316
final test
ibelar Jun 5, 2020
a457659
added basic action executor test in behat
ibelar Jun 5, 2020
71e7b4f
remove template from console output
ibelar Jun 5, 2020
f344249
Fix missing DIContainerTrait when StaticAddToTrait is used
mvorisek Jun 7, 2020
a83dc81
Fix missing DIContainerTrait when StaticAddToTrait is used
mvorisek Jun 7, 2020
78e1d09
Merge branch 'develop' into fix/unit-test-url
mvorisek Jun 7, 2020
6a6b03e
Merge branch 'fix_for_new_factory' into fix/unit-test-url
mvorisek Jun 7, 2020
5e4b2af
extra changes for merge
mvorisek Jun 7, 2020
035e349
Merge branch 'fix/unit-test-url' of https://github.com/atk4/ui into f…
ibelar Jun 7, 2020
e04b328
fix hardcode column name
ibelar Jun 7, 2020
0a72253
Apply fixes from StyleCI
ibelar Jun 7, 2020
a2d2a61
cs fixer
ibelar Jun 7, 2020
37a3b67
move utility function to trait
ibelar Jun 8, 2020
8a8d6a4
cs fixer
ibelar Jun 8, 2020
27a3f75
adding behat test for grid search
ibelar Jun 8, 2020
34daf33
refine search to kingdom only
ibelar Jun 8, 2020
5fc3b5c
wait for toast to hide
ibelar Jun 8, 2020
036291f
add crud testing in behat
ibelar Jun 8, 2020
cd275e2
replace jsNotify coverage
ibelar Jun 8, 2020
18bebc2
Merge branch 'develop' into fix/unit-test-url
ibelar Jun 9, 2020
959ba1b
Fix CS fixer config for "Callable" class
mvorisek Jun 10, 2020
30ca774
Refactor "I Wait x" to "I sleep x ms"
mvorisek Jun 10, 2020
2225c32
add FeatureContext::getSession() return type
mvorisek Jun 10, 2020
4a99f03
fix CS
mvorisek Jun 10, 2020
8c03449
add NS to FeatureContext
mvorisek Jun 10, 2020
3899e7a
fix bootstrap autoload/path
mvorisek Jun 10, 2020
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
5 changes: 5 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ return PhpCsFixer\Config::create()
],

// disable some too strict rules
'phpdoc_types' => [
// keep enabled, but without "alias" group to not fix
// "Callback" to "callback" in phpdoc
'groups' => ['simple', 'meta']
],
'phpdoc_types_order' => [
'null_adjustment' => 'always_last',
'sort_algorithm' => 'none',
Expand Down
2 changes: 1 addition & 1 deletion behat-travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ default:
suites:
my_suite:
contexts:
- FeatureContext
- atk4\ui\behat\FeatureContext
- Behat\MinkExtension\Context\MinkContext
extensions:
Behat\MinkExtension:
Expand Down
20 changes: 20 additions & 0 deletions demos/_unit-test/console.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
mvorisek marked this conversation as resolved.
Show resolved Hide resolved

namespace atk4\ui\demo;

use atk4\ui\jsSSE;

require_once __DIR__ . '/../atk-init.php';

$sse = jsSSE::addTo($app);
$sse->urlTrigger = 'console_test';

$console = \atk4\ui\Console::addTo($app, ['sse' => $sse]);

$console->set(function ($console) {
$console->output('Executing test process...');
$console->output('Now trying something dangerous..');
echo 'direct output is captured';

throw new \atk4\core\Exception('BOOM - exceptions are caught');
});
13 changes: 13 additions & 0 deletions demos/_unit-test/console_exec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace atk4\ui\demo;

use atk4\ui\jsSSE;

require_once __DIR__ . '/../atk-init.php';

$sse = jsSSE::addTo($app);
$sse->urlTrigger = 'console_test';

$console = \atk4\ui\Console::addTo($app, ['sse' => $sse]);
$console->exec('/bin/pwd');
32 changes: 32 additions & 0 deletions demos/_unit-test/console_run.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace atk4\ui\demo;

use atk4\ui\jsSSE;

require_once __DIR__ . '/../atk-init.php';

$testRunClass = get_class(new class() extends \atk4\ui\View {
use \atk4\core\DebugTrait;

public function test()
{
$this->log('info', 'Console will automatically pick up output from all DebugTrait objects');
$this->debug('debug');
$this->emergency('emergency');
$this->alert('alert');
$this->critical('critical');
$this->error('error');
$this->warning('warning');
$this->notice('notice');
$this->info('info');

return 123;
}
});

$sse = jsSSE::addTo($app);
$sse->urlTrigger = 'console_test';

$console = \atk4\ui\Console::addTo($app, ['sse' => $sse]);
$console->runMethod($testRunClass::addTo($app), 'test');
28 changes: 28 additions & 0 deletions demos/_unit-test/crud.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* For Behat testing only.
* Will test for Add, Edit and delete button using quicksearch.
* see crud.feature.
*/

namespace atk4\ui\demo;

require_once __DIR__ . '/../atk-init.php';

$m = new CountryLock($db);
$edit = $m->getAction('edit');
$edit->ui = ['execButton' => [\atk4\ui\Button::class, 'EditMe', 'blue']];
$edit->description = 'edit';

$delete = $m->getAction('delete');
$delete->ui = [];
$delete->description = 'delete';

$add = $m->getAction('add');
$add->ui = ['execButton' => [\atk4\ui\Button::class, 'AddMe', 'blue']];
$add->description = 'Add';

$g = \atk4\ui\CRUD::addTo($app, ['ipp' => 10, 'menu' => ['class' => ['atk-grid-menu']]]);
$g->setModel($m);

$g->addQuickSearch(['name'], true);
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@

namespace atk4\ui\demo;

use atk4\ui\CallbackLater;

require_once __DIR__ . '/../atk-init.php';

// JUST TO TEST Exceptions and Error throws

$modal = \atk4\ui\Modal::addTo($app);
$cb = CallbackLater::addTo($app);
$cb->urlTrigger = 'm_cb';

$modal = \atk4\ui\Modal::addTo($app, ['cb' => $cb]);
$modal->name = 'm_test';

$modal->set(function ($m) use ($modal) {
throw new \Exception('TEST!');
Expand All @@ -15,7 +21,10 @@
$button = \atk4\ui\Button::addTo($app, ['Test modal exception']);
$button->on('click', $modal->show());

$modal2 = \atk4\ui\Modal::addTo($app);
$cb1 = CallbackLater::addTo($app);

$cb1->urlTrigger = 'm2_cb';
$modal2 = \atk4\ui\Modal::addTo($app, ['cb' => $cb1]);

$modal2->set(function ($m) use ($modal2) {
trigger_error('error triggered');
Expand Down
17 changes: 17 additions & 0 deletions demos/_unit-test/post.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace atk4\ui\demo;

use atk4\ui\Form;
use atk4\ui\jsToast;

require_once __DIR__ . '/../atk-init.php';

$f = Form::addTo($app);
$f->name = 'test_form';

$f->addField('f1')->set('v1');

$f->onSubmit(function ($f) {
return new jsToast('Post ok');
});
24 changes: 24 additions & 0 deletions demos/_unit-test/reload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace atk4\ui\demo;

use atk4\ui\Button;
use atk4\ui\Callback;
use atk4\ui\jsReload;
use atk4\ui\View;

require_once __DIR__ . '/../atk-init.php';

$v = View::addTo($app, ['ui' => 'segment']);
$v->set('Test');
$v->name = 'reload';

$b = Button::addTo($app)->set('Reload');
$b->on('click', new jsReload($v));

$cb = Callback::addTo($app);
$cb->urlTrigger = 'c_reload';

\atk4\ui\Loader::addTo($app, ['cb' => $cb])->set(function ($page) {
$v = View::addTo($page, ['ui' => 'segment'])->set('loaded');
});
24 changes: 24 additions & 0 deletions demos/_unit-test/sse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace atk4\ui\demo;

use atk4\ui\jsExpression;
use atk4\ui\View;

require_once __DIR__ . '/../atk-init.php';

$v = View::addTo($app)->set('This will trigger a network request for testing sse...');

$sse = \atk4\ui\jsSSE::addTo($app);
// url trigger must match php_unit test in sse provider.
$sse->urlTrigger = 'see_test';

$v->js(true, $sse->set(function () use ($sse) {
$sse->send(new jsExpression('console.log("test")'));
$sse->send(new jsExpression('console.log("test")'));
$sse->send(new jsExpression('console.log("test")'));
$sse->send(new jsExpression('console.log("test")'));

// non-SSE way
return $sse->send(new jsExpression('console.log("test")'));
}));
3 changes: 0 additions & 3 deletions demos/atk-init.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@
$app->initLayout(new $layout());

$layout = $app->layout;
// Need for phpunit only for producing right url.
$layout->name = 'atk_admin';
$layout->id = $layout->name;

if ($layout instanceof \atk4\ui\Layout\Navigable) {
$layout->addMenuItem(['Welcome to Agile Toolkit', 'icon' => 'gift'], [$demosUrl . 'index']);
Expand Down
12 changes: 7 additions & 5 deletions demos/collection/actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace atk4\ui\demo;

use atk4\ui\Button;

require_once __DIR__ . '/../atk-init.php';

\atk4\ui\Button::addTo($app, ['js Event Executor', 'small right floated basic blue', 'iconRight' => 'right arrow'])
Expand Down Expand Up @@ -39,21 +41,21 @@

$app->add($grid = new \atk4\ui\GridLayout(['columns' => 3]));

$grid->add($executor = new \atk4\ui\ActionExecutor\Basic(), 'r1c1');
$grid->add($executor = new \atk4\ui\ActionExecutor\Basic(['executorButton' => [Button::class, 'Import', 'primary']]), 'r1c1');
$executor->setAction($action);
$executor->ui = 'segment';
$executor->description = 'Execute action using "Basic" executor and path="." argument';
$executor->setArguments(['path' => '.']);
$executor->onHook(\atk4\ui\ActionExecutor\Basic::HOOK_AFTER_EXECUTE, function ($x, $ret) {
return new \atk4\ui\jsToast('Files imported: ' . $ret);
$executor->onHook(\atk4\ui\ActionExecutor\Basic::HOOK_AFTER_EXECUTE, function ($x) {
return new \atk4\ui\jsToast('Done!');
});

$grid->add($executor = new \atk4\ui\ActionExecutor\ArgumentForm(), 'r1c2');
$executor->setAction($action);
$executor->description = 'ArgumentForm executor will ask user about arguments';
$executor->ui = 'segment';
$executor->onHook(\atk4\ui\ActionExecutor\Basic::HOOK_AFTER_EXECUTE, function ($x, $ret) {
return new \atk4\ui\jsToast('Files imported: ' . $ret);
return new \atk4\ui\jsToast('Imported!');
});

$grid->add($executor = new \atk4\ui\ActionExecutor\Preview(), 'r1c3');
Expand All @@ -63,7 +65,7 @@
$executor->description = 'Displays preview in console prior to executing';
$executor->setArguments(['path' => '.']);
$executor->onHook(\atk4\ui\ActionExecutor\Basic::HOOK_AFTER_EXECUTE, function ($x, $ret) {
return new \atk4\ui\jsToast('Files imported: ' . $ret);
return new \atk4\ui\jsToast('Confirm!');
});

\atk4\ui\CRUD::addTo($app, ['ipp' => 5])->setModel($files);
3 changes: 2 additions & 1 deletion demos/collection/tablefilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

//For popup positioning to work correctly, table need to be inside a view segment.
$view = \atk4\ui\View::addTo($app, ['ui' => 'basic segment']);
$g = \atk4\ui\Grid::addTo($view);
// Important: menu class added for Behat testing.
$g = \atk4\ui\Grid::addTo($view, ['menu' => ['class' => ['atk-grid-menu']]]);

$m = new CountryLock($db);
$m->addExpression('is_uk', $m->expr('if([iso] = [country], 1, 0)', ['country' => 'GB']))->type = 'boolean';
Expand Down
8 changes: 5 additions & 3 deletions demos/interactive/card-action.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace atk4\ui\demo;

use atk4\ui\Button;

require_once __DIR__ . '/../atk-init.php';

\atk4\ui\Button::addTo($app, ['Card Deck', 'small right floated basic blue', 'iconRight' => 'right arrow'])
Expand All @@ -25,10 +27,10 @@
'args' => [
'note' => ['type' => 'string', 'required' => true],
],
'callback' => function ($m) {
return 'Note to client is sent.';
'callback' => function ($m, $note) {
return 'Note to client is sent: ' . $note;
},
]);
$c->addSection('Client Country:', $client, ['iso', 'numcode', 'phonecode'], true);

$c->addClickAction($notify, null, [$client->get('id')]);
$c->addClickAction($notify, new Button(['Send Note']), [$client->get('id')]);
6 changes: 4 additions & 2 deletions demos/interactive/wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

namespace atk4\ui\demo;

use atk4\ui\Callback;
use atk4\ui\Wizard;

require_once __DIR__ . '/../atk-init.php';

/**
* Demonstrates how to use a wizard.
*/
$t = Wizard::addTo($app);

$t = Wizard::addTo($app, ['stepCallback' => Callback::addTo($app, ['urlTrigger' => 'demo_wizard'])]);
// First step will automatcally be active when you open page first. It
// will contain the 'Next' button with a link.
$t->addStep('Welcome', function (Wizard $w) {
Expand All @@ -26,6 +26,8 @@
// to store wizard-specific variables
$t->addStep(['Set DSN', 'icon' => 'configure', 'description' => 'Database Connection String'], function (Wizard $w) {
$f = \atk4\ui\Form::addTo($w);
// IMPORTANT - needed for php_unit Wizard test.
$f->name = 'w_form';

$f->addField('dsn', 'Connect DSN', ['required' => true])->placeholder = 'mysql://user:pass@db-host.example.com/mydb';
$f->onSubmit(function (\atk4\ui\Form $form) use ($w) {
Expand Down
3 changes: 3 additions & 0 deletions demos/obsolete/notify2.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public function init(): void
$head = \atk4\ui\Header::addTo($app, ['Notification Types']);

$form = \atk4\ui\Form::addTo($app, ['segment']);
// Unit test only.
$form->name = 'notify';

\atk4\ui\Label::addTo($form, ['Some of notification options that can be set.', 'top attached'], ['AboveFields']);
$form->buttonSave->set('Show');
$form->setModel(new $notifierClass($db), false);
Expand Down
24 changes: 24 additions & 0 deletions features/basicexecutor.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Feature: Executor
Testing basic action executor

Scenario: basic
Given I am on "collection/actions.php"
And I press button "Import"
And wait for callback
Then Toast display should contains text "Done!"

Scenario: form
Given I am on "collection/actions.php"
And I press button "Run"
And wait for callback
Then I should see "Must not be empty"
Then I fill in "path" with "."
Then I press button "Run"
And wait for callback
Then Toast display should contains text "Imported!"

Scenario: preview
Given I am on "collection/actions.php"
And I press button "Confirm"
And wait for callback
Then Toast display should contains text "Confirm!"
Loading