Skip to content

Commit

Permalink
tests: fix build against latest nette/forms
Browse files Browse the repository at this point in the history
  • Loading branch information
xificurk committed Apr 17, 2021
1 parent 412a159 commit 62b3f3c
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions tests/EmailAddressInput/EmailAddressInputTest.phpt
Expand Up @@ -21,12 +21,6 @@ require_once __DIR__ . '/../bootstrap.php';
class EmailAddressInputTest extends TestCase
{

protected function setUp(): void
{
parent::setUp();
$_COOKIE['_nss'] = '1';
}

public function testSetNullValue(): void
{
$input = new EmailAddressInput();
Expand Down Expand Up @@ -86,11 +80,10 @@ class EmailAddressInputTest extends TestCase

public function testNoDataSubmitted(): void
{
$_SERVER['REQUEST_METHOD'] = 'POST';
$_FILES = [];
$this->resetHttpGlobalVariables();
$_POST = ['email' => ''];

$form = new Form();
$form = $this->createForm();
$emailAddressInput = new EmailAddressInput();
$form['email'] = $emailAddressInput;
$form->fireEvents();
Expand All @@ -107,11 +100,10 @@ class EmailAddressInputTest extends TestCase

public function testEmptyValueSubmitted(): void
{
$_SERVER['REQUEST_METHOD'] = 'POST';
$_FILES = [];
$this->resetHttpGlobalVariables();
$_POST = ['email' => '@'];

$form = new Form();
$form = $this->createForm();
$emailAddressInput = new EmailAddressInput();
$form['email'] = $emailAddressInput;
$emailAddressInput->setEmptyValue('@');
Expand All @@ -129,11 +121,10 @@ class EmailAddressInputTest extends TestCase

public function testValidDataSubmitted(): void
{
$_SERVER['REQUEST_METHOD'] = 'POST';
$_FILES = [];
$this->resetHttpGlobalVariables();
$_POST = ['email' => 'Example@Example.com'];

$form = new Form();
$form = $this->createForm();
$emailAddressInput = new EmailAddressInput();
$form['email'] = $emailAddressInput;
$form->fireEvents();
Expand All @@ -151,11 +142,10 @@ class EmailAddressInputTest extends TestCase

public function testInvalidDataSubmitted(): void
{
$_SERVER['REQUEST_METHOD'] = 'POST';
$_FILES = [];
$this->resetHttpGlobalVariables();
$_POST = ['email' => 'foo'];

$form = new Form();
$form = $this->createForm();
$emailAddressInput = new EmailAddressInput();
$form['email'] = $emailAddressInput;
$emailAddressInput->setRequired('true');
Expand All @@ -170,6 +160,23 @@ class EmailAddressInputTest extends TestCase
);
}

private function resetHttpGlobalVariables(): void
{
$_SERVER['REQUEST_METHOD'] = 'POST';
$_FILES = [];
$_COOKIE['_nss'] = '1';
$_POST = [];
$_GET = [];
}

private function createForm(): Form
{
$form = new Form();
$form->onSubmit[] = function (): void {
};
return $form;
}

}


Expand Down

0 comments on commit 62b3f3c

Please sign in to comment.