Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ jobs:
uses: contributte/.github/.github/workflows/nette-tester-coverage-v2.yml@master
secrets: inherit
with:
php: "8.2"
php: "8.3"
11 changes: 4 additions & 7 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:

strategy:
matrix:
php-version: [ "8.2" ]
php-version: [ "8.3" ]
operating-system: [ "ubuntu-latest" ]
fail-fast: false

Expand Down Expand Up @@ -82,7 +82,7 @@ jobs:

strategy:
matrix:
php-version: [ "8.2" ]
php-version: [ "8.3" ]
operating-system: [ "ubuntu-latest" ]
fail-fast: false

Expand Down Expand Up @@ -138,16 +138,13 @@ jobs:

strategy:
matrix:
php-version: ["8.2", "8.3", "8.4","8.5"]
php-version: ["8.3", "8.4", "8.5"]
operating-system: [ "ubuntu-latest" ]
composer-args: [ "" ]
include:
- php-version: "8.2"
operating-system: "ubuntu-latest"
composer-args: "--prefer-lowest"
- php-version: "8.3"
operating-system: "ubuntu-latest"
composer-args: "--ignore-platform-reqs"
composer-args: "--prefer-lowest"
fail-fast: false

steps:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Nette extension for Bootstrap forms.

| State | Version | Branch | Nette | PHP | Bootstrap |
|-------------|---------------|----------|-------|---------|-------------|
| dev | `^0.9` | `master` | 3.3+ | `^8.2` | `4.x` `5.x` |
| dev | `^0.9` | `master` | 3.3+ | `^8.3` | `4.x` `5.x` |
| stable | `^0.8` | `master` | 3.0+ | `^8.1` | `4.x` `5.x` |
| stable | `^0.7` | `master` | 3.0+ | `^8.1` | `4.x` `5.x` |
| stable | `^0.6` | `master` | 3.0+ | `^8.1` | `4.x` `5.x` |
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
}
],
"require": {
"php": ">=8.2",
"nette/forms": "3.2.9",
"php": ">=8.3",
"nette/forms": "^3.3.0",
"nette/application": "^3.0"
},
"require-dev": {
"contributte/qa": "^v0.4",
"phpunit/phpunit": "^11.5",
"phpunit/phpunit": "^12.5",
"phpstan/phpstan": "^2.2",
"phpstan/phpstan-deprecation-rules": "^2.0",
"phpstan/phpstan-nette": "^2.0",
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.5/phpunit.xsd" cacheDirectory=".phpunit.cache">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/12.5/phpunit.xsd" cacheDirectory=".phpunit.cache">
<testsuites>
<testsuite name="all">
<directory>tests</directory>
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ public function renderEnd(): string
*/
public function renderLabel(BaseControl $control): Html
{
if ($control->caption === null) {
if ($control->getCaption() === null) {
return Html::el();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Grid/BootstrapCell.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function render(): Html
$element = $this->elementPrototype;

/** @var BootstrapRenderer $renderer */
$renderer = $this->row->getParent()->form->renderer;
$renderer = $this->row->getParent()->getForm()->getRenderer();

$element = $renderer->configElem(RendererConfig::GRID_CELL, $element);
$element->class[] = $this->createClass();
Expand Down
2 changes: 1 addition & 1 deletion src/Grid/BootstrapRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public function getOption(string $option)
public function render(): Html
{
/** @var BootstrapRenderer $renderer */
$renderer = $this->container->form->renderer;
$renderer = $this->container->getForm()->getRenderer();

$element = $renderer->configElem(RendererConfig::GRID_ROW, $this->elementPrototype);
foreach ($this->cells as $cell) {
Expand Down
2 changes: 1 addition & 1 deletion src/Inputs/ButtonInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function getControl($content = null): Html
$btn = parent::getControl($content);
$btn->setName('button');
$this->addBtnClass($btn);
$btn->setHtml($content ?? (string) $this->caption);
$btn->setHtml($content ?? (string) $this->getCaption());
$btn->removeAttribute('value');

return $btn;
Expand Down
2 changes: 1 addition & 1 deletion src/Inputs/CheckboxInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function getControl(): Html
return self::makeCheckbox(
$this->getHtmlName(),
$this->getHtmlId(),
$this->translate($this->caption),
$this->translate($this->getCaption()),
$this->value,
false,
$this->required,
Expand Down
8 changes: 7 additions & 1 deletion src/Traits/BootstrapContainerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Contributte\FormsBootstrap\Traits;

use Closure;
use Contributte\FormsBootstrap\BootstrapContainer;
use Contributte\FormsBootstrap\BootstrapForm;
use Contributte\FormsBootstrap\Inputs\ButtonInput;
Expand Down Expand Up @@ -294,14 +295,19 @@ public function addSelect(string $name, $label = null, ?array $items = null, ?in

/**
* @param string|Html|null $caption
* @param Closure|null $onSubmit handler bound to the button's onClick, added in nette/forms 3.3
* @return SubmitButtonInput
*/
public function addSubmit(string $name, $caption = null): SubmitButton
public function addSubmit(string $name, $caption = null, ?Closure $onSubmit = null): SubmitButton
{
$comp = new SubmitButtonInput($caption);
$comp->setBtnClass('btn-primary');
$this->addComponent($comp, $name);

if ($onSubmit !== null) {
$comp->onClick[] = $onSubmit;
}

return $comp;
}

Expand Down
24 changes: 24 additions & 0 deletions tests/E2E/FormSubmissionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Tests\E2E;

use ArrayObject;
use Contributte\FormsBootstrap\BootstrapForm;
use Nette\Forms\Controls\SubmitButton;
use Nette\Http\FileUpload;

/**
Expand Down Expand Up @@ -41,6 +43,28 @@ public function testOnSuccessHandlerReceivesSubmittedValues(): void
$this->assertFalse($this->presenter->errored);
}

public function testAddSubmitHandlerIsCalledWhenThatButtonSubmitsTheForm(): void
{
// an object, so the closures below can share it without capturing by reference
$seen = new ArrayObject();

$this->submit(
function () use ($seen): BootstrapForm {
$form = new BootstrapForm();
$form->setAction('/');
$form->addText('name', 'Name');
$form->addSubmit('send', 'Send', function (SubmitButton $button) use ($seen): void {
$seen['values'] = $button->getForm()->getValues('array');
});

return $form;
},
['name' => 'Dalibor', 'send' => 'Send']
);

$this->assertSame(['name' => 'Dalibor'], $seen['values'] ?? null);
}

public function testMissingRequiredValueFailsValidation(): void
{
$form = $this->submit(
Expand Down
2 changes: 1 addition & 1 deletion tests/Grid/BootstrapCellTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected function setUp(): void
$this->form = new BootstrapForm();
$this->row = $this->form->addRow();
$this->cell = $this->row->addCell(12);
$this->form->setParent($this->createMock(Presenter::class));
$this->form->setParent($this->createStub(Presenter::class));
// A real (non-empty) action makes Nette inject the "_do" signal field,
// mirroring production where the form is attached to a routed presenter.
$this->form->setAction('/');
Expand Down
2 changes: 1 addition & 1 deletion tests/Grid/BootstrapGroupRowRenderingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function testGroupRowRendering(): void
$form->addGroup('Group 1', false)
->add([$row1]);
$form->setRenderer(new BootstrapRenderer(RenderMode::SIDE_BY_SIDE_MODE));
$form->setParent($this->createMock(Presenter::class));
$form->setParent($this->createStub(Presenter::class));
// A real (non-empty) action makes Nette inject the "_do" signal field,
// mirroring production where the form is attached to a routed presenter.
$form->setAction('/');
Expand Down
2 changes: 1 addition & 1 deletion tests/Grid/BootstrapRowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ protected function setUp(): void
{
$this->form = new BootstrapForm();
$this->row = $this->form->addRow();
$this->form->setParent($this->createMock(Presenter::class));
$this->form->setParent($this->createStub(Presenter::class));
// A real (non-empty) action makes Nette inject the "_do" signal field,
// mirroring production where the form is attached to a routed presenter.
$this->form->setAction('/');
Expand Down
2 changes: 1 addition & 1 deletion tests/Inputs/ColorPickerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function testShowsValidationState(): void
{
$form = new BootstrapForm();
// Rendering a form requires a presenter with a non-empty action; see BaseTestCase users.
$form->setParent($this->createMock(Presenter::class));
$form->setParent($this->createStub(Presenter::class));
$form->setAction('/');

$input = $form->addColor('color', 'Choose color');
Expand Down
2 changes: 1 addition & 1 deletion tests/Inputs/DateTimeControlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function testShowsValidationState(): void
{
$form = new BootstrapForm();
// Rendering a form requires a presenter with a non-empty action; see BaseTestCase users.
$form->setParent($this->createMock(Presenter::class));
$form->setParent($this->createStub(Presenter::class));
$form->setAction('/');

$dt = $form->addDate('date', 'Date');
Expand Down
2 changes: 1 addition & 1 deletion tests/Rendering/GroupRenderingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function testUngroupedControlsAreRenderedBeforeGroups(): void
protected function setUp(): void
{
$this->form = new BootstrapForm();
$this->form->setParent($this->createMock(Presenter::class));
$this->form->setParent($this->createStub(Presenter::class));
// A real (non-empty) action makes Nette inject the "_do" signal field,
// mirroring production where the form is attached to a routed presenter.
$this->form->setAction('/');
Expand Down
4 changes: 2 additions & 2 deletions tests/Rendering/RendererConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public function testGroupHiddenAccessors(): void
public function testHiddenFieldsStayInPlaceWhenGroupingIsOff(): void
{
$form = new BootstrapForm();
$form->setParent($this->createMock(Presenter::class));
$form->setParent($this->createStub(Presenter::class));
$form->setAction('/');
$form->getRenderer()->setGroupHidden(false);
$form->addHidden('secret', 'v');
Expand Down Expand Up @@ -189,7 +189,7 @@ private function sideBySideForm(): BootstrapForm
{
$form = new BootstrapForm();
$form->setRenderer(new BootstrapRenderer(RenderMode::SIDE_BY_SIDE_MODE));
$form->setParent($this->createMock(Presenter::class));
$form->setParent($this->createStub(Presenter::class));
$form->setAction('/');

return $form;
Expand Down
2 changes: 1 addition & 1 deletion tests/Rendering/SideBySideTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected function setUp(): void
{
$this->form = new BootstrapForm();
$this->form->setRenderer(new BootstrapRenderer(RenderMode::SIDE_BY_SIDE_MODE));
$this->form->setParent($this->createMock(Presenter::class));
$this->form->setParent($this->createStub(Presenter::class));
// A real (non-empty) action makes Nette inject the "_do" signal field,
// mirroring production where the form is attached to a routed presenter.
$this->form->setAction('/');
Expand Down
2 changes: 1 addition & 1 deletion tests/Rendering/VerticalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ protected function setUp(): void
{
$this->form = new BootstrapForm();
$this->form->setRenderer(new BootstrapRenderer(RenderMode::VERTICAL_MODE));
$this->form->setParent($this->createMock(Presenter::class));
$this->form->setParent($this->createStub(Presenter::class));
// A real (non-empty) action makes Nette inject the "_do" signal field,
// mirroring production where the form is attached to a routed presenter.
$this->form->setAction('/');
Expand Down
23 changes: 23 additions & 0 deletions tests/Traits/BootstrapContainerTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,29 @@ public function testAddButtonIsNotSubmitter(): void
$this->assertStringNotContainsString('type="submit"', $html);
}

public function testAddSubmitWithoutHandlerRegistersNoClickListener(): void
{
$form = new BootstrapForm();
$button = $form->addSubmit('send', 'Send');

$this->assertStringContainsString('type="submit"', (string) $button->getControl());
$this->assertSame([], $button->onClick);
}

/**
* nette/forms 3.3 grew a third addSubmit() argument that wires a handler
* straight onto the button's onClick.
*/
public function testAddSubmitTakesAnOnSubmitHandler(): void
{
$form = new BootstrapForm();
$handler = function (): void {
};
$button = $form->addSubmit('send', 'Send', $handler);

$this->assertSame([$handler], $button->onClick);
}

public function testFactoriesAlsoWorkInsideContainer(): void
{
$form = new BootstrapForm();
Expand Down
Loading