Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Allow to create empty option in Select #2288

Merged
merged 16 commits into from

9 participants

@bakura10

DOES NOT break BC.

This PR adds an option to every Select element in order to automatically prepend an empty option to a select element. This is useful either in a user experience point of view, but most often because a lot of JavaScript libraries need an empty option to render, for instance, a placeholder value.

EDIT : it now instead allows to specify a string for the empty option. This string will be used as the label for the empty option, but without any value. This is by far more flexible as it allows to set either an empty string or a kind of placeholder.

@travisbot

This pull request fails (merged 9e881d7 into 3a4cee6).

@travisbot

This pull request passes (merged 4eb320f into 3a4cee6).

kuwabarahiroshi and others added some commits
@kuwabarahiroshi kuwabarahiroshi Modified status line parser regexp.
HTTP response should accept status line with zero length reasen phrase.
d2cfcce
@kpieters kpieters ZF2-514 Fixed fatal error when using expression in columns part of a …
…join, Added unit test, fixed typo's in unit test
ca24ad1
@xtreamwayz xtreamwayz Update library/Zend/Form/Element/Range.php
This does not give the required result. It gives the isset result which is a boolean true or false.
(isset($this->attributes['min'])) ?: 0

This does work. It adds the value as expected.
(isset($this->attributes['min'])) ? $this->attributes['min'] : 0, 
9a4571f
@weierophinney weierophinney Merge branch 'patch-1' of https://github.com/gpeltink/zf2 ef90275
@weierophinney weierophinney Merge branch 'master' of https://github.com/kuwabarahiroshi/zf2 b5f1a44
@ralphschindler ralphschindler Merge branch 'hotfix/ZF2-514' of git://github.com/kpieters/zf2 into k…
…pieters-hotfix/ZF2-514
294ad43
@ralphschindler ralphschindler Zend\Db\Sql\Select: simpler test for ZF2-514 9c85cc3
@xtreamwayz xtreamwayz Pass the right validator options
Same issue as with zendframework#2293

