Skip to content

Commit

Permalink
Presenter: argsToParams() and saveState() now distinguish between NUL…
Browse files Browse the repository at this point in the history
…L and FALSE [Closes #107]
  • Loading branch information
enumag authored and dg committed Jan 13, 2016
1 parent 31d7a7e commit 1716d77
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Application/UI/Presenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,7 @@ public static function argsToParams($class, $method, & $args, $supplemental = []
));
}

if ($args[$name] === $def || ($def === NULL && is_scalar($args[$name]) && (string) $args[$name] === '')) {
if ($args[$name] === $def || ($def === NULL && $args[$name] === '')) {
$args[$name] = NULL; // value transmit is unnecessary
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Application/UI/PresenterComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public function saveState(array & $params, $reflection = NULL)
));
}

if ($params[$name] === $meta['def'] || ($meta['def'] === NULL && is_scalar($params[$name]) && (string) $params[$name] === '')) {
if ($params[$name] === $meta['def'] || ($meta['def'] === NULL && $params[$name] === '')) {
$params[$name] = NULL; // value transmit is unnecessary
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/UI/Presenter.link().php7.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TestPresenter extends Application\UI\Presenter
Assert::same('/index.php?var1=20&action=default&do=hint&presenter=Test', $this->link('hint!', ['var1' => $this->var1 * 2]));
Assert::same('/index.php?y=2&action=default&do=hint&presenter=Test', $this->link('hint!', 1, 2));
Assert::same('/index.php?y=2&bool=1&str=1&action=default&do=hint&presenter=Test', $this->link('hint!', '1', '2', TRUE, TRUE));
Assert::same('/index.php?y=2&str=0&action=default&do=hint&presenter=Test', $this->link('hint!', '1', '2', FALSE, FALSE));
Assert::same('/index.php?y=2&bool=0&str=0&action=default&do=hint&presenter=Test', $this->link('hint!', '1', '2', FALSE, FALSE));
Assert::same('/index.php?action=default&do=hint&presenter=Test', $this->link('hint!', ['str' => '', 'var2' => '']));
Assert::same('/index.php?action=default&do=hint&presenter=Test', $this->link('hint!', [1]));
Assert::same('#error: Argument $x passed to TestPresenter::handleHint() must be int, array given.', $this->link('hint!', [1], (object) [1]));
Expand All @@ -57,7 +57,7 @@ class TestPresenter extends Application\UI\Presenter
// optional arguments
Assert::same('/index.php?y=2&action=default&do=null&presenter=Test', $this->link('null!', 1, 2));
Assert::same('/index.php?y=2&bool=1&str=1&action=default&do=null&presenter=Test', $this->link('null!', '1', '2', TRUE, TRUE));
Assert::same('/index.php?y=2&str=0&action=default&do=null&presenter=Test', $this->link('null!', '1', '2', FALSE, FALSE));
Assert::same('/index.php?y=2&bool=0&str=0&action=default&do=null&presenter=Test', $this->link('null!', '1', '2', FALSE, FALSE));
Assert::same('/index.php?action=default&do=null&presenter=Test', $this->link('null!', ['str' => '', 'var2' => '']));
Assert::same('/index.php?action=default&do=null&presenter=Test', $this->link('null!', [1]));
Assert::same('#error: Argument $x passed to TestPresenter::handleNull() must be int, array given.', $this->link('null!', [1], (object) [1]));
Expand Down
4 changes: 2 additions & 2 deletions tests/UI/Presenter.link().phpt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class TestPresenter extends Application\UI\Presenter
Assert::same('/index.php?action=product&presenter=Test', $this->link('product', ['var1' => $this->var1]));
Assert::same('/index.php?var1=20&action=product&presenter=Test', $this->link('product', ['var1' => $this->var1 * 2, 'ok' => TRUE]));
Assert::same('/index.php?var1=1&ok=0&action=product&presenter=Test', $this->link('product', ['var1' => TRUE, 'ok' => '0']));
Assert::same('/index.php?var1=0&ok=0&action=product&presenter=Test', $this->link('product', ['var1' => FALSE, 'ok' => FALSE, 'var2' => FALSE]));
Assert::same('/index.php?var1=0&ok=0&var2=0&action=product&presenter=Test', $this->link('product', ['var1' => FALSE, 'ok' => FALSE, 'var2' => FALSE]));
Assert::same("#error: Value passed to persistent parameter 'ok' in presenter Test must be boolean, string given.", $this->link('product', ['var1' => NULL, 'ok' => 'a']));
Assert::same("#error: Value passed to persistent parameter 'var1' in presenter Test must be integer, array given.", $this->link('product', ['var1' => [1], 'ok' => FALSE]));
Assert::same("#error: Unable to pass parameters to action 'Test:product', missing corresponding method.", $this->link('product', 1, 2));
Expand Down Expand Up @@ -137,7 +137,7 @@ class TestPresenter extends Application\UI\Presenter
Assert::same('/index.php?mycontrol-x=0a&mycontrol-y=1a&action=default&do=mycontrol-click&presenter=Test', $this['mycontrol']->link('click', '0a', '1a'));
Assert::same('/index.php?mycontrol-x=1&action=default&do=mycontrol-click&presenter=Test', $this['mycontrol']->link('click', [1]));
Assert::same('#error: Argument $x passed to TestControl::handleClick() must be scalar, array given.', $this['mycontrol']->link('click', [1], (object) [1]));
Assert::same('/index.php?mycontrol-x=1&action=default&do=mycontrol-click&presenter=Test', $this['mycontrol']->link('click', TRUE, FALSE));
Assert::same('/index.php?mycontrol-x=1&mycontrol-y=0&action=default&do=mycontrol-click&presenter=Test', $this['mycontrol']->link('click', TRUE, FALSE));
Assert::same('/index.php?action=default&do=mycontrol-click&presenter=Test', $this['mycontrol']->link('click', NULL, ''));
Assert::same('#error: Passed more parameters than method TestControl::handleClick() expects.', $this['mycontrol']->link('click', 1, 2, 3));
Assert::same('/index.php?mycontrol-x=1&mycontrol-y=2&action=default&do=mycontrol-click&presenter=Test', $this['mycontrol']->link('click!', ['x' => 1, 'y' => 2, 'round' => 0]));
Expand Down

0 comments on commit 1716d77

Please sign in to comment.