|
11 | 11 | use Brd6\NotionSdkPhp\Resource\Block\ChildPageBlock; |
12 | 12 | use Brd6\NotionSdkPhp\Resource\Block\ColumnBlock; |
13 | 13 | use Brd6\NotionSdkPhp\Resource\Block\ColumnListBlock; |
| 14 | +use Brd6\NotionSdkPhp\Resource\Block\Heading1Block; |
| 15 | +use Brd6\NotionSdkPhp\Resource\Block\Heading2Block; |
| 16 | +use Brd6\NotionSdkPhp\Resource\Block\Heading3Block; |
| 17 | +use Brd6\NotionSdkPhp\Resource\Block\Heading4Block; |
| 18 | +use Brd6\NotionSdkPhp\Resource\Block\Heading5Block; |
| 19 | +use Brd6\NotionSdkPhp\Resource\Block\Heading6Block; |
14 | 20 | use Brd6\NotionSdkPhp\Resource\Block\ParagraphBlock; |
15 | 21 | use Brd6\NotionSdkPhp\Resource\Block\SyncedBlockBlock; |
| 22 | +use Brd6\NotionSdkPhp\Resource\Block\UnsupportedBlock; |
16 | 23 | use Brd6\NotionSdkPhp\Resource\File\AbstractFile; |
17 | 24 | use Brd6\NotionSdkPhp\Resource\File\Emoji; |
18 | 25 | use Brd6\NotionSdkPhp\Resource\Property\CalloutProperty; |
@@ -52,6 +59,17 @@ public function testInvalidBlockType(): void |
52 | 59 | ]); |
53 | 60 | } |
54 | 61 |
|
| 62 | + public function testUnsupportedBlock(): void |
| 63 | + { |
| 64 | + $block = AbstractBlock::fromRawData([ |
| 65 | + 'object' => 'block', |
| 66 | + 'type' => 'unsupported_block', |
| 67 | + ]); |
| 68 | + |
| 69 | + $this->assertInstanceOf(UnsupportedBlock::class, $block); |
| 70 | + $this->assertEquals('unsupported_block', $block->getType()); |
| 71 | + } |
| 72 | + |
55 | 73 | public function testBlock(): void |
56 | 74 | { |
57 | 75 | $block = AbstractBlock::fromRawData( |
@@ -110,30 +128,42 @@ public function testParagraphBlock(): void |
110 | 128 | public function testHeadingsBlock(): void |
111 | 129 | { |
112 | 130 | $headings = [ |
113 | | - 'heading_1', |
114 | | - 'heading_2', |
115 | | - 'heading_3', |
| 131 | + 'heading_1' => Heading1Block::class, |
| 132 | + 'heading_2' => Heading2Block::class, |
| 133 | + 'heading_3' => Heading3Block::class, |
| 134 | + 'heading_4' => Heading4Block::class, |
| 135 | + 'heading_5' => Heading5Block::class, |
| 136 | + 'heading_6' => Heading6Block::class, |
116 | 137 | ]; |
117 | 138 |
|
118 | | - foreach ($headings as $heading) { |
| 139 | + foreach ($headings as $heading => $blockClass) { |
119 | 140 | $rawContent = (string) file_get_contents('tests/Fixtures/client_blocks_retrieve_block_heading1_200.json'); |
120 | 141 |
|
121 | 142 | $rawContent = str_replace('heading_1', $heading, $rawContent); |
| 143 | + $rawData = (array) json_decode($rawContent, true); |
122 | 144 |
|
123 | 145 | $block = AbstractBlock::fromRawData( |
124 | | - (array) json_decode( |
125 | | - $rawContent, |
126 | | - true, |
127 | | - ), |
| 146 | + $rawData, |
128 | 147 | ); |
129 | 148 |
|
| 149 | + $blockData = $block->toArray(); |
130 | 150 | $typeFormatted = StringHelper::snakeCaseToCamelCase($block->getType()); |
131 | 151 | $getterMethodName = "get$typeFormatted"; |
132 | 152 |
|
| 153 | + $this->assertInstanceOf($blockClass, $block); |
133 | 154 | $this->assertEquals($heading, $block->getType()); |
134 | 155 | $this->assertNotNull($block->$getterMethodName()); |
135 | 156 | $this->assertInstanceOf(HeadingProperty::class, $block->$getterMethodName()); |
136 | 157 | $this->assertGreaterThan(0, count($block->$getterMethodName()->getRichText())); |
| 158 | + $this->assertArrayHasKey($heading, $blockData); |
| 159 | + $this->assertSame($rawData[$heading]['color'], $blockData[$heading]['color']); |
| 160 | + $this->assertSame($rawData[$heading]['rich_text'][0]['type'], $blockData[$heading]['rich_text'][0]['type']); |
| 161 | + $this->assertEquals($rawData[$heading]['rich_text'][0]['annotations'], $blockData[$heading]['rich_text'][0]['annotations']); |
| 162 | + $this->assertSame($rawData[$heading]['rich_text'][0]['plain_text'], $blockData[$heading]['rich_text'][0]['plain_text']); |
| 163 | + $this->assertSame( |
| 164 | + $rawData[$heading]['rich_text'][0]['text']['content'], |
| 165 | + $blockData[$heading]['rich_text'][0]['text']['content'], |
| 166 | + ); |
137 | 167 |
|
138 | 168 | $richText = $block->$getterMethodName()->getRichText()[0]; |
139 | 169 |
|
|
0 commit comments