Skip to content

Commit

Permalink
Adjust to widget changes
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Nov 30, 2020
1 parent 8ebe89f commit 8bb5499
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 71 deletions.
44 changes: 18 additions & 26 deletions phpunit.xml.dist
@@ -1,28 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
colors="true"
verbose="true"
bootstrap="vendor/autoload.php"
failOnRisky="true"
failOnWarning="true">
<php>
<ini name="error_reporting" value="-1"/>
</php>

<testsuites>
<testsuite name="Yii Form tests">
<directory>./tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./</directory>
<exclude>
<directory>./tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" colors="true" verbose="true" bootstrap="vendor/autoload.php" failOnRisky="true" failOnWarning="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory>./</directory>
</include>
<exclude>
<directory>./tests</directory>
<directory>./vendor</directory>
</exclude>
</coverage>
<php>
<ini name="error_reporting" value="-1"/>
</php>
<testsuites>
<testsuite name="YiiForm">
<directory>./tests</directory>
</testsuite>
</testsuites>
</phpunit>
16 changes: 8 additions & 8 deletions src/FormModel.php
Expand Up @@ -4,22 +4,22 @@

namespace Yiisoft\Form;

use Closure;
use ReflectionClass;
use InvalidArgumentException;
use Yiisoft\Strings\Inflector;
use Yiisoft\Strings\StringHelper;
use Yiisoft\Validator\Rule\Required;
use Yiisoft\Validator\ValidatorFactoryInterface;

use function array_key_exists;
use function array_merge;
use Closure;
use function explode;
use function get_object_vars;
use InvalidArgumentException;
use function is_subclass_of;

use ReflectionClass;
use function reset;
use function sprintf;
use function strpos;
use Yiisoft\Strings\Inflector;
use Yiisoft\Strings\StringHelper;
use Yiisoft\Validator\Rule\Required;
use Yiisoft\Validator\ValidatorFactoryInterface;

/**
* Form model represents an HTML form: its data, validation and presentation.
Expand Down
8 changes: 4 additions & 4 deletions src/Widget/ErrorSummary.php
Expand Up @@ -4,15 +4,15 @@

namespace Yiisoft\Form\Widget;

use function array_merge;
use function array_unique;
use function array_values;
use Yiisoft\Arrays\ArrayHelper;

use Yiisoft\Form\FormModelInterface;
use Yiisoft\Html\Html;
use Yiisoft\Widget\Widget;

use function array_merge;
use function array_unique;
use function array_values;

final class ErrorSummary extends Widget
{
private FormModelInterface $data;
Expand Down
6 changes: 3 additions & 3 deletions src/Widget/Field.php
Expand Up @@ -4,17 +4,17 @@

namespace Yiisoft\Form\Widget;

use function array_merge;
use InvalidArgumentException;
use function strtr;
use Yiisoft\Arrays\ArrayHelper;
use Yiisoft\Factory\Exceptions\InvalidConfigException;
use Yiisoft\Form\FormModelInterface;
use Yiisoft\Form\Helper\HtmlForm;

use Yiisoft\Html\Html;
use Yiisoft\Widget\Widget;

use function array_merge;
use function strtr;

/**
* Renders the field widget along with label, error tag and hint tag (if any) according to template.
*/
Expand Down
14 changes: 8 additions & 6 deletions src/Widget/Form.php
Expand Up @@ -4,17 +4,17 @@

namespace Yiisoft\Form\Widget;

use Yiisoft\Arrays\ArrayHelper;
use Yiisoft\Html\Html;
use Yiisoft\Http\Method;
use Yiisoft\Widget\Widget;

use function explode;
use function implode;
use function strcasecmp;
use function strpos;

use function substr;
use function urldecode;
use Yiisoft\Arrays\ArrayHelper;
use Yiisoft\Html\Html;
use Yiisoft\Http\Method;
use Yiisoft\Widget\Widget;

