-
Notifications
You must be signed in to change notification settings - Fork 126
Expand file tree
/
Copy pathRevalidatePreviousStepsFlowTest.php
More file actions
77 lines (60 loc) · 2.55 KB
/
Copy pathRevalidatePreviousStepsFlowTest.php
File metadata and controls
77 lines (60 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
namespace Craue\FormFlowBundle\Tests;
use Craue\FormFlowBundle\Tests\IntegrationTestBundle\Entity\RevalidatePreviousStepsData;
use Craue\FormFlowBundle\Tests\IntegrationTestCase;
/**
* @group integration
*
* @author Christian Raue <christian.raue@gmail.com>
* @copyright 2011-2015 Christian Raue
* @license http://opensource.org/licenses/mit-license.php MIT License
*/
class RevalidatePreviousStepsFlowTest extends IntegrationTestCase {
/**
* {@inheritDoc}
*/
protected function setUp() {
parent::setUp();
RevalidatePreviousStepsData::resetValidationCalls();
}
public function testRevalidatePreviousSteps_enabled() {
$crawler = $this->client->request('GET', $this->url('_FormFlow_revalidatePreviousSteps_enabled'));
$this->assertSame(200, $this->client->getResponse()->getStatusCode());
// next -> step 2
$form = $crawler->selectButton('next')->form();
$crawler = $this->client->submit($form);
// trying to go to step 3, but validation changed for step 1
$form = $crawler->selectButton('next')->form();
$crawler = $this->client->submit($form);
$this->assertCurrentStepNumber(2, $crawler);
$this->assertContainsFormError('The form for step 1 is invalid. Please go back and try to submit it again.', $crawler);
$this->assertEquals(array('onPreviousStepInvalid #1'), $this->getCalledEvents());
// back -> step 1
$form = $crawler->selectButton('back')->form();
$crawler = $this->client->submit($form);
// trying to go to step 2
$form = $crawler->selectButton('next')->form();
$crawler = $this->client->submit($form);
$this->assertCurrentStepNumber(1, $crawler);
$this->assertContainsFormError('Take this!', $crawler);
}
public function testRevalidatePreviousSteps_disabled() {
$crawler = $this->client->request('GET', $this->url('_FormFlow_revalidatePreviousSteps_disabled'));
$this->assertSame(200, $this->client->getResponse()->getStatusCode());
// next -> step 2
$form = $crawler->selectButton('next')->form();
$crawler = $this->client->submit($form);
// next -> step 3
$form = $crawler->selectButton('next')->form();
$crawler = $this->client->submit($form);
$this->assertCurrentStepNumber(3, $crawler);
}
protected function getCalledEvents() {
$container = static::$kernel->getContainer();
$container->enterScope('request');
$container->set('request', $this->client->getRequest(), 'request');
$flow = $container->get('integrationTestBundle.form.flow.revalidatePreviousSteps');
$storage = $container->get('craue.form.flow.storage');
return $storage->get($flow->getCalledEventsSessionKey());
}
}