Skip to content

Commit 25a55a7

Browse files
enumagdg
authored andcommitted
Presenter: argsToParams() and saveState() now distinguish between NULL and FALSE [Closes #107]
# Conflicts: # tests/UI/Presenter.link().php7.phpt
1 parent d47468f commit 25a55a7

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

src/Application/UI/Presenter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,7 @@ public static function argsToParams($class, $method, & $args, $supplemental = []
10471047
));
10481048
}
10491049

1050-
if ($args[$name] === $def || ($def === NULL && is_scalar($args[$name]) && (string) $args[$name] === '')) {
1050+
if ($args[$name] === $def || ($def === NULL && $args[$name] === '')) {
10511051
$args[$name] = NULL; // value transmit is unnecessary
10521052
}
10531053
}

src/Application/UI/PresenterComponent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public function saveState(array & $params, $reflection = NULL)
178178
));
179179
}
180180

181-
if ($params[$name] === $meta['def'] || ($meta['def'] === NULL && is_scalar($params[$name]) && (string) $params[$name] === '')) {
181+
if ($params[$name] === $meta['def'] || ($meta['def'] === NULL && $params[$name] === '')) {
182182
$params[$name] = NULL; // value transmit is unnecessary
183183
}
184184
}

tests/UI/Presenter.link().php7.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class TestPresenter extends Application\UI\Presenter
3636
Assert::same('/index.php?var1=20&action=default&do=hint&presenter=Test', $this->link('hint!', ['var1' => $this->var1 * 2]));
3737
Assert::same('/index.php?y=2&action=default&do=hint&presenter=Test', $this->link('hint!', 1, 2));
3838
Assert::same('/index.php?y=2&bool=1&str=1&action=default&do=hint&presenter=Test', $this->link('hint!', '1', '2', TRUE, TRUE));
39-
Assert::same('/index.php?y=0&str=0&action=default&do=hint&presenter=Test', $this->link('hint!', '1', 0, FALSE, FALSE));
39+
Assert::same('/index.php?y=0&bool=0&str=0&action=default&do=hint&presenter=Test', $this->link('hint!', '1', 0, FALSE, FALSE));
4040
Assert::same('/index.php?action=default&do=hint&presenter=Test', $this->link('hint!', ['str' => '', 'var2' => '']));
4141
Assert::same('/index.php?action=default&do=hint&presenter=Test', $this->link('hint!', [1]));
4242
Assert::same('#error: Argument $x passed to TestPresenter::handleHint() must be int, array given.', $this->link('hint!', [1], (object) [1]));
@@ -57,7 +57,7 @@ class TestPresenter extends Application\UI\Presenter
5757
// optional arguments
5858
Assert::same('/index.php?y=2&action=default&do=null&presenter=Test', $this->link('null!', 1, 2));
5959
Assert::same('/index.php?y=2&bool=1&str=1&action=default&do=null&presenter=Test', $this->link('null!', '1', '2', TRUE, TRUE));
60-
Assert::same('/index.php?y=0&str=0&action=default&do=null&presenter=Test', $this->link('null!', '1', 0, FALSE, FALSE));
60+
Assert::same('/index.php?y=0&bool=0&str=0&action=default&do=null&presenter=Test', $this->link('null!', '1', 0, FALSE, FALSE));
6161
Assert::same('/index.php?action=default&do=null&presenter=Test', $this->link('null!', ['str' => '', 'var2' => '']));
6262
Assert::same('/index.php?action=default&do=null&presenter=Test', $this->link('null!', [1]));
6363
Assert::same('#error: Argument $x passed to TestPresenter::handleNull() must be int, array given.', $this->link('null!', [1], (object) [1]));

tests/UI/Presenter.link().phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class TestPresenter extends Application\UI\Presenter
8383
Assert::same('/index.php?action=product&presenter=Test', $this->link('product', ['var1' => $this->var1]));
8484
Assert::same('/index.php?var1=20&action=product&presenter=Test', $this->link('product', ['var1' => $this->var1 * 2, 'ok' => TRUE]));
8585
Assert::same('/index.php?var1=1&ok=0&action=product&presenter=Test', $this->link('product', ['var1' => TRUE, 'ok' => '0']));
86-
Assert::same('/index.php?var1=0&ok=0&action=product&presenter=Test', $this->link('product', ['var1' => FALSE, 'ok' => FALSE, 'var2' => FALSE]));
86+
Assert::same('/index.php?var1=0&ok=0&var2=0&action=product&presenter=Test', $this->link('product', ['var1' => FALSE, 'ok' => FALSE, 'var2' => FALSE]));
8787
Assert::same("#error: Value passed to persistent parameter 'ok' in presenter Test must be boolean, string given.", $this->link('product', ['var1' => NULL, 'ok' => 'a']));
8888
Assert::same("#error: Value passed to persistent parameter 'var1' in presenter Test must be integer, array given.", $this->link('product', ['var1' => [1], 'ok' => FALSE]));
8989
Assert::same("#error: Unable to pass parameters to action 'Test:product', missing corresponding method.", $this->link('product', 1, 2));
@@ -137,7 +137,7 @@ class TestPresenter extends Application\UI\Presenter
137137
Assert::same('/index.php?mycontrol-x=0a&mycontrol-y=1a&action=default&do=mycontrol-click&presenter=Test', $this['mycontrol']->link('click', '0a', '1a'));
138138
Assert::same('/index.php?mycontrol-x=1&action=default&do=mycontrol-click&presenter=Test', $this['mycontrol']->link('click', [1]));
139139
Assert::same('#error: Argument $x passed to TestControl::handleClick() must be scalar, array given.', $this['mycontrol']->link('click', [1], (object) [1]));
140-
Assert::same('/index.php?mycontrol-x=1&action=default&do=mycontrol-click&presenter=Test', $this['mycontrol']->link('click', TRUE, FALSE));
140+
Assert::same('/index.php?mycontrol-x=1&mycontrol-y=0&action=default&do=mycontrol-click&presenter=Test', $this['mycontrol']->link('click', TRUE, FALSE));
141141
Assert::same('/index.php?action=default&do=mycontrol-click&presenter=Test', $this['mycontrol']->link('click', NULL, ''));
142142
Assert::same('#error: Passed more parameters than method TestControl::handleClick() expects.', $this['mycontrol']->link('click', 1, 2, 3));
143143
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]));

0 commit comments

Comments
 (0)