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

Do not mutate App::$request during testing #2111

Merged
merged 14 commits into from
Sep 22, 2023
2 changes: 1 addition & 1 deletion demos/_unit-test/sse.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
$v = View::addTo($app)->set('This will trigger a network request for testing SSE...');

$sse = JsSse::addTo($app);
// URL trigger must match php_unit test in sse provider.
// URL trigger must match phpunit test in SSE provider
$sse->setUrlTrigger('see_test');

$v->js(true, $sse->set(static function () use ($sse) {
Expand Down
6 changes: 2 additions & 4 deletions demos/basic/button.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';

// Demonstrates how to use buttons.

Header::addTo($app, ['Basic Button', 'size' => 2]);

// With Seed
// with seed
Button::addTo($app, ['Click me'])->link(['index']);

// Without Seeding
// without seeding
$b1 = new Button('Click me (no seed)');
$app->add($b1);
// must be added first
Expand Down
2 changes: 1 addition & 1 deletion demos/collection/card-deck.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
]);

// Create custom button for this action in card.
// create custom button for this action in card
$app->getExecutorFactory()->registerTrigger(ExecutorFactory::CARD_BUTTON, [Button::class, 'class.blue' => true, 'icon' => 'plane'], $action);

$action->args = [
Expand Down
10 changes: 5 additions & 5 deletions demos/collection/crud.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@

$crud = Crud::addTo($app, ['ipp' => 10]);

// callback for model action add form.
// callback for model action add form
$crud->onFormAdd(static function (Form $form, ModalExecutor $ex) use ($model) {
$form->js(true, $form->getControl($model->fieldName()->name)->jsInput()->val('Entering value via javascript'));
});

// callback for model action edit form.
// callback for model action edit form
$crud->onFormEdit(static function (Form $form) use ($model) {
$form->js(true, $form->getControl($model->fieldName()->name)->jsInput()->attr('readonly', true));
});
Expand All @@ -51,7 +51,7 @@
'menu' => ['class' => ['green inverted']],
'table' => ['class' => ['red inverted']],
]);
// Condition on the model can be applied on a model
// condition on the model can be applied on a model
$model = new Country($app->db);
$model->addCondition($model->fieldName()->numcode, '<', 200);
$model->onHook(Model::HOOK_VALIDATE, static function (Country $model, ?string $intent) {
Expand All @@ -64,7 +64,7 @@
});
$crud->setModel($model);

// Because Crud inherits Grid, you can also define custom actions
// because Crud inherits Grid, you can also define custom actions
$crud->addModalAction(['icon' => 'cogs'], 'Details', static function (View $p, $id) use ($crud) {
$model = Country::assertInstanceOf($crud->model);
Message::addTo($p, ['Details for: ' . $model->load($id)->name . ' (id: ' . $id . ')']);
Expand Down Expand Up @@ -102,6 +102,6 @@ public function addFormTo(View $view): Form

$crud->menu->addItem(['Rescan', 'icon' => 'recycle']);

// Condition on the model can be applied after setting the model
// condition on the model can be applied after setting the model
$crud->setModel($file);
$file->addCondition($file->fieldName()->parent_folder_id, null);
2 changes: 1 addition & 1 deletion demos/collection/crud3.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected function init(): void
}
});

// Prepare Persistence and data Model
// prepare Persistence and data Model
$data = ['test' => [
1 => ['id' => 1, 'name' => 'ABC9', 'code' => 11, 'country' => 'Ireland'],
2 => ['id' => 2, 'name' => 'ABC8', 'code' => 12, 'country' => 'Ireland'],
Expand Down
10 changes: 5 additions & 5 deletions demos/collection/grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
'nameField' => $model->fieldName()->name,
]);

// Adding Quicksearch on Name field using auto query.
// adding Quicksearch on Name field using auto query
$grid->addQuickSearch([$model->fieldName()->name], true);

