Skip to content

Commit

Permalink
Tidy up some code sniffer issues
Browse files Browse the repository at this point in the history
  • Loading branch information
g105b committed Oct 3, 2018
1 parent 48fb608 commit fa2ff57
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 35 deletions.
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -6,6 +6,7 @@
"require": {
"php": ">=7.1.0",
"ext-dom": "*",
"ext-mbstring": "*",
"symfony/css-selector": "3.2.14"
},

Expand Down
5 changes: 3 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions src/Element.php
Expand Up @@ -13,6 +13,7 @@
* @property string $className Gets and sets the value of the class attribute
* @property-read TokenList $classList Returns a live TokenList collection of
* the class attributes of the element
* @property bool $checked Indicates whether the element is checked or not
* @property string $value Gets or sets the value of the element according to
* its element type
* @property string $id Gets or sets the value of the id attribute
Expand Down Expand Up @@ -201,18 +202,18 @@ public function prop_get_checked():bool {

public function prop_set_checked(bool $checked):bool {
if ($checked) {
if ($this->getAttribute('type') === 'radio') {
if ($this->getAttribute("type") === "radio") {
// TODO: Use `form` attribute when implemented: https://github.com/PhpGt/Dom/issues/161
$parentForm = $this->closest('form');
$parentForm = $this->closest("form");
if (!is_null($parentForm)) {
self::formRemoveCheckedAttributeFromElementsWithName($parentForm, $this->getAttribute('name'));
self::formRemoveCheckedAttributeFromElementsWithName($parentForm, $this->getAttribute("name"));
}
}

$this->setAttribute('checked', 'checked');
$this->setAttribute("checked", "checked");
}
else {
$this->removeAttribute('checked');
$this->removeAttribute("checked");
}

return $this->checked;
Expand Down
56 changes: 28 additions & 28 deletions test/unit/FormTest.php
Expand Up @@ -5,32 +5,32 @@
use Gt\Dom\HTMLDocument;
use Gt\Dom\Test\Helper\Helper;

class FormTest extends TestCase {
public function testMultipleRadioCanNotBeCheckedViaProperty() {
$document = new HTMLDocument(Helper::HTML_FORM_WITH_RADIOS);
$whiteRadio = $document->querySelector("input[value=white]");
$blackRadio = $document->querySelector("input[value=black]");
$whiteRadio->checked = true;
self::assertTrue(
$whiteRadio->hasAttribute("checked"),
"Checked attribute should be present on white radio after setting property on white."
);
self::assertFalse(
$blackRadio->hasAttribute("checked"),
"Checked attribute should not be present on black radio after setting property on white."
);
$blackRadio->checked = true;
self::assertFalse(
$whiteRadio->hasAttribute("checked"),
"Checked attribute should not be present on white after setting property on black."
);
self::assertTrue(
$blackRadio->hasAttribute("checked"),
"Checked attribute should be present on black after setting property on black."
);
}
class FormTest extends TestCase {
public function testMultipleRadioCanNotBeCheckedViaProperty() {
$document = new HTMLDocument(Helper::HTML_FORM_WITH_RADIOS);
$whiteRadio = $document->querySelector("input[value=white]");
$blackRadio = $document->querySelector("input[value=black]");

$whiteRadio->checked = true;

self::assertTrue(
$whiteRadio->hasAttribute("checked"),
"Checked attribute should be present on white radio after setting property on white."
);
self::assertFalse(
$blackRadio->hasAttribute("checked"),
"Checked attribute should not be present on black radio after setting property on white."
);

$blackRadio->checked = true;

self::assertFalse(
$whiteRadio->hasAttribute("checked"),
"Checked attribute should not be present on white after setting property on black."
);
self::assertTrue(
$blackRadio->hasAttribute("checked"),
"Checked attribute should be present on black after setting property on black."
);
}
}

0 comments on commit fa2ff57

Please sign in to comment.