Allow to create empty option in Select #2288

Merged
merged 16 commits into from Sep 10, 2012
View
@@ -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
@@ -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'];
@@ -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,
));
}
@@ -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,
));
}
@@ -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;
@@ -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(
@@ -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) {
@@ -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),
);
}
@@ -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');
@@ -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());
+ }
}