Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-3856: Changed Checkbox's value to never be considered empty #336

Merged
merged 5 commits into from Oct 6, 2022

Conversation

mnocon
Copy link
Member

@mnocon mnocon commented Sep 22, 2022

Question Answer
JIRA issue IBX-3856
Type bugfix
Target Ibexa version v3.3
BC breaks yes, not significant

Replacement for https://github.com/ezsystems/ezplatform-version-comparison/pull/81

I've:

  1. implemented a failing test showing the desired behaviour (ab459ce)
  2. implemented the actual change (the new test now passes) (e01db7a)
  3. smuggled a small improvement to the codebase (9f21465) - the isEmptyValue(SPIValue $value) signature does not allow nulls, this removal is even suggested by PHPStorm.

In the original discussion there was this suggestion:

From my point of view, isEmptyValue for CheckboxFieldtype should check only for null value as default value have that value set.

But I'm not sure about it - the default value seems to be false and null seems is not even specified as an allowed value:
https://github.com/ezsystems/ezplatform-kernel/blob/1.3/eZ/Publish/Core/Persistence/Legacy/Content/FieldValue/Converter/CheckboxConverter.php#L74
https://github.com/ezsystems/ezplatform-kernel/blob/1.3/eZ/Publish/Core/Persistence/Legacy/Content/FieldValue/Converter/CheckboxConverter.php#L39
https://github.com/ezsystems/ezplatform-kernel/blob/1.3/eZ/Publish/Core/FieldType/Checkbox/Value.php#L16-L21

Changing the default value to null (and allowing the value to be bool|null) seems like asking for trouble, because 3rd party code might not be ready to deal with nulls in the value - that's why I went the "this field is never empty" way.

If accepted, I will prepare a PR removing this condition:
https://github.com/ezsystems/ezplatform-admin-ui/blob/e9f2b07f26a47f0158417ea0e2ddf4f0ea5436b7/src/bundle/Resources/views/themes/admin/content/content_view_fields.html.twig#L25

as it will be no longer needed.

I will gladly accept any feedback, as my kernel-fu is very, very basic 馃槃

Checklist:

  • Provided PR description.
  • Tested the solution manually.
  • Provided automated test coverage.
  • Checked that target branch is set correctly (master for features, the oldest supported for bugs).
  • Ran PHP CS Fixer for new PHP code (use $ composer fix-cs).
  • Asked for a review (ping @ezsystems/engineering-team).

@mnocon mnocon changed the title Added test IBX-3856: Changed Checkbox's value to never be considered empty Sep 22, 2022
@mnocon mnocon force-pushed the IBX-3856-ezboolean-empty-when-false branch from f622579 to 9513b80 Compare September 22, 2022 20:01
@mnocon mnocon force-pushed the IBX-3856-ezboolean-empty-when-false branch 2 times, most recently from 0992bc2 to 82fcdc5 Compare September 22, 2022 20:27
@mnocon mnocon force-pushed the IBX-3856-ezboolean-empty-when-false branch from 82fcdc5 to 7e8a12c Compare September 22, 2022 20:43
@mnocon mnocon marked this pull request as ready for review September 23, 2022 07:56
@mnocon mnocon requested a review from a team September 23, 2022 07:56
@alongosz alongosz added the Doc needed The changes require some documentation label Sep 23, 2022
@@ -392,6 +387,21 @@ public function testFindContentFieldCriterion(bool $isActive): void
self::assertSame($isActive, $value->bool);
}

public function testAddFieldDefinition()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function testAddFieldDefinition()
public function testAddFieldDefinition(): void

Comment on lines 392 to 394
$content = $this->addFieldDefinition();

$this->assertCount(2, $content->getFields());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would like to see sanity check prior addFieldDefinition - assert count = 1

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how to do this - this test is a variation of the base one:

public function testAddFieldDefinition()
{
$content = $this->addFieldDefinition();
$this->assertCount(2, $content->getFields());
$this->assertTrue(
$this->getRepository()->getFieldTypeService()->getFieldType(
$this->getTypeName()
)->isEmptyValue(
$content->getFieldValue('data')
)
);
}

But I had to change the assertion.

The method 'addFieldDefinition` first removes the fieldDefinition:


and then adds it again

The flow inside addFieldDefinition looks like this then:

  • The Content item is created (with 2 fields)
  • the tested field definition is removed
  • the tested field definition is added again

Current approach makes the $content variable available only after the call to addFieldDefinition finishes, I can't really add that sanity check without reworking this test.

I wanted to reuse the existing setup methods, but if you think it's good to add some custom setup for this test then I will do it

{
$content = $this->addFieldDefinition();

$this->assertCount(2, $content->getFields());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Static methods should be called statically.

Suggested change
$this->assertCount(2, $content->getFields());
self::assertCount(2, $content->getFields());


$this->assertCount(2, $content->getFields());

$this->assertFalse(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$this->assertFalse(
self::assertFalse(

$this->assertCount(2, $content->getFields());

$this->assertFalse(
$this->getRepository()->getFieldTypeService()->getFieldType(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Readability, please extract

$fieldTypeService = $this->getRepository()->getFieldTypeService()

as the first call of the method. If you need to call it after addFieldDefinition then it should be called as getRepository(false) because the method has side effects.

/**
* @dataProvider provideForValueIsNeverEmpty
*/
public function testValueIsNeverEmpty(CheckboxValue $value)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function testValueIsNeverEmpty(CheckboxValue $value)
public function testValueIsNeverEmpty(CheckboxValue $value): void

@alongosz
Copy link
Member

@ezsystems/documentation-team this is behavior change - CheckBox Field Type after the change is not going to be considered as empty in any case - it can be either true or false. This should be reflected on the Doc page for that Field Type.

@sonarcloud
Copy link

sonarcloud bot commented Sep 23, 2022

Kudos, SonarCloud Quality Gate passed!聽 聽 Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Copy link

@tomaszszopinski tomaszszopinski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QA approved IbexaDXP 3.3 commerce.

@adamwojs adamwojs merged commit 776eb56 into 1.3 Oct 6, 2022
@adamwojs adamwojs deleted the IBX-3856-ezboolean-empty-when-false branch October 6, 2022 08:26
alongosz added a commit to ibexa/core that referenced this pull request Oct 6, 2022
Merged up ezsystems/ezplatform-kernel#336

Co-Authored-By: Marek Noco艅 <mnocon@users.noreply.github.com>
@DominikaK DominikaK removed the Doc needed The changes require some documentation label Oct 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
10 participants