Skip to content

Commit

Permalink
Add a test for the DataTransformer in the case of the absence of captcha
Browse files Browse the repository at this point in the history
  • Loading branch information
lgeorget committed Nov 12, 2020
1 parent 08a2cb6 commit 2ed4eb3
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Tests/Form/DataTransformer/HCatchaValueFetcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class HCaptchaValueFetcherTest extends TestCase

private $request;

private $noCaptchaRequestStack;

private $noCaptchaRequest;

public function setUp(): void
{
$this->requestStack = $this->createMock(RequestStack::class);
Expand All @@ -30,6 +34,20 @@ public function setUp(): void
$this->requestStack->expects($this->any())
->method('getMasterRequest')
->willReturn($this->request);

$this->noCaptchaRequestStack = $this->createMock(RequestStack::class);
$this->noCaptchaRequest = Request::create(
'/some_route',
'POST',
[], // request parameters
[], // cookies
[], // files
[ 'REMOTE_ADDR' => '10.0.1.1' ], // server
''
);
$this->noCaptchaRequestStack->expects($this->any())
->method('getMasterRequest')
->willReturn($this->noCaptchaRequest);
}

public function test_The_value_fetcher_builds_the_correct_form_value_from_the_request()
Expand All @@ -41,6 +59,14 @@ public function test_The_value_fetcher_builds_the_correct_form_value_from_the_re
$this->assertEquals($expected, $value);
}

public function test_The_value_fetcher_builds_a_null_form_value_if_the_request_contains_no_captcha()
{
$valueFetcher = new HCaptchaValueFetcher($this->noCaptchaRequestStack);

$value = $valueFetcher->reverseTransform(null);
$this->assertNull($value);
}

public function test_The_value_fetcher_does_not_do_transformation_from_model_to_form_data()
{
$valueFetcher = new HCaptchaValueFetcher($this->requestStack);
Expand Down

0 comments on commit 2ed4eb3

Please sign in to comment.