Skip to content

Commit

Permalink
failing test for #149
Browse files Browse the repository at this point in the history
  • Loading branch information
craue committed Oct 6, 2014
1 parent aa91c6b commit 5001e8f
Show file tree
Hide file tree
Showing 9 changed files with 195 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Tests/IntegrationTestBundle/Controller/FormFlowController.php
Expand Up @@ -3,6 +3,7 @@
namespace Craue\FormFlowBundle\Tests\IntegrationTestBundle\Controller;

use Craue\FormFlowBundle\Form\FormFlow;
use Craue\FormFlowBundle\Tests\IntegrationTestBundle\Entity\Issue149Data;
use Craue\FormFlowBundle\Tests\IntegrationTestBundle\Entity\Issue64Data;
use Craue\FormFlowBundle\Tests\IntegrationTestBundle\Entity\PhotoUpload;
use Craue\FormFlowBundle\Tests\IntegrationTestBundle\Entity\RevalidatePreviousStepsData;
Expand Down Expand Up @@ -73,6 +74,14 @@ public function issue87Action() {
return $this->processFlow((object) array(), $this->get('integrationTestBundle.form.flow.issue87'));
}

/**
* @Route("/issue149/", name="_FormFlow_issue149")
* @Template("IntegrationTestBundle:FormFlow:issue149.html.twig")
*/
public function issue149Action() {
return $this->processFlow(new Issue149Data(), $this->get('integrationTestBundle.form.flow.issue149'));
}

/**
* @Route("/revalidatePreviousSteps/enabled/", defaults={"enabled"=true}, name="_FormFlow_revalidatePreviousSteps_enabled")
* @Route("/revalidatePreviousSteps/disabled/", defaults={"enabled"=false}, name="_FormFlow_revalidatePreviousSteps_disabled")
Expand Down
17 changes: 17 additions & 0 deletions Tests/IntegrationTestBundle/Entity/Issue149Data.php
@@ -0,0 +1,17 @@
<?php

namespace Craue\FormFlowBundle\Tests\IntegrationTestBundle\Entity;

/**
* @author Christian Raue <christian.raue@gmail.com>
* @copyright 2011-2014 Christian Raue
* @license http://opensource.org/licenses/mit-license.php MIT License
*/
class Issue149Data {

/**
* @var Issue149SubData
*/
public $photo;

}
24 changes: 24 additions & 0 deletions Tests/IntegrationTestBundle/Entity/Issue149SubData.php
@@ -0,0 +1,24 @@
<?php

namespace Craue\FormFlowBundle\Tests\IntegrationTestBundle\Entity;

use Symfony\Component\HttpFoundation\File\UploadedFile;

/**
* @author Christian Raue <christian.raue@gmail.com>
* @copyright 2011-2014 Christian Raue
* @license http://opensource.org/licenses/mit-license.php MIT License
*/
class Issue149SubData {

/**
* @var UploadedFile
*/
public $image;

/**
* @var string
*/
public $title;

}
52 changes: 52 additions & 0 deletions Tests/IntegrationTestBundle/Form/Issue149Flow.php
@@ -0,0 +1,52 @@
<?php

namespace Craue\FormFlowBundle\Tests\IntegrationTestBundle\Form;

use Craue\FormFlowBundle\Form\FormFlow;

/**
* @author Christian Raue <christian.raue@gmail.com>
* @copyright 2011-2014 Christian Raue
* @license http://opensource.org/licenses/mit-license.php MIT License
*/
class Issue149Flow extends FormFlow {

/**
* {@inheritDoc}
*/
public function getName() {
return 'issue149';
}

/**
* {@inheritDoc}
*/
protected function loadStepsConfig() {
return array(
array(
'label' => 'step1',
'type' => 'issue149',
),
array(
'label' => 'step2',
'type' => 'issue149',
),
array(
'label' => 'step3',
'type' => 'issue149',
),
);
}

/**
* {@inheritDoc}
*/
public function getFormOptions($step, array $options = array()) {
$options = parent::getFormOptions($step, $options);

$options['cascade_validation'] = true;

return $options;
}

}
39 changes: 39 additions & 0 deletions Tests/IntegrationTestBundle/Form/Issue149Form.php
@@ -0,0 +1,39 @@
<?php

