-
-
Notifications
You must be signed in to change notification settings - Fork 524
fix(processors): normalize string 'true'/'false' to boolean in getProperty #16888
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Ibochkarev
wants to merge
7
commits into
modxcms:3.x
Choose a base branch
from
Ibochkarev:fix/processor-boolean-property-normalization
base: 3.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+4
−3
Open
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
81e30e2
fix(processors): normalize string 'true'/'false' to boolean in getPro…
Ibochkarev 516fac6
Update core/src/Revolution/Processors/Processor.php
Ibochkarev 8cd8708
Update core/src/Revolution/Processors/Processor.php
Ibochkarev bfe970c
Update core/src/Revolution/Processors/Processor.php
Ibochkarev c928dc5
fix(processors): add getBooleanProperty(), keep getProperty() unchanged
Ibochkarev 858d4af
Update core/src/Revolution/Processors/Resource/Get.php
Ibochkarev 205c2c1
refactor: address PR review — keep only Resource/Get fix
Ibochkarev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file is part of the MODX Revolution package. | ||
| * | ||
| * Copyright (c) MODX, LLC | ||
| * | ||
| * For complete copyright and license information, see the COPYRIGHT and LICENSE | ||
| * files found in the top-level directory of this distribution. | ||
| * | ||
| * @package modx-test | ||
| */ | ||
|
|
||
| namespace MODX\Revolution\Tests\Processors; | ||
|
|
||
| use MODX\Revolution\MODxTestCase; | ||
| use MODX\Revolution\Processors\Processor; | ||
|
|
||
| /** | ||
| * Tests for Processor::getBooleanProperty() normalization. | ||
| * | ||
| * @package modx-test | ||
| * @subpackage modx | ||
| * @group Processors | ||
| * @group Processor | ||
| */ | ||
| class ProcessorTest extends MODxTestCase | ||
| { | ||
| /** | ||
| * @return Processor | ||
| */ | ||
| private function createProcessor(array $properties = []): Processor | ||
| { | ||
| return new class ($this->modx, $properties) extends Processor { | ||
| public function process() | ||
| { | ||
| return $this->success(); | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| public function testGetBooleanPropertyStringTrue(): void | ||
| { | ||
| $p = $this->createProcessor(['flag' => 'true']); | ||
| $this->assertTrue($p->getBooleanProperty('flag', false)); | ||
| } | ||
|
|
||
| public function testGetBooleanPropertyStringTrueCaseInsensitive(): void | ||
| { | ||
| $p = $this->createProcessor(['flag' => 'TRUE']); | ||
| $this->assertTrue($p->getBooleanProperty('flag', false)); | ||
|
|
||
| $p = $this->createProcessor(['flag' => 'True']); | ||
| $this->assertTrue($p->getBooleanProperty('flag', false)); | ||
| } | ||
|
|
||
| public function testGetBooleanPropertyStringTrueTrimmed(): void | ||
| { | ||
| $p = $this->createProcessor(['flag' => ' true ']); | ||
| $this->assertTrue($p->getBooleanProperty('flag', false)); | ||
| } | ||
|
|
||
| public function testGetBooleanPropertyStringFalse(): void | ||
| { | ||
| $p = $this->createProcessor(['flag' => 'false']); | ||
| $this->assertFalse($p->getBooleanProperty('flag', true)); | ||
| } | ||
|
|
||
| public function testGetBooleanPropertyStringFalseCaseInsensitive(): void | ||
| { | ||
| $p = $this->createProcessor(['flag' => 'FALSE']); | ||
| $this->assertFalse($p->getBooleanProperty('flag', true)); | ||
|
|
||
| $p = $this->createProcessor(['flag' => ' False ']); | ||
| $this->assertFalse($p->getBooleanProperty('flag', true)); | ||
| } | ||
|
|
||
| public function testGetBooleanPropertyOnYesOne(): void | ||
| { | ||
| $p = $this->createProcessor(['a' => 'on', 'b' => 'yes', 'c' => '1']); | ||
| $this->assertTrue($p->getBooleanProperty('a', false)); | ||
| $this->assertTrue($p->getBooleanProperty('b', false)); | ||
| $this->assertTrue($p->getBooleanProperty('c', false)); | ||
| } | ||
|
|
||
| public function testGetBooleanPropertyOffNoZero(): void | ||
| { | ||
| $p = $this->createProcessor(['a' => 'off', 'b' => 'no', 'c' => '0']); | ||
| $this->assertFalse($p->getBooleanProperty('a', true)); | ||
| $this->assertFalse($p->getBooleanProperty('b', true)); | ||
| $this->assertFalse($p->getBooleanProperty('c', true)); | ||
| } | ||
|
|
||
| public function testGetBooleanPropertyMissingKeyReturnsDefault(): void | ||
| { | ||
| $p = $this->createProcessor([]); | ||
| $this->assertFalse($p->getBooleanProperty('missing', false)); | ||
| $this->assertTrue($p->getBooleanProperty('missing', true)); | ||
| } | ||
|
|
||
| public function testGetBooleanPropertyNativeBoolean(): void | ||
| { | ||
| $p = $this->createProcessor(['t' => true, 'f' => false]); | ||
| $this->assertTrue($p->getBooleanProperty('t', false)); | ||
| $this->assertFalse($p->getBooleanProperty('f', true)); | ||
| } | ||
|
|
||
| public function testGetBooleanPropertyNonStringCastedToBool(): void | ||
| { | ||
| $p = $this->createProcessor(['one' => 1, 'zero' => 0]); | ||
| $this->assertTrue($p->getBooleanProperty('one', false)); | ||
| $this->assertFalse($p->getBooleanProperty('zero', true)); | ||
| } | ||
|
|
||
| public function testGetBooleanPropertyUnknownStringReturnsDefault(): void | ||
| { | ||
| $p = $this->createProcessor(['key' => 'unknown']); | ||
| $this->assertFalse($p->getBooleanProperty('key', false)); | ||
| $this->assertTrue($p->getBooleanProperty('key', true)); | ||
| } | ||
|
|
||
| public function testGetBooleanPropertyEmptyStringReturnsDefault(): void | ||
| { | ||
| $p = $this->createProcessor(['key' => '']); | ||
| $this->assertFalse($p->getBooleanProperty('key', false)); | ||
| $this->assertTrue($p->getBooleanProperty('key', true)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.