Skip to content

Commit

Permalink
added BC methods for Twig filters `craue_addDynamicStepNavigationPara…
Browse files Browse the repository at this point in the history
…meter` and `craue_removeDynamicStepNavigationParameter`
  • Loading branch information
craue committed Jun 24, 2015
1 parent 326817f commit 6f1de29
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
55 changes: 55 additions & 0 deletions Tests/Twig/Extension/FormFlowExtensionBcMethodsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace Craue\FormFlowBundle\Tests\Form;

use Craue\FormFlowBundle\Tests\UnitTestCase;

/**
* Tests for BC.
*
* @group unit
*
* @author Christian Raue <christian.raue@gmail.com>
* @copyright 2011-2015 Christian Raue
* @license http://opensource.org/licenses/mit-license.php MIT License
*/
class FormFlowExtensionBcMethodsTest extends UnitTestCase {

protected $collectDeprecationNotices = true;

private $deprecatedMessage = 'Twig filter %s is deprecated since version 3.0. Use filter %s instead.';

public function testBcMethodDelegation_addDynamicStepNavigationParameter() {
$extension = $this->getMock('\Craue\FormFlowBundle\Twig\Extension\FormFlowExtension', array('addDynamicStepNavigationParameters'));

$parameters = array('foo' => 'bar');
$flow = $this->getMockedFlow();
$stepNumber = 1;

$extension
->expects($this->once())
->method('addDynamicStepNavigationParameters')
->with($this->equalTo($parameters), $this->equalTo($flow), $this->equalTo($stepNumber))
;

$extension->addDynamicStepNavigationParameter($parameters, $flow, $stepNumber);
$this->assertEquals(array(sprintf($this->deprecatedMessage, 'craue_addDynamicStepNavigationParameter', 'craue_addDynamicStepNavigationParameters')), $this->getDeprecationNotices());
}

public function testBcMethodDelegation_removeDynamicStepNavigationParameter() {
$extension = $this->getMock('\Craue\FormFlowBundle\Twig\Extension\FormFlowExtension', array('removeDynamicStepNavigationParameters'));

$parameters = array('foo' => 'bar');
$flow = $this->getMockedFlow();

$extension
->expects($this->once())
->method('removeDynamicStepNavigationParameters')
->with($this->equalTo($parameters), $this->equalTo($flow))
;

$extension->removeDynamicStepNavigationParameter($parameters, $flow);
$this->assertEquals(array(sprintf($this->deprecatedMessage, 'craue_removeDynamicStepNavigationParameter', 'craue_removeDynamicStepNavigationParameters')), $this->getDeprecationNotices());
}

}
18 changes: 18 additions & 0 deletions Twig/Extension/FormFlowExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,18 @@ public function getFilters() {
return array(
'craue_addDynamicStepNavigationParameters' => new \Twig_Filter_Method($this, 'addDynamicStepNavigationParameters'),
'craue_removeDynamicStepNavigationParameters' => new \Twig_Filter_Method($this, 'removeDynamicStepNavigationParameters'),
// methods for BC with third-party templates (e.g. MopaBootstrapBundle)
'craue_addDynamicStepNavigationParameter' => new \Twig_Filter_Method($this, 'addDynamicStepNavigationParameter'),
'craue_removeDynamicStepNavigationParameter' => new \Twig_Filter_Method($this, 'removeDynamicStepNavigationParameter'),
);
}

return array(
new \Twig_SimpleFilter('craue_addDynamicStepNavigationParameters', array($this, 'addDynamicStepNavigationParameters')),
new \Twig_SimpleFilter('craue_removeDynamicStepNavigationParameters', array($this, 'removeDynamicStepNavigationParameters')),
// methods for BC with third-party templates (e.g. MopaBootstrapBundle)
new \Twig_SimpleFilter('craue_addDynamicStepNavigationParameter', array($this, 'addDynamicStepNavigationParameter')),
new \Twig_SimpleFilter('craue_removeDynamicStepNavigationParameter', array($this, 'removeDynamicStepNavigationParameter')),
);
}

Expand Down Expand Up @@ -113,4 +119,16 @@ public function isStepLinkable(FormFlow $flow, $stepNumber) {
return false;
}

// methods for BC with third-party templates (e.g. MopaBootstrapBundle)

public function addDynamicStepNavigationParameter(array $parameters, FormFlow $flow, $stepNumber) {
@trigger_error('Twig filter craue_addDynamicStepNavigationParameter is deprecated since version 3.0. Use filter craue_addDynamicStepNavigationParameters instead.', E_USER_DEPRECATED);
return $this->addDynamicStepNavigationParameters($parameters, $flow, $stepNumber);
}

public function removeDynamicStepNavigationParameter(array $parameters, FormFlow $flow) {
@trigger_error('Twig filter craue_removeDynamicStepNavigationParameter is deprecated since version 3.0. Use filter craue_removeDynamicStepNavigationParameters instead.', E_USER_DEPRECATED);
return $this->removeDynamicStepNavigationParameters($parameters, $flow);
}

}
2 changes: 1 addition & 1 deletion UPGRADE-3.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,6 @@ This version adds support for concurrent instances of the same flow, which requi

- The Twig filters `craue_addDynamicStepNavigationParameter` and `craue_removeDynamicStepNavigationParameter` have been
renamed to `craue_addDynamicStepNavigationParameters` and `craue_removeDynamicStepNavigationParameters`, i.e.
pluralized, since they now handle more than one parameter.
pluralized, since they now handle more than one parameter. Filters with the old names still exist, but are deprecated.

- The template `CraueFormFlowBundle:FormFlow:stepField.html.twig` (deprecated in 2.1.0) has been removed.

0 comments on commit 6f1de29

Please sign in to comment.