diff --git a/src/Style/CheckboxStyle.php b/src/Style/CheckboxStyle.php index 5d20ee64..19553227 100644 --- a/src/Style/CheckboxStyle.php +++ b/src/Style/CheckboxStyle.php @@ -31,11 +31,6 @@ class CheckboxStyle */ private $displaysExtra; - /** - * @var bool - */ - private $custom = false; - public function __construct() { $this->markerOn = self::DEFAULT_STYLES['markerOn']; @@ -46,7 +41,14 @@ public function __construct() public function hasChangedFromDefaults() : bool { - return $this->custom; + $currentValues = [ + $this->markerOn, + $this->markerOff, + $this->itemExtra, + $this->displaysExtra, + ]; + + return $currentValues !== array_values(self::DEFAULT_STYLES); } public function getMarker(bool $selected) : string @@ -61,8 +63,6 @@ public function getMarkerOn() : string public function setMarkerOn(string $marker) : self { - $this->custom = true; - $this->markerOn = $marker; return $this; @@ -75,8 +75,6 @@ public function getMarkerOff() : string public function setMarkerOff(string $marker) : self { - $this->custom = true; - $this->markerOff = $marker; return $this; @@ -89,8 +87,6 @@ public function getItemExtra() : string public function setItemExtra(string $itemExtra) : self { - $this->custom = true; - $this->itemExtra = $itemExtra; // if we customise item extra, it means we most likely want to display it @@ -106,8 +102,6 @@ public function getDisplaysExtra() : bool public function setDisplaysExtra(bool $displaysExtra) : self { - $this->custom = true; - $this->displaysExtra = $displaysExtra; return $this; diff --git a/src/Style/RadioStyle.php b/src/Style/RadioStyle.php index a2064a2a..f8b300cd 100644 --- a/src/Style/RadioStyle.php +++ b/src/Style/RadioStyle.php @@ -46,7 +46,14 @@ public function __construct() public function hasChangedFromDefaults() : bool { - return $this->custom; + $currentValues = [ + $this->markerOn, + $this->markerOff, + $this->itemExtra, + $this->displaysExtra, + ]; + + return $currentValues !== array_values(self::DEFAULT_STYLES); } public function getMarker(bool $selected) : string @@ -61,8 +68,6 @@ public function getMarkerOn() : string public function setMarkerOn(string $marker) : self { - $this->custom = true; - $this->markerOn = $marker; return $this; @@ -75,8 +80,6 @@ public function getMarkerOff() : string public function setMarkerOff(string $marker) : self { - $this->custom = true; - $this->markerOff = $marker; return $this; @@ -89,8 +92,6 @@ public function getItemExtra() : string public function setItemExtra(string $itemExtra) : self { - $this->custom = true; - $this->itemExtra = $itemExtra; // if we customise item extra, it means we most likely want to display it @@ -106,8 +107,6 @@ public function getDisplaysExtra() : bool public function setDisplaysExtra(bool $displaysExtra) : self { - $this->custom = true; - $this->displaysExtra = $displaysExtra; return $this; diff --git a/test/Style/CheckboxStyleTest.php b/test/Style/CheckboxStyleTest.php new file mode 100644 index 00000000..7f3e7fb9 --- /dev/null +++ b/test/Style/CheckboxStyleTest.php @@ -0,0 +1,81 @@ +hasChangedFromDefaults()); + } + + public function testGetMarker() : void + { + $style = new CheckboxStyle; + + self::assertSame('[✔] ', $style->getMarker(true)); + self::assertSame('[ ] ', $style->getMarker(false)); + } + + public function testGetSetMarkerOn() : void + { + $style = new CheckboxStyle; + + self::assertSame('[✔] ', $style->getMarkerOn()); + + $style->setMarkerOn('[x] '); + + self::assertSame('[x] ', $style->getMarkerOn()); + self::assertTrue($style->hasChangedFromDefaults()); + } + + public function testGetSetMarkerOff() : void + { + $style = new CheckboxStyle; + + self::assertSame('[ ] ', $style->getMarkerOff()); + + $style->setMarkerOff('( ) '); + + self::assertSame('( ) ', $style->getMarkerOff()); + self::assertTrue($style->hasChangedFromDefaults()); + } + + public function testGetSetItemExtra() : void + { + $style = new CheckboxStyle; + + self::assertSame('✔', $style->getItemExtra()); + + $style->setItemExtra('[!EXTRA]!'); + + self::assertSame('[!EXTRA]!', $style->getItemExtra()); + self::assertTrue($style->hasChangedFromDefaults()); + } + + public function testModifyingItemExtraForcesExtraToBeDisplayedWhenNoItemsDisplayExtra() : void + { + $style = new CheckboxStyle; + self::assertFalse($style->getDisplaysExtra()); + + $style->setItemExtra('[!EXTRA]!'); + self::assertTrue($style->getDisplaysExtra()); + } + + public function testGetSetDisplayExtra() : void + { + $style = new CheckboxStyle; + + self::assertFalse($style->getDisplaysExtra()); + + $style->setDisplaysExtra(true); + + self::assertTrue($style->getDisplaysExtra()); + self::assertTrue($style->hasChangedFromDefaults()); + } +} diff --git a/test/Style/RadioStyleTest.php b/test/Style/RadioStyleTest.php new file mode 100644 index 00000000..eabf2919 --- /dev/null +++ b/test/Style/RadioStyleTest.php @@ -0,0 +1,81 @@ +hasChangedFromDefaults()); + } + + public function testGetMarker() : void + { + $style = new RadioStyle; + + self::assertSame('[●] ', $style->getMarker(true)); + self::assertSame('[○] ', $style->getMarker(false)); + } + + public function testGetSetMarkerOn() : void + { + $style = new RadioStyle; + + self::assertSame('[●] ', $style->getMarkerOn()); + + $style->setMarkerOn('[x] '); + + self::assertSame('[x] ', $style->getMarkerOn()); + self::assertTrue($style->hasChangedFromDefaults()); + } + + public function testGetSetMarkerOff() : void + { + $style = new RadioStyle; + + self::assertSame('[○] ', $style->getMarkerOff()); + + $style->setMarkerOff('( ) '); + + self::assertSame('( ) ', $style->getMarkerOff()); + self::assertTrue($style->hasChangedFromDefaults()); + } + + public function testGetSetItemExtra() : void + { + $style = new RadioStyle; + + self::assertSame('✔', $style->getItemExtra()); + + $style->setItemExtra('[!EXTRA]!'); + + self::assertSame('[!EXTRA]!', $style->getItemExtra()); + self::assertTrue($style->hasChangedFromDefaults()); + } + + public function testModifyingItemExtraForcesExtraToBeDisplayedWhenNoItemsDisplayExtra() : void + { + $style = new RadioStyle; + self::assertFalse($style->getDisplaysExtra()); + + $style->setItemExtra('[!EXTRA]!'); + self::assertTrue($style->getDisplaysExtra()); + } + + public function testGetSetDisplayExtra() : void + { + $style = new RadioStyle; + + self::assertFalse($style->getDisplaysExtra()); + + $style->setDisplaysExtra(true); + + self::assertTrue($style->getDisplaysExtra()); + self::assertTrue($style->hasChangedFromDefaults()); + } +}