It passes the value of isset and not the min/step attribute.
156cfc0
@bakura10 bakura10 Add unit test ebf819e
@weierophinney weierophinney Merge branch 'prg-use-params' of https://github.com/bakura10/zf2 ceeccff
@weierophinney weierophinney Merge branch 'patch-2' of https://github.com/gpeltink/zf2 2db58cf
@Slamdunk Slamdunk Notifications now to #zftalk.dev e02a3b4
@padraic padraic Merge pull request #2302 from Slamdunk/patch-1
Notifications now to #zftalk.dev
bcc6ee9
@bakura10 bakura10 Merge branch 'form/create-empty-option' of github.com:bakura10/zf2 in…
…to form/create-empty-option
7a86ea5
library/Zend/Form/Element/Select.php
@@ -96,6 +104,10 @@ public function setOptions($options)
$this->setValueOptions($this->options['options']);
}
+ if (isset($this->options['create_empty_option'])) {
+ $this->setShouldCreateEmptyOption($this->options['create_empty_option']);
@weierophinney Owner

I don't see this method in the class, and looking at the tests, this line would never get exercised. Can you please test this permutation?

Oops. My mistake !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@weierophinney weierophinney merged commit a4ddea4 into zendframework:master

1 check passed

Details default The Travis build passed
@weierophinney

Excellent, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 29, 2012
  1. @bakura10
Commits on Sep 3, 2012
  1. @kuwabarahiroshi

    Modified status line parser regexp.

    kuwabarahiroshi authored
    HTTP response should accept status line with zero length reasen phrase.
  2. @kpieters

    ZF2-514 Fixed fatal error when using expression in columns part of a …

    kpieters authored
    …join, Added unit test, fixed typo's in unit test
Commits on Sep 4, 2012
  1. @xtreamwayz

    Update library/Zend/Form/Element/Range.php

    xtreamwayz authored
    This does not give the required result. It gives the isset result which is a boolean true or false.
    (isset($this->attributes['min'])) ?: 0
    
    This does work. It adds the value as expected.
    (isset($this->attributes['min'])) ? $this->attributes['min'] : 0, 
  2. @weierophinney
  3. @weierophinney
  4. @ralphschindler
  5. @ralphschindler
  6. @xtreamwayz

    Pass the right validator options

    xtreamwayz authored
    Same issue as with zendframework#2293
    
    It passes the value of isset and not the min/step attribute.
  7. @bakura10

    Add unit test

    bakura10 authored
  8. @weierophinney
  9. @weierophinney
Commits on Sep 6, 2012
  1. @Slamdunk
Commits on Sep 8, 2012
  1. @padraic

    Merge pull request #2302 from Slamdunk/patch-1

    padraic authored
    Notifications now to #zftalk.dev
Commits on Sep 10, 2012
  1. @bakura10

    Merge branch 'form/create-empty-option' of github.com:bakura10/zf2 in…

    bakura10 authored
    …to form/create-empty-option
  2. @bakura10

    Update option

    bakura10 authored
This page is out of date. Refresh to see the latest.
View
2  .travis.yml
@@ -16,5 +16,5 @@ script:
- output=$(php php-cs-fixer.phar fix -v --dry-run --level=psr2 .); if [[ $output ]]; then while read -r line; do echo -e "\e[00;31m$line\e[00m"; done <<< "$output"; false; fi;
notifications:
- irc: "irc.freenode.org#zftalk.2"
+ irc: "irc.freenode.org#zftalk.dev"
email: false
View
4 library/Zend/Db/Sql/Select.php
@@ -573,7 +573,9 @@ protected function processSelect(PlatformInterface $platform, Adapter $adapter =
$adapter,
$this->processInfo['paramPrefix'] . ((is_string($jKey)) ? $jKey : 'column')
);
- $parameterContainer->merge($jColumnParts->getParameterContainer());
+ if ($parameterContainer) {
+ $parameterContainer->merge($jColumnParts->getParameterContainer());
+ }
$jColumns[] = $jColumnParts->getSql();
} else {
$name = (is_array($join['name'])) ? key($join['name']) : $name = $join['name'];
View
4 library/Zend/Form/Element/Number.php
@@ -77,8 +77,8 @@ protected function getValidators()
|| 'any' !== $this->attributes['step']
) {
$validators[] = new StepValidator(array(
- 'baseValue' => (isset($this->attributes['min'])) ?: 0,
- 'step' => (isset($this->attributes['step'])) ?: 1,
+ 'baseValue' => (isset($this->attributes['min'])) ? $this->attributes['min'] : 0,
+ 'step' => (isset($this->attributes['step'])) ? $this->attributes['step'] : 1,
));
}
View
8 library/Zend/Form/Element/Range.php
@@ -53,12 +53,12 @@ protected function getValidators()
}
$validators[] = new GreaterThanValidator(array(
- 'min' => (isset($this->attributes['min'])) ?: 0,
+ 'min' => (isset($this->attributes['min'])) ? $this->attributes['min'] : 0,
'inclusive' => $inclusive
));
$validators[] = new LessThanValidator(array(
- 'max' => (isset($this->attributes['max'])) ?: 100,
+ 'max' => (isset($this->attributes['max'])) ? $this->attributes['max'] : 100,
'inclusive' => $inclusive
));
@@ -67,8 +67,8 @@ protected function getValidators()
|| 'any' !== $this->attributes['step']
) {
$validators[] = new StepValidator(array(
- 'baseValue' => (isset($this->attributes['min'])) ?: 0,
- 'step' => (isset($this->attributes['step'])) ?: 1,
+ 'baseValue' => (isset($this->attributes['min'])) ? $this->attributes['min'] : 0,
+ 'step' => (isset($this->attributes['step'])) ? $this->attributes['step'] : 1,
));
}
View
6 library/Zend/Form/Element/Select.php
@@ -86,7 +86,7 @@ public function setValueOptions(array $options)
* - label: label to associate with the element
* - label_attributes: attributes to use when the label is rendered
* - value_options: list of values and labels for the select options
- * _ create_empty_option: should an empty option be prepended to the options ?
+ * _ empty_option: should an empty option be prepended to the options ?
*
* @param array|\Traversable $options
* @return Select|ElementInterface
@@ -104,8 +104,8 @@ public function setOptions($options)
$this->setValueOptions($this->options['options']);
}
- if (isset($this->options['create_empty_option'])) {
- $this->setShouldCreateEmptyOption($this->options['create_empty_option']);
+ if (isset($this->options['empty_option'])) {
+ $this->setEmptyOption($this->options['empty_option']);
}
return $this;
View
2  library/Zend/Http/Response.php
@@ -180,7 +180,7 @@ public static function fromString($string)
$response = new static();
- $regex = '/^HTTP\/(?P<version>1\.[01]) (?P<status>\d{3})(?:[ ]+(?P<reason>.+))?$/';
+ $regex = '/^HTTP\/(?P<version>1\.[01]) (?P<status>\d{3})(?:[ ]+(?P<reason>.*))?$/';
$matches = array();
if (!preg_match($regex, $firstLine, $matches)) {
throw new Exception\InvalidArgumentException(
View
12 library/Zend/Mvc/Controller/Plugin/PostRedirectGet.php
@@ -27,9 +27,13 @@ public function __invoke($redirect = null, $redirectToUrl = false)
{
$controller = $this->getController();
$request = $controller->getRequest();
+ $params = array();
if (null === $redirect) {
- $redirect = $controller->getEvent()->getRouteMatch()->getMatchedRouteName();
+ $routeMatch = $controller->getEvent()->getRouteMatch();
+
+ $redirect = $routeMatch->getMatchedRouteName();
+ $params = $routeMatch->getParams();
}
$container = new Container('prg_post1');
@@ -42,9 +46,8 @@ public function __invoke($redirect = null, $redirectToUrl = false)
// get the redirect plugin from the plugin manager
$redirector = $controller->getPluginManager()->get('Redirect');
} else {
-
/*
- * if the user wants to redirect to a route, the redirector has to come
+ * If the user wants to redirect to a route, the redirector has to come
* from the plugin manager -- otherwise no router will be injected
*/
if ($redirectToUrl === false) {
@@ -55,13 +58,14 @@ public function __invoke($redirect = null, $redirectToUrl = false)
}
if ($redirectToUrl === false) {
- $response = $redirector->toRoute($redirect);
+ $response = $redirector->toRoute($redirect, $params);
$response->setStatusCode(303);
return $response;
}
$response = $redirector->toUrl($redirect);
$response->setStatusCode(303);
+
return $response;
} else {
if ($container->post !== null) {
View
16 tests/ZendTest/Db/Sql/SelectTest.php
@@ -253,7 +253,7 @@ public function testOrder()
}
/**
- * @testdox unit test: Test join() returns same Select object (is chainable)
+ * @testdox unit test: Test having() returns same Select object (is chainable)
* @covers Zend\Db\Sql\Select::having
*/
public function testHaving()
@@ -275,7 +275,7 @@ public function testGetRawStateViaHaving(Select $select)
}
/**
- * @testdox unit test: Test join() returns same Select object (is chainable)
+ * @testdox unit test: Test group() returns same Select object (is chainable)
* @covers Zend\Db\Sql\Select::group
*/
public function testGroup()
@@ -746,6 +746,17 @@ public function providerData()
'processOrder' => array(array(array('isnull("name") DESC'), array('"name"', Select::ORDER_ASCENDING)))
);
+ // join with Expression object in COLUMNS part (ZF2-514)
+ // @co-author Koen Pieters (kpieters)
+ $select35 = new Select;
+ $select35->from('foo')->columns(array())->join('bar', 'm = n', array('thecount' => new Expression("COUNT(*)")));
+ $sqlPrep35 = // same
+ $sqlStr35 = 'SELECT COUNT(*) AS "thecount" FROM "foo" INNER JOIN "bar" ON "m" = "n"';
+ $internalTests35 = array(
+ 'processSelect' => array(array(array('COUNT(*)', '"thecount"')), '"foo"'),
+ 'processJoins' => array(array(array('INNER', '"bar"', '"m" = "n"')))
+ );
+
/**
* $select = the select object
* $sqlPrep = the sql as a result of preparation
@@ -790,6 +801,7 @@ public function providerData()
array($select32, $sqlPrep32, array(), $sqlStr32, $internalTests32),
array($select33, $sqlPrep33, array(), $sqlStr33, $internalTests33),
array($select34, $sqlPrep34, array(), $sqlStr34, $internalTests34),
+ array($select35, $sqlPrep35, array(), $sqlStr35, $internalTests35),
);
}
View
15 tests/ZendTest/Http/ResponseTest.php
@@ -73,6 +73,21 @@ public function testResponseEndsAtStatusCode()
$this->assertEquals('Foo Bar', $response->getContent());
}
+ public function testResponseHasZeroLengthReasonPhrase()
+ {
+ // Space after status code is mandatory,
+ // though, reason phrase can be empty.
+ // @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html#sec6.1
+ $string = 'HTTP/1.0 200 ' . "\r\n\r\n" . 'Foo Bar';
+
+ $response = Response::fromString($string);
+ $this->assertEquals(200, $response->getStatusCode());
+ $this->assertEquals('Foo Bar', $response->getContent());
+
+ // Reason phrase would fallback to default reason phrase.
+ $this->assertEquals('OK', $response->getReasonPhrase());
+ }
+
public function testGzipResponse ()
{
$response_text = file_get_contents(__DIR__ . '/_files/response_gzip');
View
29 tests/ZendTest/Mvc/Controller/Plugin/PostRedirectGetTest.php
@@ -16,6 +16,7 @@
use Zend\Http\Response;
use Zend\Mvc\MvcEvent;
use Zend\Mvc\Router\Http\Literal as LiteralRoute;
+use Zend\Mvc\Router\Http\Segment as SegmentRoute;
use Zend\Mvc\Router\RouteMatch;
use Zend\Mvc\Router\SimpleRouteStack;
use Zend\Stdlib\Parameters;
@@ -41,7 +42,14 @@ public function setUp()
'route' => '/',
'defaults' => array(
'controller' => 'ZendTest\Mvc\Controller\TestAsset\SampleController',
- ),
+ )
+ )));
+
+ $router->addRoute('sub', SegmentRoute::factory(array(
+ 'route' => '/foo/:param',
+ 'defaults' => array(
+ 'param' => 1
+ )
)));
$this->controller = new SampleController();
@@ -126,7 +134,6 @@ public function testNullRouteUsesMatchedRouteName()
'postval1' => 'value1'
)));
-
$result = $this->controller->dispatch($this->request, $this->response);
$prgResultRoute = $this->controller->prg();
@@ -135,4 +142,22 @@ public function testNullRouteUsesMatchedRouteName()
$this->assertEquals('/', $prgResultRoute->getHeaders()->get('Location')->getUri());
$this->assertEquals(303, $prgResultRoute->getStatusCode());
}
+
+ public function testReuseMatchedParameters()
+ {
+ $this->controller->getEvent()->getRouteMatch()->setMatchedRouteName('sub');
+
+ $this->request->setMethod('POST');
+ $this->request->setPost(new Parameters(array(
+ 'postval1' => 'value1'
+ )));
+
+ $this->controller->dispatch($this->request, $this->response);
+ $prgResultRoute = $this->controller->prg();
+
+ $this->assertInstanceOf('Zend\Http\Response', $prgResultRoute);
+ $this->assertTrue($prgResultRoute->getHeaders()->has('Location'));
+ $this->assertEquals('/foo/1', $prgResultRoute->getHeaders()->get('Location')->getUri());
+ $this->assertEquals(303, $prgResultRoute->getStatusCode());
+ }
}
Something went wrong with that request. Please try again.