diff --git a/src/PhpSpreadsheet/Style/Color.php b/src/PhpSpreadsheet/Style/Color.php index 1cb141a8..534bcc9f 100644 --- a/src/PhpSpreadsheet/Style/Color.php +++ b/src/PhpSpreadsheet/Style/Color.php @@ -63,7 +63,7 @@ class Color extends Supervisor // Initialise values if (!$isConditional) { - $this->argb = $this->validateColour($colorValue, self::VALIDATE_ARGB_SIZE) ? $colorValue : self::COLOR_BLACK; + $this->argb = $this->validateColor($colorValue, self::VALIDATE_ARGB_SIZE) ? $colorValue : self::COLOR_BLACK; } } @@ -124,9 +124,9 @@ class Color extends Supervisor return $this; } - private function validateColour(string $colorValue, int $size): bool + private function validateColor(string $colorValue, int $size): bool { - return in_array(ucfirst($colorValue), self::NAMED_COLORS) || + return in_array(ucfirst(strtolower($colorValue)), self::NAMED_COLORS) || preg_match(sprintf(self::VALIDATE_COLOR_VALUE, $size), $colorValue); } @@ -155,7 +155,7 @@ class Color extends Supervisor { if ($colorValue === '' || $colorValue === null) { $colorValue = self::COLOR_BLACK; - } elseif (!$this->validateColour($colorValue, self::VALIDATE_ARGB_SIZE)) { + } elseif (!$this->validateColor($colorValue, self::VALIDATE_ARGB_SIZE)) { return $this; } @@ -194,7 +194,7 @@ class Color extends Supervisor { if ($colorValue === '' || $colorValue === null) { $colorValue = '000000'; - } elseif (!$this->validateColour($colorValue, self::VALIDATE_RGB_SIZE)) { + } elseif (!$this->validateColor($colorValue, self::VALIDATE_RGB_SIZE)) { return $this; } diff --git a/tests/PhpSpreadsheetTests/CommentTest.php b/tests/PhpSpreadsheetTests/CommentTest.php new file mode 100644 index 00000000..3fd22854 --- /dev/null +++ b/tests/PhpSpreadsheetTests/CommentTest.php @@ -0,0 +1,76 @@ +getAuthor()); + self::assertEquals('96pt', $comment->getWidth()); + self::assertEquals('59.25pt', $comment->getMarginLeft()); + self::assertEquals('1.5pt', $comment->getMarginTop()); + self::assertEquals('55.5pt', $comment->getHeight()); + self::assertInstanceOf(Color::class, $comment->getFillColor()); + self::assertEquals('FFFFFFE1', $comment->getFillColor()->getARGB()); + self::assertInstanceOf(RichText::class, $comment->getText()); + self::assertEquals(Alignment::HORIZONTAL_GENERAL, $comment->getAlignment()); + self::assertFalse($comment->getVisible()); + } + + public function testSetAuthor() + { + $comment = new Comment(); + $comment->setAuthor('Mark Baker'); + self::assertEquals('Mark Baker', $comment->getAuthor()); + } + + public function testSetMarginLeft() + { + $comment = new Comment(); + $comment->setMarginLeft('20pt'); + self::assertEquals('20pt', $comment->getMarginLeft()); + } + + public function testSetMarginTop() + { + $comment = new Comment(); + $comment->setMarginTop('2.5pt'); + self::assertEquals('2.5pt', $comment->getMarginTop()); + } + + public function testSetWidth() + { + $comment = new Comment(); + $comment->setWidth('120pt'); + self::assertEquals('120pt', $comment->getWidth()); + } + + public function testSetHeight() + { + $comment = new Comment(); + $comment->setHeight('60pt'); + self::assertEquals('60pt', $comment->getHeight()); + } + + public function testSetFillColor() + { + $comment = new Comment(); + $comment->setFillColor(new Color('RED')); + self::assertEquals('RED', $comment->getFillColor()->getARGB()); + } + + public function testSetAlignment() + { + $comment = new Comment(); + $comment->setAlignment(Alignment::HORIZONTAL_CENTER); + self::assertEquals(Alignment::HORIZONTAL_CENTER, $comment->getAlignment()); + } +}