/**
* A widget for rendering a form
Expand All @@ -34,8 +34,10 @@ final class Form extends Widget
*
* {@see end())}
*/
public function start(): string
public function begin(): ?string
{
parent::begin();

$hiddenInputs = [];

$csrfToken = ArrayHelper::remove($this->options, 'csrf', false);
Expand Down
4 changes: 2 additions & 2 deletions src/Widget/Input.php
Expand Up @@ -4,14 +4,14 @@

namespace Yiisoft\Form\Widget;

use function in_array;
use Yiisoft\Arrays\ArrayHelper;
use Yiisoft\Form\FormModelInterface;
use Yiisoft\Form\Helper\HtmlForm;
use Yiisoft\Html\Html;

use Yiisoft\Widget\Widget;

use function in_array;

final class Input extends Widget
{
private ?string $id = null;
Expand Down
5 changes: 2 additions & 3 deletions tests/FormModelTest.php
Expand Up @@ -5,13 +5,12 @@
namespace Yiisoft\Form\Tests;

use InvalidArgumentException;
use function str_repeat;
use Yiisoft\Form\FormModel;

use Yiisoft\Form\Tests\Stub\LoginForm;

use Yiisoft\Validator\Rule\Required;

use function str_repeat;

require __DIR__ . '/Stub/NonNamespacedForm.php';

final class FormModelTest extends TestCase
Expand Down
38 changes: 19 additions & 19 deletions tests/Widget/FormTest.php
Expand Up @@ -14,16 +14,16 @@ final class FormTest extends TestCase
public function testFormsBegin(): void
{
$expected = '<form action="/test" method="POST">';
$created = Form::begin()
$created = Form::widget()
->action('/test')
->start();
->begin();
$this->assertEquals($expected, $created);

$expected = '<form action="/example" method="GET">';
$created = Form::begin()
$created = Form::widget()
->action('/example')
->method('GET')
->start();
->begin();
$this->assertEquals($expected, $created);

$hiddens = [
Expand All @@ -32,14 +32,14 @@ public function testFormsBegin(): void
];
$this->assertEquals(
'<form action="/example" method="GET">' . "\n" . implode("\n", $hiddens),
Form::begin()->action('/example?id=1&title=%3C')->method('GET')->start()
Form::widget()->action('/example?id=1&title=%3C')->method('GET')->begin()
);

$expected = '<form action="/foo" method="GET">%A<input type="hidden" name="p" value="">';
$actual = Form::begin()
$actual = Form::widget()
->action('/foo?p')
->method('GET')
->start();
->begin();
$this->assertStringMatchesFormat($expected, $actual);
}

Expand All @@ -65,17 +65,17 @@ public function dataProviderFormsBeginSimulateViaPost(): array
*/
public function testFormsBeginSimulateViaPost(string $expected, string $method, array $options = []): void
{
$actual = Form::begin()
$actual = Form::widget()
->action('/foo')
->method($method)
->options($options)
->start();
->begin();
$this->assertStringMatchesFormat($expected, $actual);
}

public function testFormsEnd(): void
{
Form::begin()->start();
Form::widget()->begin();
$this->assertEquals('</form>', Form::end());
}

Expand All @@ -84,7 +84,7 @@ public function testFormsSimpleFields(): void
$data = new PersonalForm();

$data->email('admin@example.com');
$html = Form::begin()->action('/something')->start();
$html = Form::widget()->action('/something')->begin();
$html .= Field::widget()
->config($data, 'email')
->template('{input}')
Expand All @@ -98,7 +98,7 @@ public function testFormsSimpleFields(): void
HTML;
$this->assertEqualsWithoutLE($expected, $html);

$html = Form::begin()->action('/something')->options(['class' => 'formTestMe'])->start();
$html = Form::widget()->action('/something')->options(['class' => 'formTestMe'])->begin();
$html .= Field::widget()
->config($data, 'email')
->enclosedByContainer(true, ['class' => 'fieldTestMe'])
Expand All @@ -121,7 +121,7 @@ public function testFormsFieldsOptions(): void
$data->name('yii test');
$data->validate();

$html = Form::begin()->action('/something')->start();
$html = Form::widget()->action('/something')->begin();
$html .= Field::widget()
->config($data, 'name')
->inputCssClass('form-testme');
Expand All @@ -137,7 +137,7 @@ public function testFormsFieldsOptions(): void
HTML;
$this->assertEqualsWithoutLE($expected, $html);

$html = Form::begin()->action('/something')->start();
$html = Form::widget()->action('/something')->begin();
$html .= Field::widget()
->config($data, 'name')
->inputCssClass('form-testme');
Expand Down Expand Up @@ -166,7 +166,7 @@ public function testFormsIssue5356(): void
$data = new PersonalForm();
$data->cityBirth(2);

$html = Form::begin()->action('/something')->start();
$html = Form::widget()->action('/something')->begin();
$html .= Field::widget()
->config($data, 'cityBirth')
->template('{input}')
Expand All @@ -186,7 +186,7 @@ public function testFormsIssue5356(): void
HTML;
$this->assertEqualsWithoutLE($expected, $html);

$html = Form::begin()->action('/something')->start();
$html = Form::widget()->action('/something')->begin();
$html .= Field::widget()
->config($data, 'cityBirth')
->listBox($citys, ['multiple' => true, 'unselect' => '1']);
Expand Down Expand Up @@ -220,7 +220,7 @@ public function testFormsFieldsValidationOnContainer(): void
$data->email('admin@example.com');
$data->validate();

$html = Form::begin()->action('/something')->start();
$html = Form::widget()->action('/something')->begin();
$html .= Field::widget($fieldConfig)
->config($data, 'name');
$html .= Field::widget($fieldConfig)
Expand Down Expand Up @@ -250,7 +250,7 @@ public function testFormsFieldsValidationOnInput(): void
$data->email('admin');
$data->validate();

$html = Form::begin()->action('/something')->start();
$html = Form::widget()->action('/something')->begin();
$html .= Field::widget()
->config($data, 'name');
$html .= Field::widget()
Expand Down Expand Up @@ -303,7 +303,7 @@ public function testForms(): void
$data->load($record);
$data->validate();

$html = Form::begin()->action('/something')->start();
$html = Form::widget()->action('/something')->begin();
$html .= Field::widget($fieldConfig)
->config($data, 'id')
->textinput();
Expand Down

0 comments on commit 8bb5499

Please sign in to comment.