namespace Craue\FormFlowBundle\Tests\IntegrationTestBundle\Form;

use Craue\FormFlowBundle\Tests\IntegrationTestBundle\Entity\Issue149SubData;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;

/**
* @author Christian Raue <christian.raue@gmail.com>
* @copyright 2011-2014 Christian Raue
* @license http://opensource.org/licenses/mit-license.php MIT License
*/
class Issue149Form extends AbstractType {

/**
* {@inheritDoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options) {
switch ($options['flow_step']) {
case 1:
$subForm = $builder->create('photo', 'form', array(
'data_class' => get_class(new Issue149SubData()),
));
$subForm->add('image', 'file');
$subForm->add('title');
$builder->add($subForm);
break;
}
}

/**
* {@inheritDoc}
*/
public function getName() {
return 'issue149';
}

}
5 changes: 5 additions & 0 deletions Tests/IntegrationTestBundle/Resources/config/form.xml
Expand Up @@ -23,6 +23,11 @@
class="Craue\FormFlowBundle\Tests\IntegrationTestBundle\Form\Issue64Form">
<tag name="form.type" alias="issue64" />
</service>

<service id="integrationTestBundle.form.issue149"
class="Craue\FormFlowBundle\Tests\IntegrationTestBundle\Form\Issue149Form">
<tag name="form.type" alias="issue149" />
</service>
</services>

</container>
6 changes: 6 additions & 0 deletions Tests/IntegrationTestBundle/Resources/config/form_flow.xml
Expand Up @@ -42,6 +42,12 @@
scope="request">
</service>

<service id="integrationTestBundle.form.flow.issue149"
class="Craue\FormFlowBundle\Tests\IntegrationTestBundle\Form\Issue149Flow"
parent="craue.form.flow"
scope="request">
</service>

<service id="integrationTestBundle.form.flow.revalidatePreviousSteps"
class="Craue\FormFlowBundle\Tests\IntegrationTestBundle\Form\RevalidatePreviousStepsFlow"
parent="craue.form.flow"
Expand Down
@@ -0,0 +1 @@
{% extends 'IntegrationTestBundle::layout_flow.html.twig' %}
42 changes: 42 additions & 0 deletions Tests/Issue149Test.php
@@ -0,0 +1,42 @@
<?php

namespace Craue\FormFlowBundle\Tests;

use Craue\FormFlowBundle\Tests\IntegrationTestCase;

/**
* @group integration
* @see https://github.com/craue/CraueFormFlowBundle/issues/149
*
* @author Christian Raue <christian.raue@gmail.com>
* @copyright 2011-2014 Christian Raue
* @license http://opensource.org/licenses/mit-license.php MIT License
*/
class Issue149Test extends IntegrationTestCase {

/**
* The issue is caused by existence of a file field, regardless of actually uploading a file.
*/
public function testIssue149() {
$crawler = $this->client->request('GET', $this->url('_FormFlow_issue149'));
$this->assertSame(200, $this->client->getResponse()->getStatusCode());
$this->assertCurrentStepNumber(1, $crawler);
$this->assertCurrentFormData('{"photo":null}', $crawler);

// enter a title -> step 2
$form = $crawler->selectButton('next')->form();
$crawler = $this->client->submit($form, array(
'issue149[photo][title]' => 'blue pixel',
));
$this->assertCurrentStepNumber(2, $crawler);
$this->assertCurrentFormData('{"photo":{"image":null,"title":"blue pixel"}}', $crawler);

// next -> step 3
$form = $crawler->selectButton('next')->form();
$crawler = $this->client->submit($form);
$this->assertCurrentStepNumber(3, $crawler);
// ensure that the title is preserved
$this->assertCurrentFormData('{"photo":{"image":null,"title":"blue pixel"}}', $crawler);
}

}

0 comments on commit 5001e8f

Please sign in to comment.