diff --git a/composer.json b/composer.json index 51ae66ea..2c9a6c6a 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,10 @@ "scripts": { "ci:phpcs": "phpcs -q --report=checkstyle | cs2pr", "ci:psalm": "psalm --output-format=github --shepherd --stats", - "ci:coverage": "paratest --coverage-clover dist/phpunit/clover.xml", + "ci:coverage": [ + "Composer\\Config::disableProcessTimeout", + "paratest --coverage-clover dist/phpunit/clover.xml" + ], "ci:unit": "paratest --testsuite Unit", "ci:integration": "paratest --testsuite Integration", "ci:mutation": [ @@ -53,7 +56,7 @@ ], "test:phpcs": "phpcs", "test:psalm": "psalm --no-cache", - "test:unit": "paratest --testsuite Unit", + "test:unit": "phpunit --testsuite Unit", "test:integration": "paratest --testsuite Integration", "test:coverage": "paratest --coverage-html dist/phpunit/html && echo \"Open the result on your browser: $PWD/dist/phpunit/html/index.html\"" }, diff --git a/src/Blocks/BulletedListItem.php b/src/Blocks/BulletedListItem.php index affd65ba..3e70bace 100644 --- a/src/Blocks/BulletedListItem.php +++ b/src/Blocks/BulletedListItem.php @@ -2,6 +2,7 @@ namespace Notion\Blocks; +use Notion\Common\Color; use Notion\Common\RichText; /** @@ -13,6 +14,7 @@ * @psalm-type BulletedListItemJson = array{ * bulleted_list_item: array{ * rich_text: list, + * color?: string, * children?: list, * }, * } @@ -28,6 +30,7 @@ class BulletedListItem implements BlockInterface private function __construct( private readonly BlockMetadata $metadata, public readonly array $text, + public readonly Color $color, public readonly array $children, ) { $this->metadata->checkType(BlockType::BulletedListItem); @@ -40,7 +43,7 @@ public static function create(): self { $metadata = BlockMetadata::create(BlockType::BulletedListItem); - return new self($metadata, [], []); + return new self($metadata, [], Color::Default, []); } /** @@ -51,7 +54,7 @@ public static function fromString(string $content): self $metadata = BlockMetadata::create(BlockType::BulletedListItem); $text = [ RichText::fromString($content) ]; - return new self($metadata, $text, []); + return new self($metadata, $text, Color::Default, []); } public static function fromArray(array $array): self @@ -64,9 +67,11 @@ public static function fromArray(array $array): self $text = array_map(fn($t) => RichText::fromArray($t), $item["rich_text"]); + $color = Color::tryFrom($item["color"] ?? "") ?? Color::Default; + $children = array_map(fn($b) => BlockFactory::fromArray($b), $item["children"] ?? []); - return new self($metadata, $text, $children); + return new self($metadata, $text, $color, $children); } public function toArray(): array @@ -75,6 +80,7 @@ public function toArray(): array $array["bulleted_list_item"] = [ "rich_text" => array_map(fn(RichText $t) => $t->toArray(), $this->text), + "color" => $this->color->value, "children" => array_map(fn(BlockInterface $b) => $b->toArray(), $this->children), ]; @@ -94,7 +100,7 @@ public function metadata(): BlockMetadata public function changeText(RichText ...$text): self { - return new self($this->metadata->update(), $text, $this->children); + return new self($this->metadata->update(), $text, $this->color, $this->children); } /** @@ -105,7 +111,7 @@ public function addText(RichText $text): self $texts = $this->text; $texts[] = $text; - return new self($this->metadata, $texts, $this->children); + return new self($this->metadata, $texts, $this->color, $this->children); } public function changeChildren(BlockInterface ...$children): self @@ -115,6 +121,7 @@ public function changeChildren(BlockInterface ...$children): self return new self( $this->metadata->updateHasChildren($hasChildren), $this->text, + $this->color, $children, ); } @@ -127,15 +134,27 @@ public function addChild(BlockInterface $child): self return new self( $this->metadata->updateHasChildren(true), $this->text, + $this->color, $children, ); } + public function changeColor(Color $color): self + { + return new self( + $this->metadata->update(), + $this->text, + $color, + $this->children, + ); + } + public function archive(): BlockInterface { return new self( $this->metadata->archive(), $this->text, + $this->color, $this->children, ); } diff --git a/src/Blocks/Callout.php b/src/Blocks/Callout.php index cede3e61..5668ccb1 100644 --- a/src/Blocks/Callout.php +++ b/src/Blocks/Callout.php @@ -2,6 +2,7 @@ namespace Notion\Blocks; +use Notion\Common\Color; use Notion\Common\Emoji; use Notion\Common\File; use Notion\Common\Icon; @@ -16,6 +17,7 @@ * @psalm-type CalloutJson = array{ * callout: array{ * rich_text: list, + * color?: string, * children?: list, * icon: EmojiJson|FileJson, * }, @@ -33,6 +35,7 @@ private function __construct( private readonly BlockMetadata $metadata, public readonly array $text, public readonly Icon $icon, + public readonly Color $color, public readonly array $children, ) { $metadata->checkType(BlockType::Callout); @@ -43,7 +46,7 @@ public static function create(): self $metadata = BlockMetadata::create(BlockType::Callout); $icon = Icon::fromEmoji(Emoji::fromString("⭐")); - return new self($metadata, [], $icon, []); + return new self($metadata, [], $icon, Color::Default, []); } public static function fromString(string $emoji, string $content): self @@ -52,7 +55,7 @@ public static function fromString(string $emoji, string $content): self $text = [ RichText::fromString($content) ]; $icon = Icon::fromEmoji(Emoji::fromString($emoji)); - return new self($metadata, $text, $icon, []); + return new self($metadata, $text, $icon, Color::Default, []); } public static function fromArray(array $array): self @@ -76,9 +79,11 @@ public static function fromArray(array $array): self $icon = Icon::fromFile($file); } + $color = Color::tryFrom($callout["color"] ?? "") ?? Color::Default; + $children = array_map(fn($b) => BlockFactory::fromArray($b), $callout["children"] ?? []); - return new self($metadata, $text, $icon, $children); + return new self($metadata, $text, $icon, $color, $children); } public function toArray(): array @@ -88,6 +93,7 @@ public function toArray(): array $array["callout"] = [ "rich_text" => array_map(fn(RichText $t) => $t->toArray(), $this->text), "icon" => $this->icon->toArray(), + "color" => $this->color->value, "children" => array_map(fn(BlockInterface $b) => $b->toArray(), $this->children), ]; @@ -106,7 +112,7 @@ public function metadata(): BlockMetadata public function changeText(RichText ...$text): self { - return new self($this->metadata, $text, $this->icon, $this->children); + return new self($this->metadata, $text, $this->icon, $this->color, $this->children); } public function addText(RichText $text): self @@ -114,7 +120,7 @@ public function addText(RichText $text): self $texts = $this->text; $texts[] = $text; - return new self($this->metadata, $texts, $this->icon, $this->children); + return new self($this->metadata, $texts, $this->icon, $this->color, $this->children); } public function changeIcon(Emoji|File|Icon $icon): self @@ -127,7 +133,7 @@ public function changeIcon(Emoji|File|Icon $icon): self $icon = Icon::fromFile($icon); } - return new self($this->metadata, $this->text, $icon, $this->children); + return new self($this->metadata, $this->text, $icon, $this->color, $this->children); } public function changeChildren(BlockInterface ...$children): self @@ -138,6 +144,7 @@ public function changeChildren(BlockInterface ...$children): self $this->metadata->updateHasChildren($hasChildren), $this->text, $this->icon, + $this->color, $children, ); } @@ -151,16 +158,29 @@ public function addChild(BlockInterface $child): self $this->metadata->updateHasChildren(true), $this->text, $this->icon, + $this->color, $children, ); } + public function changeColor(Color $color): self + { + return new self( + $this->metadata->update(), + $this->text, + $this->icon, + $color, + $this->children, + ); + } + public function archive(): BlockInterface { return new self( $this->metadata->archive(), $this->text, $this->icon, + $this->color, $this->children, ); } diff --git a/src/Blocks/Heading1.php b/src/Blocks/Heading1.php index 85d1cfd1..7f6cfcae 100644 --- a/src/Blocks/Heading1.php +++ b/src/Blocks/Heading1.php @@ -2,6 +2,7 @@ namespace Notion\Blocks; +use Notion\Common\Color; use Notion\Exceptions\BlockException; use Notion\Common\RichText; use Notion\Exceptions\HeadingException; @@ -14,6 +15,7 @@ * heading_1: array{ * rich_text: RichTextJson[], * is_toggleable: bool, + * color?: string, * children?: BlockMetadataJson[] * }, * } @@ -30,6 +32,7 @@ private function __construct( private readonly BlockMetadata $metadata, public readonly array $text, public readonly bool $isToggleable, + public readonly Color $color, public readonly array|null $children, ) { $metadata->checkType(BlockType::Heading1); @@ -39,7 +42,7 @@ public static function fromText(RichText ...$text): self { $block = BlockMetadata::create(BlockType::Heading1); - return new self($block, $text, false, []); + return new self($block, $text, false, Color::Default, []); } public static function fromString(string $content): self @@ -47,7 +50,7 @@ public static function fromString(string $content): self $block = BlockMetadata::create(BlockType::Heading1); $text = [ RichText::fromString($content) ]; - return new self($block, $text, false, []); + return new self($block, $text, false, Color::Default, []); } public static function fromArray(array $array): self @@ -62,12 +65,14 @@ public static function fromArray(array $array): self $isToggleable = $heading["is_toggleable"]; + $color = Color::tryFrom($heading["color"] ?? "") ?? Color::Default; + $children = null; if ($isToggleable) { $children = array_map(fn($b) => BlockFactory::fromArray($b), $heading["children"] ?? []); } - return new self($block, $text, $isToggleable, $children); + return new self($block, $text, $isToggleable, $color, $children); } public function toArray(): array @@ -77,6 +82,7 @@ public function toArray(): array $array["heading_1"] = [ "rich_text" => array_map(fn(RichText $t) => $t->toArray(), $this->text), "is_toggleable" => $this->isToggleable, + "color" => $this->color->value, "children" => array_map(fn($b) => $b->toArray(), $this->children ?? []) ]; @@ -100,7 +106,7 @@ public function metadata(): BlockMetadata public function changeText(RichText ...$text): self { - return new self($this->metadata, $text, $this->isToggleable, $this->children); + return new self($this->metadata, $text, $this->isToggleable, $this->color, $this->children); } public function addText(RichText $text): self @@ -108,12 +114,12 @@ public function addText(RichText $text): self $texts = $this->text; $texts[] = $text; - return new self($this->metadata, $texts, $this->isToggleable, $this->children); + return new self($this->metadata, $texts, $this->isToggleable, $this->color, $this->children); } public function toggllify(): self { - return new self($this->metadata, $this->text, true, []); + return new self($this->metadata, $this->text, true, $this->color, []); } public function untogglify(): self @@ -122,7 +128,18 @@ public function untogglify(): self throw HeadingException::untogglifyWithChildren(); } - return new self($this->metadata, $this->text, false, null); + return new self($this->metadata, $this->text, false, $this->color, null); + } + + public function changeColor(Color $color): self + { + return new self( + $this->metadata->update(), + $this->text, + $this->isToggleable, + $color, + $this->children, + ); } public function addChild(BlockInterface $child): self @@ -136,6 +153,7 @@ public function addChild(BlockInterface $child): self $this->metadata, $this->text, $this->isToggleable, + $this->color, $children, ); } @@ -146,7 +164,7 @@ public function changeChildren(BlockInterface ...$children): self throw BlockException::noChindrenSupport(); } - return new self($this->metadata, $this->text, $this->isToggleable, $children); + return new self($this->metadata, $this->text, $this->isToggleable, $this->color, $children); } public function archive(): BlockInterface @@ -155,6 +173,7 @@ public function archive(): BlockInterface $this->metadata->archive(), $this->text, $this->isToggleable, + $this->color, $this->children, ); } diff --git a/src/Blocks/Heading2.php b/src/Blocks/Heading2.php index 89456125..c93b8d1b 100644 --- a/src/Blocks/Heading2.php +++ b/src/Blocks/Heading2.php @@ -2,6 +2,7 @@ namespace Notion\Blocks; +use Notion\Common\Color; use Notion\Exceptions\BlockException; use Notion\Common\RichText; use Notion\Exceptions\HeadingException; @@ -14,6 +15,7 @@ * heading_2: array{ * rich_text: RichTextJson[], * is_toggleable: bool, + * color?: string, * children?: BlockMetadataJson[] * }, * } @@ -30,6 +32,7 @@ private function __construct( private readonly BlockMetadata $metadata, public readonly array $text, public readonly bool $isToggleable, + public readonly Color $color, public readonly array|null $children, ) { $metadata->checkType(BlockType::Heading2); @@ -39,7 +42,7 @@ public static function fromText(RichText ...$text): self { $block = BlockMetadata::create(BlockType::Heading2); - return new self($block, $text, false, []); + return new self($block, $text, false, Color::Default, []); } public static function fromString(string $content): self @@ -47,7 +50,7 @@ public static function fromString(string $content): self $block = BlockMetadata::create(BlockType::Heading2); $text = [ RichText::fromString($content) ]; - return new self($block, $text, false, []); + return new self($block, $text, false, Color::Default, []); } public static function fromArray(array $array): self @@ -62,12 +65,14 @@ public static function fromArray(array $array): self $isToggleable = $heading["is_toggleable"]; + $color = Color::tryFrom($heading["color"] ?? "") ?? Color::Default; + $children = null; if ($isToggleable) { $children = array_map(fn($b) => BlockFactory::fromArray($b), $heading["children"] ?? []); } - return new self($block, $text, $isToggleable, $children); + return new self($block, $text, $isToggleable, $color, $children); } public function toArray(): array @@ -77,6 +82,7 @@ public function toArray(): array $array["heading_2"] = [ "rich_text" => array_map(fn(RichText $t) => $t->toArray(), $this->text), "is_toggleable" => $this->isToggleable, + "color" => $this->color->value, "children" => array_map(fn($b) => $b->toArray(), $this->children ?? []) ]; @@ -100,7 +106,7 @@ public function metadata(): BlockMetadata public function changeText(RichText ...$text): self { - return new self($this->metadata, $text, $this->isToggleable, $this->children); + return new self($this->metadata, $text, $this->isToggleable, $this->color, $this->children); } public function addText(RichText $text): self @@ -108,12 +114,12 @@ public function addText(RichText $text): self $texts = $this->text; $texts[] = $text; - return new self($this->metadata, $texts, $this->isToggleable, $this->children); + return new self($this->metadata, $texts, $this->isToggleable, $this->color, $this->children); } public function toggllify(): self { - return new self($this->metadata, $this->text, true, []); + return new self($this->metadata, $this->text, true, $this->color, []); } public function untogglify(): self @@ -122,7 +128,18 @@ public function untogglify(): self throw HeadingException::untogglifyWithChildren(); } - return new self($this->metadata, $this->text, false, null); + return new self($this->metadata, $this->text, false, $this->color, null); + } + + public function changeColor(Color $color): self + { + return new self( + $this->metadata->update(), + $this->text, + $this->isToggleable, + $color, + $this->children, + ); } public function addChild(BlockInterface $child): self @@ -136,6 +153,7 @@ public function addChild(BlockInterface $child): self $this->metadata, $this->text, $this->isToggleable, + $this->color, $children, ); } @@ -146,7 +164,7 @@ public function changeChildren(BlockInterface ...$children): self throw BlockException::noChindrenSupport(); } - return new self($this->metadata, $this->text, $this->isToggleable, $children); + return new self($this->metadata, $this->text, $this->isToggleable, $this->color, $children); } public function archive(): BlockInterface @@ -155,6 +173,7 @@ public function archive(): BlockInterface $this->metadata->archive(), $this->text, $this->isToggleable, + $this->color, $this->children, ); } diff --git a/src/Blocks/Heading3.php b/src/Blocks/Heading3.php index 329c8f80..96ada800 100644 --- a/src/Blocks/Heading3.php +++ b/src/Blocks/Heading3.php @@ -2,6 +2,7 @@ namespace Notion\Blocks; +use Notion\Common\Color; use Notion\Exceptions\BlockException; use Notion\Common\RichText; use Notion\Exceptions\HeadingException; @@ -14,6 +15,7 @@ * heading_3: array{ * rich_text: RichTextJson[], * is_toggleable: bool, + * color?: string, * children?: BlockMetadataJson[] * }, * } @@ -30,6 +32,7 @@ private function __construct( private readonly BlockMetadata $metadata, public readonly array $text, public readonly bool $isToggleable, + public readonly Color $color, public readonly array|null $children, ) { $metadata->checkType(BlockType::Heading3); @@ -39,7 +42,7 @@ public static function fromText(RichText ...$text): self { $block = BlockMetadata::create(BlockType::Heading3); - return new self($block, $text, false, []); + return new self($block, $text, false, Color::Default, []); } public static function fromString(string $content): self @@ -47,7 +50,7 @@ public static function fromString(string $content): self $block = BlockMetadata::create(BlockType::Heading3); $text = [ RichText::fromString($content) ]; - return new self($block, $text, false, []); + return new self($block, $text, false, Color::Default, []); } public static function fromArray(array $array): self @@ -62,12 +65,14 @@ public static function fromArray(array $array): self $isToggleable = $heading["is_toggleable"]; + $color = Color::tryFrom($heading["color"] ?? "") ?? Color::Default; + $children = null; if ($isToggleable) { $children = array_map(fn($b) => BlockFactory::fromArray($b), $heading["children"] ?? []); } - return new self($block, $text, $isToggleable, $children); + return new self($block, $text, $isToggleable, $color, $children); } public function toArray(): array @@ -77,6 +82,7 @@ public function toArray(): array $array["heading_3"] = [ "rich_text" => array_map(fn(RichText $t) => $t->toArray(), $this->text), "is_toggleable" => $this->isToggleable, + "color" => $this->color->value, "children" => array_map(fn($b) => $b->toArray(), $this->children ?? []) ]; @@ -100,7 +106,7 @@ public function metadata(): BlockMetadata public function changeText(RichText ...$text): self { - return new self($this->metadata, $text, $this->isToggleable, $this->children); + return new self($this->metadata, $text, $this->isToggleable, $this->color, $this->children); } public function addText(RichText $text): self @@ -108,12 +114,12 @@ public function addText(RichText $text): self $texts = $this->text; $texts[] = $text; - return new self($this->metadata, $texts, $this->isToggleable, $this->children); + return new self($this->metadata, $texts, $this->isToggleable, $this->color, $this->children); } public function toggllify(): self { - return new self($this->metadata, $this->text, true, []); + return new self($this->metadata, $this->text, true, $this->color, []); } public function untogglify(): self @@ -122,7 +128,18 @@ public function untogglify(): self throw HeadingException::untogglifyWithChildren(); } - return new self($this->metadata, $this->text, false, null); + return new self($this->metadata, $this->text, false, $this->color, null); + } + + public function changeColor(Color $color): self + { + return new self( + $this->metadata->update(), + $this->text, + $this->isToggleable, + $color, + $this->children, + ); } public function addChild(BlockInterface $child): self @@ -136,6 +153,7 @@ public function addChild(BlockInterface $child): self $this->metadata, $this->text, $this->isToggleable, + $this->color, $children, ); } @@ -146,7 +164,7 @@ public function changeChildren(BlockInterface ...$children): self throw BlockException::noChindrenSupport(); } - return new self($this->metadata, $this->text, $this->isToggleable, $children); + return new self($this->metadata, $this->text, $this->isToggleable, $this->color, $children); } public function archive(): BlockInterface @@ -155,6 +173,7 @@ public function archive(): BlockInterface $this->metadata->archive(), $this->text, $this->isToggleable, + $this->color, $this->children, ); } diff --git a/src/Blocks/NumberedListItem.php b/src/Blocks/NumberedListItem.php index abd281a0..17106548 100644 --- a/src/Blocks/NumberedListItem.php +++ b/src/Blocks/NumberedListItem.php @@ -2,7 +2,7 @@ namespace Notion\Blocks; -use Notion\Exceptions\BlockException; +use Notion\Common\Color; use Notion\Common\RichText; /** @@ -12,6 +12,7 @@ * @psalm-type NumberedListItemJson = array{ * numbered_list_item: array{ * rich_text: list, + * color?: string, * children?: list, * }, * } @@ -27,6 +28,7 @@ class NumberedListItem implements BlockInterface private function __construct( private readonly BlockMetadata $metadata, public readonly array $text, + public readonly Color $color, public readonly array $children, ) { $metadata->checkType(BlockType::NumberedListItem); @@ -36,7 +38,7 @@ public static function create(): self { $block = BlockMetadata::create(BlockType::NumberedListItem); - return new self($block, [], []); + return new self($block, [], Color::Default, []); } public static function fromString(string $content): self @@ -44,7 +46,7 @@ public static function fromString(string $content): self $block = BlockMetadata::create(BlockType::NumberedListItem); $text = [ RichText::fromString($content) ]; - return new self($block, $text, []); + return new self($block, $text, Color::Default, []); } public static function fromArray(array $array): self @@ -57,9 +59,11 @@ public static function fromArray(array $array): self $text = array_map(fn($t) => RichText::fromArray($t), $item["rich_text"]); + $color = Color::tryFrom($item["color"] ?? "") ?? Color::Default; + $children = array_map(fn($b) => BlockFactory::fromArray($b), $item["children"] ?? []); - return new self($block, $text, $children); + return new self($block, $text, $color, $children); } public function toArray(): array @@ -68,6 +72,7 @@ public function toArray(): array $array["numbered_list_item"] = [ "rich_text" => array_map(fn(RichText $t) => $t->toArray(), $this->text), + "color" => $this->color->value, "children" => array_map(fn(BlockInterface $b) => $b->toArray(), $this->children), ]; @@ -86,7 +91,7 @@ public function metadata(): BlockMetadata public function changeText(RichText ...$text): self { - return new self($this->metadata->update(), $text, $this->children); + return new self($this->metadata->update(), $text, $this->color, $this->children); } public function addText(RichText $text): self @@ -94,7 +99,7 @@ public function addText(RichText $text): self $texts = $this->text; $texts[] = $text; - return new self($this->metadata->update(), $texts, $this->children); + return new self($this->metadata->update(), $texts, $this->color, $this->children); } public function addChild(BlockInterface $child): self @@ -105,6 +110,7 @@ public function addChild(BlockInterface $child): self return new self( $this->metadata->updateHasChildren(true), $this->text, + $this->color, $children, ); } @@ -116,15 +122,27 @@ public function changeChildren(BlockInterface ...$children): self return new self( $this->metadata->updateHasChildren($hasChildren), $this->text, + $this->color, $children, ); } + public function changeColor(Color $color): self + { + return new self( + $this->metadata->update(), + $this->text, + $color, + $this->children, + ); + } + public function archive(): BlockInterface { return new self( $this->metadata->archive(), $this->text, + $this->color, $this->children, ); } diff --git a/src/Blocks/Paragraph.php b/src/Blocks/Paragraph.php index 23260daa..901ed4f2 100644 --- a/src/Blocks/Paragraph.php +++ b/src/Blocks/Paragraph.php @@ -2,6 +2,7 @@ namespace Notion\Blocks; +use Notion\Common\Color; use Notion\Common\RichText; /** @@ -12,6 +13,7 @@ * paragraph: array{ * rich_text: list, * children?: list, + * color?: string, * }, * } * @@ -27,6 +29,7 @@ private function __construct( private readonly BlockMetadata $metadata, public readonly array $text, public readonly array $children, + public readonly Color $color, ) { $metadata->checkType(BlockType::Paragraph); } @@ -35,7 +38,7 @@ public static function create(): self { $block = BlockMetadata::create(BlockType::Paragraph); - return new self($block, [], []); + return new self($block, [], [], Color::Default); } public static function fromString(string $content): self @@ -43,7 +46,7 @@ public static function fromString(string $content): self $block = BlockMetadata::create(BlockType::Paragraph); $text = [ RichText::fromString($content) ]; - return new self($block, $text, []); + return new self($block, $text, [], Color::Default); } public static function fromArray(array $array): self @@ -58,7 +61,9 @@ public static function fromArray(array $array): self $children = array_map(fn($b) => BlockFactory::fromArray($b), $paragraph["children"] ?? []); - return new self($block, $text, $children); + $color = Color::tryFrom($paragraph["color"] ?? "") ?? Color::Default; + + return new self($block, $text, $children, $color); } public function toArray(): array @@ -68,6 +73,7 @@ public function toArray(): array $array["paragraph"] = [ "rich_text" => array_map(fn(RichText $t) => $t->toArray(), $this->text), "children" => array_map(fn(BlockInterface $b) => $b->toArray(), $this->children), + "color" => $this->color->value, ]; return $array; @@ -91,7 +97,7 @@ public function metadata(): BlockMetadata /** @param RichText[] $text */ public function changeText(array $text): self { - return new self($this->metadata, $text, $this->children); + return new self($this->metadata, $text, $this->children, $this->color); } public function addText(RichText $text): self @@ -99,7 +105,7 @@ public function addText(RichText $text): self $texts = $this->text; $texts[] = $text; - return new self($this->metadata, $texts, $this->children); + return new self($this->metadata, $texts, $this->children, $this->color); } public function changeChildren(BlockInterface ...$children): self @@ -110,6 +116,7 @@ public function changeChildren(BlockInterface ...$children): self $this->metadata->updateHasChildren($hasChildren), $this->text, $children, + $this->color, ); } @@ -122,6 +129,17 @@ public function addChild(BlockInterface $child): self $this->metadata->updateHasChildren(true), $this->text, $children, + $this->color, + ); + } + + public function changeColor(Color $color): self + { + return new self( + $this->metadata->update(), + $this->text, + $this->children, + $color, ); } @@ -131,6 +149,7 @@ public function archive(): BlockInterface $this->metadata->archive(), $this->text, $this->children, + $this->color, ); } } diff --git a/src/Blocks/Quote.php b/src/Blocks/Quote.php index 2e5f611c..22845e90 100644 --- a/src/Blocks/Quote.php +++ b/src/Blocks/Quote.php @@ -2,6 +2,7 @@ namespace Notion\Blocks; +use Notion\Common\Color; use Notion\Exceptions\BlockException; use Notion\Common\RichText; @@ -12,6 +13,7 @@ * @psalm-type QuoteJson = array{ * quote: array{ * rich_text: list, + * color?: string, * children: list, * }, * } @@ -27,6 +29,7 @@ class Quote implements BlockInterface private function __construct( private readonly BlockMetadata $metadata, public readonly array $text, + public readonly Color $color, public readonly array $children, ) { $metadata->checkType(BlockType::Quote); @@ -36,7 +39,7 @@ public static function create(): self { $block = BlockMetadata::create(BlockType::Quote); - return new self($block, [], []); + return new self($block, [], Color::Default, []); } public static function fromString(string $content): self @@ -44,7 +47,7 @@ public static function fromString(string $content): self $block = BlockMetadata::create(BlockType::Quote); $text = [ RichText::fromString($content) ]; - return new self($block, $text, []); + return new self($block, $text, Color::Default, []); } public static function fromArray(array $array): self @@ -57,9 +60,11 @@ public static function fromArray(array $array): self $text = array_map(fn($t) => RichText::fromArray($t), $quote["rich_text"]); + $color = Color::tryFrom($quote["color"] ?? "") ?? Color::Default; + $children = array_map(fn($b) => BlockFactory::fromArray($b), $quote["children"] ?? []); - return new self($block, $text, $children); + return new self($block, $text, $color, $children); } public function toArray(): array @@ -68,6 +73,7 @@ public function toArray(): array $array["quote"] = [ "rich_text" => array_map(fn(RichText $t) => $t->toArray(), $this->text), + "color" => $this->color->value, "children" => array_map(fn(BlockInterface $b) => $b->toArray(), $this->children), ]; @@ -92,7 +98,7 @@ public function metadata(): BlockMetadata /** @param RichText[] $text */ public function changeText(array $text): self { - return new self($this->metadata, $text, $this->children); + return new self($this->metadata, $text, $this->color, $this->children); } public function addText(RichText $text): self @@ -100,7 +106,7 @@ public function addText(RichText $text): self $texts = $this->text; $texts[] = $text; - return new self($this->metadata, $texts, $this->children); + return new self($this->metadata, $texts, $this->color, $this->children); } public function changeChildren(BlockInterface ...$children): self @@ -110,6 +116,7 @@ public function changeChildren(BlockInterface ...$children): self return new self( $this->metadata->updateHasChildren($hasChildren), $this->text, + $this->color, $children, ); } @@ -122,15 +129,27 @@ public function addChild(BlockInterface $child): self return new self( $this->metadata->updateHasChildren(true), $this->text, + $this->color, $children, ); } + public function changeColor(Color $color): self + { + return new self( + $this->metadata->update(), + $this->text, + $color, + $this->children, + ); + } + public function archive(): BlockInterface { return new self( $this->metadata->archive(), $this->text, + $this->color, $this->children, ); } diff --git a/src/Blocks/TableOfContents.php b/src/Blocks/TableOfContents.php index 4cf400b6..4dcbb5e2 100644 --- a/src/Blocks/TableOfContents.php +++ b/src/Blocks/TableOfContents.php @@ -2,13 +2,16 @@ namespace Notion\Blocks; +use Notion\Common\Color; use Notion\Exceptions\BlockException; /** * @psalm-import-type BlockMetadataJson from BlockMetadata * * @psalm-type TableOfContentsJson = array{ - * table_of_contents: array + * table_of_contents: array{ + * color?: string + * } * } * * @psalm-immutable @@ -17,6 +20,7 @@ class TableOfContents implements BlockInterface { private function __construct( private readonly BlockMetadata $metadata, + public readonly Color $color, ) { $metadata->checkType(BlockType::TableOfContents); } @@ -25,7 +29,7 @@ public static function create(): self { $block = BlockMetadata::create(BlockType::TableOfContents); - return new self($block); + return new self($block, Color::Default); } public static function fromArray(array $array): self @@ -33,7 +37,12 @@ public static function fromArray(array $array): self /** @psalm-var BlockMetadataJson $array */ $block = BlockMetadata::fromArray($array); - return new self($block); + /** @psalm-var TableOfContentsJson $array */ + $toc = $array["table_of_contents"]; + + $color = Color::tryFrom($toc["color"] ?? "") ?? Color::Default; + + return new self($block, $color); } public function toArray(): array @@ -60,10 +69,19 @@ public function changeChildren(BlockInterface ...$children): never throw BlockException::noChindrenSupport(); } + public function changeColor(Color $color): self + { + return new self( + $this->metadata->update(), + $color, + ); + } + public function archive(): BlockInterface { return new self( $this->metadata->archive(), + $this->color, ); } } diff --git a/src/Blocks/ToDo.php b/src/Blocks/ToDo.php index eefab22b..4a3dada8 100644 --- a/src/Blocks/ToDo.php +++ b/src/Blocks/ToDo.php @@ -2,6 +2,7 @@ namespace Notion\Blocks; +use Notion\Common\Color; use Notion\Exceptions\BlockException; use Notion\Common\RichText; @@ -13,6 +14,7 @@ * to_do: array{ * checked: bool, * rich_text: list, + * color?: string, * children?: list, * }, * } @@ -29,6 +31,7 @@ private function __construct( private readonly BlockMetadata $metadata, public readonly array $text, public readonly bool $checked, + public readonly Color $color, public readonly array $children, ) { $metadata->checkType(BlockType::ToDo); @@ -38,7 +41,7 @@ public static function create(): self { $block = BlockMetadata::create(BlockType::ToDo); - return new self($block, [], false, []); + return new self($block, [], false, Color::Default, []); } public static function fromString(string $content): self @@ -46,7 +49,7 @@ public static function fromString(string $content): self $block = BlockMetadata::create(BlockType::ToDo); $text = [ RichText::fromString($content) ]; - return new self($block, $text, false, []); + return new self($block, $text, false, Color::Default, []); } public static function fromArray(array $array): self @@ -61,9 +64,11 @@ public static function fromArray(array $array): self $checked = $todo["checked"]; + $color = Color::tryFrom($todo["color"] ?? "") ?? Color::Default; + $children = array_map(fn($b) => BlockFactory::fromArray($b), $todo["children"] ?? []); - return new self($block, $text, $checked, $children); + return new self($block, $text, $checked, $color, $children); } public function toArray(): array @@ -73,6 +78,7 @@ public function toArray(): array $array["to_do"] = [ "rich_text" => array_map(fn(RichText $t) => $t->toArray(), $this->text), "checked" => $this->checked, + "color" => $this->color->value, "children" => array_map(fn(BlockInterface $b) => $b->toArray(), $this->children), ]; @@ -96,7 +102,7 @@ public function metadata(): BlockMetadata public function changeText(RichText ...$text): self { - return new self($this->metadata, $text, $this->checked, $this->children); + return new self($this->metadata, $text, $this->checked, $this->color, $this->children); } public function addText(RichText $text): self @@ -104,17 +110,17 @@ public function addText(RichText $text): self $texts = $this->text; $texts[] = $text; - return new self($this->metadata, $texts, $this->checked, $this->children); + return new self($this->metadata, $texts, $this->checked, $this->color, $this->children); } public function check(): self { - return new self($this->metadata, $this->text, true, $this->children); + return new self($this->metadata, $this->text, true, $this->color, $this->children); } public function uncheck(): self { - return new self($this->metadata, $this->text, false, $this->children); + return new self($this->metadata, $this->text, false, $this->color, $this->children); } public function changeChildren(BlockInterface ...$children): self @@ -125,6 +131,7 @@ public function changeChildren(BlockInterface ...$children): self $this->metadata->updateHasChildren($hasChildren), $this->text, $this->checked, + $this->color, $children, ); } @@ -138,16 +145,29 @@ public function addChild(BlockInterface $child): self $this->metadata->updateHasChildren(true), $this->text, $this->checked, + $this->color, $children, ); } + public function changeColor(Color $color): self + { + return new self( + $this->metadata->update(), + $this->text, + $this->checked, + $color, + $this->children, + ); + } + public function archive(): BlockInterface { return new self( $this->metadata->archive(), $this->text, $this->checked, + $this->color, $this->children, ); } diff --git a/src/Blocks/Toggle.php b/src/Blocks/Toggle.php index 2bd3cccd..9a205ae0 100644 --- a/src/Blocks/Toggle.php +++ b/src/Blocks/Toggle.php @@ -2,6 +2,7 @@ namespace Notion\Blocks; +use Notion\Common\Color; use Notion\Common\RichText; /** @@ -11,6 +12,7 @@ * @psalm-type ToggleJson = array{ * toggle: array{ * rich_text: list, + * color?: string, * children?: list, * }, * } @@ -26,6 +28,7 @@ class Toggle implements BlockInterface private function __construct( private readonly BlockMetadata $metadata, public readonly array $text, + public readonly Color $color, public readonly array $children, ) { $metadata->checkType(BlockType::Toggle); @@ -35,7 +38,7 @@ public static function createEmpty(): self { $block = BlockMetadata::create(BlockType::Toggle); - return new self($block, [], []); + return new self($block, [], Color::Default, []); } public static function fromString(string $content): self @@ -43,7 +46,7 @@ public static function fromString(string $content): self $block = BlockMetadata::create(BlockType::Toggle); $text = [ RichText::fromString($content) ]; - return new self($block, $text, []); + return new self($block, $text, Color::Default, []); } public static function fromArray(array $array): self @@ -56,9 +59,11 @@ public static function fromArray(array $array): self $text = array_map(fn($t) => RichText::fromArray($t), $toggle["rich_text"]); + $color = Color::tryFrom($toggle["color"] ?? "") ?? Color::Default; + $children = array_map(fn($b) => BlockFactory::fromArray($b), $toggle["children"] ?? []); - return new self($block, $text, $children); + return new self($block, $text, $color, $children); } public function toArray(): array @@ -66,8 +71,9 @@ public function toArray(): array $array = $this->metadata->toArray(); $array["toggle"] = [ - "rich_text" => array_map(fn(RichText $t) => $t->toArray(), $this->text), - "children" => array_map(fn(BlockInterface $b) => $b->toArray(), $this->children), + "rich_text" => array_map(fn(RichText $t) => $t->toArray(), $this->text), + "color" => $this->color->value, + "children" => array_map(fn(BlockInterface $b) => $b->toArray(), $this->children), ]; return $array; @@ -90,7 +96,7 @@ public function metadata(): BlockMetadata public function changeText(RichText ...$text): self { - return new self($this->metadata, $text, $this->children); + return new self($this->metadata, $text, $this->color, $this->children); } public function addText(RichText $text): self @@ -98,7 +104,7 @@ public function addText(RichText $text): self $texts = $this->text; $texts[] = $text; - return new self($this->metadata, $texts, $this->children); + return new self($this->metadata, $texts, $this->color, $this->children); } public function changeChildren(BlockInterface ...$children): self @@ -108,6 +114,7 @@ public function changeChildren(BlockInterface ...$children): self return new self( $this->metadata->updateHasChildren($hasChildren), $this->text, + $this->color, $children, ); } @@ -120,15 +127,27 @@ public function addChild(BlockInterface $child): self return new self( $this->metadata->updateHasChildren(true), $this->text, + $this->color, $children, ); } + public function changeColor(Color $color): self + { + return new self( + $this->metadata->update(), + $this->text, + $color, + $this->children, + ); + } + public function archive(): BlockInterface { return new self( $this->metadata->archive(), $this->text, + $this->color, $this->children, ); } diff --git a/tests/Unit/Blocks/BulletedListItemTest.php b/tests/Unit/Blocks/BulletedListItemTest.php index e114bed5..4391d95f 100644 --- a/tests/Unit/Blocks/BulletedListItemTest.php +++ b/tests/Unit/Blocks/BulletedListItemTest.php @@ -4,6 +4,7 @@ use Notion\Blocks\BlockFactory; use Notion\Blocks\BulletedListItem; +use Notion\Common\Color; use Notion\Exceptions\BlockException; use Notion\Common\Date; use Notion\Common\RichText; @@ -133,6 +134,7 @@ public function test_transform_in_array(): void "color" => "default", ], ]], + "color" => "default", "children" => [], ], ]; @@ -185,4 +187,11 @@ public function test_add_child(): void $this->assertCount(1, $item->children); $this->assertEquals($nested, $item->children[0]); } + + public function test_change_color(): void + { + $block = BulletedListItem::fromString("Hello World!")->changeColor(Color::Red); + + $this->assertSame(Color::Red, $block->color); + } } diff --git a/tests/Unit/Blocks/CalloutTest.php b/tests/Unit/Blocks/CalloutTest.php index 71ff6dcb..0450aa11 100644 --- a/tests/Unit/Blocks/CalloutTest.php +++ b/tests/Unit/Blocks/CalloutTest.php @@ -4,6 +4,7 @@ use Notion\Blocks\BlockFactory; use Notion\Blocks\Callout; +use Notion\Common\Color; use Notion\Exceptions\BlockException; use Notion\Common\Date; use Notion\Common\Emoji; @@ -235,6 +236,7 @@ public function test_transform_in_array(): void "type" => "emoji", "emoji" => "☀️", ], + "color" => "default", "children" => [], ], ]; @@ -307,4 +309,11 @@ public function test_replace_icon_file(): void $this->assertTrue($callout->icon->isFile()); } + + public function test_change_color(): void + { + $block = Callout::fromString("☀️", "Hello World!")->changeColor(Color::Red); + + $this->assertSame(Color::Red, $block->color); + } } diff --git a/tests/Unit/Blocks/Heading1Test.php b/tests/Unit/Blocks/Heading1Test.php index 905ae20d..94dccbc5 100644 --- a/tests/Unit/Blocks/Heading1Test.php +++ b/tests/Unit/Blocks/Heading1Test.php @@ -6,6 +6,7 @@ use Notion\Exceptions\BlockException; use Notion\Blocks\Heading1; use Notion\Blocks\Paragraph; +use Notion\Common\Color; use Notion\Common\Date; use Notion\Common\RichText; use Notion\Exceptions\HeadingException; @@ -74,6 +75,7 @@ public function test_create_from_array(): void ], "is_toggleable" => false, "children" => [], + "color" => "default", ], ]; @@ -137,6 +139,7 @@ public function test_transform_in_array(): void ]], "is_toggleable" => false, "children" => [], + "color" => "default", ], ]; @@ -279,6 +282,7 @@ public function test_toggleable_array_conversion(): void "divider" => new \stdClass(), ] ], + "color" => "default", ], ]; @@ -286,4 +290,11 @@ public function test_toggleable_array_conversion(): void $this->assertEquals($array, $heading->toArray()); } + + public function test_change_color(): void + { + $h1 = Heading1::fromString("Hello!")->changeColor(Color::Green); + + $this->assertSame(Color::Green, $h1->color); + } } diff --git a/tests/Unit/Blocks/Heading2Test.php b/tests/Unit/Blocks/Heading2Test.php index 7780c4e4..7b0a25db 100644 --- a/tests/Unit/Blocks/Heading2Test.php +++ b/tests/Unit/Blocks/Heading2Test.php @@ -6,6 +6,7 @@ use Notion\Exceptions\BlockException; use Notion\Blocks\Heading2; use Notion\Blocks\Paragraph; +use Notion\Common\Color; use Notion\Common\Date; use Notion\Common\RichText; use Notion\Exceptions\HeadingException; @@ -74,6 +75,7 @@ public function test_create_from_array(): void ], "is_toggleable" => false, "children" => [], + "color" => "default", ], ]; @@ -100,7 +102,7 @@ public function test_error_on_wrong_type(): void "type" => "wrong-type", "heading_2" => [ "rich_text" => [], - "is_toggleable" => true, + "is_toggleable" => false, ], ]; @@ -137,6 +139,7 @@ public function test_transform_in_array(): void ]], "is_toggleable" => false, "children" => [], + "color" => "default", ], ]; @@ -279,6 +282,7 @@ public function test_toggleable_array_conversion(): void "divider" => new \stdClass(), ] ], + "color" => "default", ], ]; @@ -286,4 +290,11 @@ public function test_toggleable_array_conversion(): void $this->assertEquals($array, $heading->toArray()); } + + public function test_change_color(): void + { + $h1 = Heading2::fromString("Hello!")->changeColor(Color::Green); + + $this->assertSame(Color::Green, $h1->color); + } } diff --git a/tests/Unit/Blocks/Heading3Test.php b/tests/Unit/Blocks/Heading3Test.php index 0a132ae8..51d38bc8 100644 --- a/tests/Unit/Blocks/Heading3Test.php +++ b/tests/Unit/Blocks/Heading3Test.php @@ -6,6 +6,7 @@ use Notion\Exceptions\BlockException; use Notion\Blocks\Heading3; use Notion\Blocks\Paragraph; +use Notion\Common\Color; use Notion\Common\Date; use Notion\Common\RichText; use Notion\Exceptions\HeadingException; @@ -74,6 +75,7 @@ public function test_create_from_array(): void ], "is_toggleable" => false, "children" => [], + "color" => "default", ], ]; @@ -100,7 +102,7 @@ public function test_error_on_wrong_type(): void "type" => "wrong-type", "heading_3" => [ "rich_text" => [], - "is_toggleable" => false, + "is_toggleable" => false, ], ]; @@ -137,6 +139,7 @@ public function test_transform_in_array(): void ]], "is_toggleable" => false, "children" => [], + "color" => "default", ], ]; @@ -279,6 +282,7 @@ public function test_toggleable_array_conversion(): void "divider" => new \stdClass(), ] ], + "color" => "default", ], ]; @@ -286,4 +290,11 @@ public function test_toggleable_array_conversion(): void $this->assertEquals($array, $heading->toArray()); } + + public function test_change_color(): void + { + $h1 = Heading3::fromString("Hello!")->changeColor(Color::Green); + + $this->assertSame(Color::Green, $h1->color); + } } diff --git a/tests/Unit/Blocks/NumberedListItemTest.php b/tests/Unit/Blocks/NumberedListItemTest.php index 1bf6bc79..37668188 100644 --- a/tests/Unit/Blocks/NumberedListItemTest.php +++ b/tests/Unit/Blocks/NumberedListItemTest.php @@ -5,6 +5,7 @@ use Notion\Blocks\BlockFactory; use Notion\Exceptions\BlockException; use Notion\Blocks\NumberedListItem; +use Notion\Common\Color; use Notion\Common\Date; use Notion\Common\RichText; use PHPUnit\Framework\TestCase; @@ -133,6 +134,7 @@ public function test_transform_in_array(): void "color" => "default", ], ]], + "color" => "default", "children" => [], ], ]; @@ -185,4 +187,11 @@ public function test_add_child(): void $this->assertCount(1, $item->children); $this->assertEquals($nested, $item->children[0]); } + + public function test_change_color(): void + { + $block = NumberedListItem::fromString("Hello World!")->changeColor(Color::Red); + + $this->assertSame(Color::Red, $block->color); + } } diff --git a/tests/Unit/Blocks/ParagraphTest.php b/tests/Unit/Blocks/ParagraphTest.php index 781a1b06..8e198b46 100644 --- a/tests/Unit/Blocks/ParagraphTest.php +++ b/tests/Unit/Blocks/ParagraphTest.php @@ -5,6 +5,7 @@ use Notion\Blocks\BlockFactory; use Notion\Exceptions\BlockException; use Notion\Blocks\Paragraph; +use Notion\Common\Color; use Notion\Common\Date; use Notion\Common\RichText; use PHPUnit\Framework\TestCase; @@ -72,6 +73,7 @@ public function test_create_from_array(): void ], ], "children" => [], + "color" => "green", ], ]; @@ -133,6 +135,7 @@ public function test_transform_in_array(): void ], ]], "children" => [], + "color" => "default", ], ]; @@ -184,4 +187,11 @@ public function test_add_child(): void $this->assertCount(1, $paragraph->children); $this->assertEquals($nested, $paragraph->children[0]); } + + public function test_change_color(): void + { + $paragraph = Paragraph::fromString("Hello World!")->changeColor(Color::Red); + + $this->assertSame(Color::Red, $paragraph->color); + } } diff --git a/tests/Unit/Blocks/QuoteTest.php b/tests/Unit/Blocks/QuoteTest.php index b09273c8..3da23cf3 100644 --- a/tests/Unit/Blocks/QuoteTest.php +++ b/tests/Unit/Blocks/QuoteTest.php @@ -5,6 +5,7 @@ use Notion\Blocks\BlockFactory; use Notion\Exceptions\BlockException; use Notion\Blocks\Quote; +use Notion\Common\Color; use Notion\Common\Date; use Notion\Common\RichText; use PHPUnit\Framework\TestCase; @@ -133,6 +134,7 @@ public function test_transform_in_array(): void "color" => "default", ], ]], + "color" => "default", "children" => [], ], ]; @@ -193,4 +195,11 @@ public function test_archive(): void $this->assertTrue($quote->metadata()->archived); } + + public function test_change_color(): void + { + $block = Quote::fromString("Hello World!")->changeColor(Color::Red); + + $this->assertSame(Color::Red, $block->color); + } } diff --git a/tests/Unit/Blocks/TableOfContentsTest.php b/tests/Unit/Blocks/TableOfContentsTest.php index 96a47637..1543e184 100644 --- a/tests/Unit/Blocks/TableOfContentsTest.php +++ b/tests/Unit/Blocks/TableOfContentsTest.php @@ -6,6 +6,7 @@ use Notion\Blocks\Paragraph; use Notion\Exceptions\BlockException; use Notion\Blocks\TableOfContents; +use Notion\Common\Color; use Notion\Common\Date; use PHPUnit\Framework\TestCase; @@ -28,7 +29,9 @@ public function test_create_from_array(): void "archived" => false, "has_children" => false, "type" => "table_of_contents", - "table_of_contents" => new \stdClass(), + "table_of_contents" => [ + "color" => "green", + ] ]; $tableOfContents = TableOfContents::fromArray($array); @@ -47,7 +50,7 @@ public function test_error_on_wrong_type(): void "archived" => false, "has_children" => false, "type" => "wrong-type", - "table_of_contents" => new \stdClass(), + "table_of_contents" => [] ]; TableOfContents::fromArray($array); @@ -87,4 +90,11 @@ public function test_no_children_support_2(): void /** @psalm-suppress UnusedMethodCall */ $block->addChild(Paragraph::create()); } + + public function test_change_color(): void + { + $block = TableOfContents::create()->changeColor(Color::Red); + + $this->assertSame(Color::Red, $block->color); + } } diff --git a/tests/Unit/Blocks/ToDoTest.php b/tests/Unit/Blocks/ToDoTest.php index ec404ca1..8dc6e536 100644 --- a/tests/Unit/Blocks/ToDoTest.php +++ b/tests/Unit/Blocks/ToDoTest.php @@ -5,6 +5,7 @@ use Notion\Blocks\BlockFactory; use Notion\Exceptions\BlockException; use Notion\Blocks\ToDo; +use Notion\Common\Color; use Notion\Common\Date; use Notion\Common\RichText; use PHPUnit\Framework\TestCase; @@ -138,6 +139,7 @@ public function test_transform_in_array(): void "color" => "default", ], ]], + "color" => "default", "children" => [], ], ]; @@ -205,4 +207,11 @@ public function test_uncheck_item(): void $this->assertFalse($toDo->checked); } + + public function test_change_color(): void + { + $block = ToDo::fromString("Hello World!")->changeColor(Color::Red); + + $this->assertSame(Color::Red, $block->color); + } } diff --git a/tests/Unit/Blocks/ToggleTest.php b/tests/Unit/Blocks/ToggleTest.php index 811b6ab2..71fa28eb 100644 --- a/tests/Unit/Blocks/ToggleTest.php +++ b/tests/Unit/Blocks/ToggleTest.php @@ -3,8 +3,10 @@ namespace Notion\Test\Unit\Blocks; use Notion\Blocks\BlockFactory; +use Notion\Blocks\ToDo; use Notion\Exceptions\BlockException; use Notion\Blocks\Toggle; +use Notion\Common\Color; use Notion\Common\Date; use Notion\Common\RichText; use PHPUnit\Framework\TestCase; @@ -132,6 +134,7 @@ public function test_transform_in_array(): void "color" => "default", ], ]], + "color" => "default", "children" => [], ], ]; @@ -184,4 +187,11 @@ public function test_add_child(): void $this->assertCount(1, $toggle->children); $this->assertEquals($nestedToggle, $toggle->children[0]); } + + public function test_change_color(): void + { + $block = ToDo::fromString("Hello World!")->changeColor(Color::Red); + + $this->assertSame(Color::Red, $block->color); + } }