if ($grid->stickyGet('no-ajax')) {
Expand All @@ -49,7 +49,7 @@

$grid->addColumn(null, [Table\Column\Template::class, 'hello<b>world</b>']);

// Creating a button for executing model test user action.
// creating a button for executing model test user action
$grid->addExecutorButton($grid->getExecutorFactory()->createExecutor($model->getUserAction('test'), $grid));

$grid->addActionButton('Say HI', static function (Jquery $j, $id) use ($grid) {
Expand All @@ -62,7 +62,7 @@
Message::addTo($p, ['Clicked on ID=' . $id]);
});

// Creating an executor for delete action.
// creating an executor for delete action
$deleteExecutor = $grid->getExecutorFactory()->createExecutor($model->getUserAction('delete'), $grid);
$deleteExecutor->onHook(BasicExecutor::HOOK_AFTER_EXECUTE, static function () {
return [
Expand All @@ -79,7 +79,7 @@
return new JsToast('Selected: ' . implode(', ', $ids) . '#');
});

// Executing a modal on a bulk selection
// executing a modal on a bulk selection
$grid->addModalBulkAction(['Delete selected', 'icon' => 'trash'], '', static function (View $modal, array $ids) use ($grid) {
Message::addTo($modal, [
'The selected records will be permanently deleted: ' . implode(', ', $ids) . '#',
Expand All @@ -103,5 +103,5 @@
});
});

// Setting ipp with an array will add an ItemPerPageSelector to paginator.
// setting ipp with an array will add an ItemPerPageSelector to paginator
$grid->setIpp([10, 100, 1000]);
2 changes: 1 addition & 1 deletion demos/collection/multitable.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';

// Re-usable component implementing counter
// re-usable component implementing counter

$finderClass = AnonymousClassNameCache::get_class(fn () => new class() extends Columns {
public array $route = [];
Expand Down
14 changes: 7 additions & 7 deletions demos/collection/tablecolumnmenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

Header::addTo($app, ['Table column may contains popup or dropdown menu.']);

// Better Popup positioning when Popup are inside a container.
// better Popup positioning when Popup are inside a container
$container = View::addTo($app, ['ui' => 'vertical segment']);
$table = Table::addTo($container, ['class.celled' => true]);
$table->setModel(new SomeData(), []);

// will add popup to this column.
// will add popup to this column
$colName = $table->addColumn('name');

// will add dropdown menu to this column.
// will add dropdown menu to this column
$colSurname = $table->addColumn('surname');

$colTitle = $table->addColumn('title');
Expand All @@ -36,7 +36,7 @@
Text::addTo($colName->addPopup())->set('Name popup');

// dynamic popup setup
// This popup will add content using the callback function.
// this popup will add content using the callback function
$colSurname->addPopup()->set(static function (View $pop) {
Text::addTo($pop)->set('This popup is loaded dynamically');
});
Expand All @@ -50,16 +50,16 @@

Header::addTo($app, ['Grid column may contains popup or dropdown menu.']);

// Table in Grid are already inside a container.
// Table in Grid are already inside a container
$grid = Grid::addTo($app);
$grid->setModel(new Country($app->db));
$grid->ipp = 5;

// Adding a dropdown menu to the column 'name'.
// adding a dropdown menu to the column 'name'
$grid->addDropdown(Country::hinting()->fieldName()->name, ['Rename', 'Delete'], static function (string $item) {
return $item;
});

// Adding a popup view to the column 'iso'
// adding a popup view to the column 'iso'
$pop = $grid->addPopup(Country::hinting()->fieldName()->iso);
Text::addTo($pop)->set('Grid column popup');
5 changes: 2 additions & 3 deletions demos/collection/tablefilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';

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

$model = new Country($app->db);
$model->addExpression('is_uk', [
Expand Down
2 changes: 1 addition & 1 deletion demos/data-action/actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
// Which fields may be edited for the action. Default to all fields.
// ModalExecutor for example, will only display fields set in this array.
'fields' => [$files->fieldName()->name],
// callback function to call in model when action execute.
// Callback function to call in model when action execute.
// Can use a closure function or model method.
'callback' => 'importFromFilesystem',
// Some Ui action executor will use this property for displaying text in button.
Expand Down
2 changes: 1 addition & 1 deletion demos/data-action/factory-view.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

public function __construct()
{
// registering card button default with our own method handler.
// registering card button default with our own method handler
$this->triggerSeed = array_merge(
$this->triggerSeed,
[self::CARD_BUTTON => ['default' => [$this, 'getCardButton']]]
Expand Down
2 changes: 1 addition & 1 deletion demos/data-action/factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
];
});

// Set new executor factory globally.
// set new executor factory globally
$app->setExecutorFactory(new $myFactory());

$country = new Country($app->db);
Expand Down
10 changes: 5 additions & 5 deletions demos/data-action/jsactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
'subHeader' => 'Model action can be trigger in various ways.',
]);

// Model action setup.
// Model action setup
$country = new Country($app->db);

$sendEmailAction = $country->addUserAction('Email', [
Expand All @@ -39,7 +39,7 @@
'subHeader' => 'Action can be triggered via a button attached to an input. The data action argument value is set to the input value.',
]);

// Note here that we explicitly required a JsCallbackExecutor for the greet action.
// note here that we explicitly required a JsCallbackExecutor for the greet action
$country->addUserAction('greet', [
'appliesTo' => UserAction::APPLIES_TO_NO_RECORDS,
'args' => [
Expand All @@ -53,7 +53,7 @@
},
]);

// Set the action property for the Line Form Control.
// set the action property for the Line Form Control
Form\Control\Line::addTo($app, ['action' => $country->getUserAction('greet')]);

// -----------------------------------------------------------------------------
Expand All @@ -66,7 +66,7 @@
'subHeader' => 'Easily trigger a data action using a Card component.',
]);

// Card component.
// Card component
$card = Card::addTo($app);
$content = new View(['class' => ['content']]);
$img = Image::addTo($content, ['../images/kristy.png']);
Expand All @@ -79,5 +79,5 @@
$s = $card->addSection('Country');
$s->addFields($entity = $country->loadAny(), [$country->fieldName()->name, $country->fieldName()->iso]);

// Pass the model action to the Card::addClickAction() method.
// pass the model action to the Card::addClickAction() method
$card->addClickAction($sendEmailAction, null, ['id' => $entity->getId()]);
6 changes: 3 additions & 3 deletions demos/data-action/jsactions2.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
$entity = $country->loadAny();
$countryId = $entity->getId();

// Model actions for this file are setup in DemoActionUtil.
// Model actions for this file are setup in DemoActionUtil
DemoActionsUtil::setupDemoActions($country);

Header::addTo($app, ['Assign Model action to button event', 'subHeader' => 'Execute model action on this country record by clicking on the appropriate button on the right.']);
Expand All @@ -38,9 +38,9 @@

$buttons = View::addTo($gl, ['ui' => 'vertical basic buttons'], ['r1c2']);

// Create a button for every action in Country model.
// create a button for every action in Country model
foreach ($country->getUserActions() as $action) {
$b = Button::addTo($buttons, [$action->getCaption()]);
// Assign action to button using current model id as URL arguments.
// assign action to button using current model id as URL arguments
$b->on('click', $action, ['args' => ['id' => $countryId]]);
}
2 changes: 1 addition & 1 deletion demos/data-action/jsactionscrud.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

$files = new File($app->db);

// This action must appear on top of the Crud
// this action must appear on top of the Crud
$files->addUserAction('import_from_filesystem', [
'caption' => 'Import',
'callback' => 'importFromFilesystem',
Expand Down
11 changes: 6 additions & 5 deletions demos/data-action/jsactionsgrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
require_once __DIR__ . '/../init-app.php';

$country = new Country($app->db);
// Model actions for this file are setup in DemoActionUtil.

// model actions for this file are setup in DemoActionUtil
DemoActionsUtil::setupDemoActions($country);

// creating special menu item for multi_step action.
// creating special menu item for multi_step action
$multiAction = $country->getUserAction('multi_step');
$specialItem = Factory::factory([View::class], ['name' => false, 'class' => ['item'], 'content' => 'Multi Step']);
Icon::addTo($specialItem, ['content' => 'window maximize outline']);
// register this menu item in factory.
// register this menu item in factory
$app->getExecutorFactory()->registerTrigger(ExecutorFactory::TABLE_MENU_ITEM, $specialItem, $multiAction);

Header::addTo($app, ['Execute model action from Grid menu items', 'subHeader' => 'Setting grid menu items in order to execute model actions or javascript.']);
Expand All @@ -42,7 +43,7 @@
Icon::addTo($jsHeader, ['content' => 'file code']);

$grid->addActionMenuItem($jsHeader);
// Beside model user action, grid menu items can also execute javascript.
// beside model user action, grid menu items can also execute javascript
$grid->addActionMenuItem('JS Callback', static function () {
return (new View())->set('JS Callback done!');
}, 'Are you sure?');
Expand All @@ -51,7 +52,7 @@

$grid->addActionMenuItem($modelHeader);

// Adding Model actions.
// adding Model actions
foreach ($country->getUserActions(UserAction::APPLIES_TO_SINGLE_RECORD) as $action) {
if (in_array($action->shortName, ['add', 'edit', 'delete'], true)) {
continue;
Expand Down
2 changes: 1 addition & 1 deletion demos/form-control/input2.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

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

// Test all kinds of input fields
// test all kinds of input fields
$group = $form->addGroup('Line');
$group->addControl('line_norm')->set('editable');
$group->addControl('line_read', ['readOnly' => true])->set('read only');
Expand Down
6 changes: 3 additions & 3 deletions demos/form-control/multiline.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@

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

// Add multiline field and set model.
// add multiline field and set model
/** @var Form\Control\Multiline */
$multiline = $form->addControl('items', [Form\Control\Multiline::class, 'tableProps' => ['color' => 'blue'], 'itemLimit' => 10, 'addOnTab' => true]);
$multiline->setModel($inventory);

// Add total field.
// add total field
$total = 0;
foreach ($inventory as $item) {
$total += $item->qty * $item->box;
Expand All @@ -42,7 +42,7 @@
$column = $sublayout->addColumn(4);
$controlTotal = $column->addControl('total', ['readOnly' => true])->set($total);

// Update total when qty and box value in any row has changed.
// update total when qty and box value in any row has changed
$multiline->onLineChange(static function (array $rows, Form $form) use ($controlTotal) {
$total = 0;
foreach ($rows as $row => $cols) {
Expand Down
9 changes: 4 additions & 5 deletions demos/form-control/upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,15 @@
$img->setThumbnailSrc($img->getApp()->cdn['atk'] . '/logo.png');
$img->set('123456', $postFile['name'] . ' (token: 123456)'); // @phpstan-ignore-line

// Do file processing here...
// do file processing here...

// This will get caught by JsCallback and show via modal.
// this will get caught by JsCallback and show via modal
// new Blabla();

// JS Action can be return.
// if using form, can return an error to form control directly.
// JS Action can be return if using form, can return an error to form control directly
// return $form->jsError('file', 'Unable to upload file.');

// can also return a notifier.
// can also return a notifier
return new JsToast([
'title' => 'Upload success',
'message' => 'Image is uploaded!',
Expand Down
2 changes: 1 addition & 1 deletion demos/form/form2.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
}
}

// In-form validation
// in-form validation
$errors = [];
if (mb_strlen($form->model->get('first_name')) < 3) {
$errors[] = $form->jsError('first_name', 'too short, ' . $form->model->get('first_name'));
Expand Down
Loading