Skip to content

Commit 6b31bcd

Browse files
authored
Merge pull request #161 from Gummibeer/add-quote-block
add quote block type
2 parents 207e873 + 1679318 commit 6b31bcd

File tree

4 files changed

+71
-3
lines changed

4 files changed

+71
-3
lines changed

src/Entities/Blocks/Block.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ private static function mapTypeToClass(string $type): string
175175
case 'video':
176176
case 'file':
177177
case 'pdf':
178+
case 'quote':
178179
$class = str_replace('_', '', ucwords($type, '_'));
179180

180181
return 'FiveamCode\\LaravelNotionApi\\Entities\\Blocks\\'.$class;

src/Entities/Blocks/Quote.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace FiveamCode\LaravelNotionApi\Entities\Blocks;
4+
5+
/**
6+
* Class Quote.
7+
*/
8+
class Quote extends TextBlock
9+
{
10+
public static function create($textContent): Quote
11+
{
12+
self::assertValidTextContent($textContent);
13+
14+
$quote = new Quote();
15+
TextBlock::createTextBlock($quote, $textContent);
16+
17+
return $quote;
18+
}
19+
20+
public function __construct(array $responseData = null)
21+
{
22+
$this->type = 'quote';
23+
parent::__construct($responseData);
24+
}
25+
}

tests/EndpointBlocksTest.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use FiveamCode\LaravelNotionApi\Entities\Blocks\NumberedListItem;
1414
use FiveamCode\LaravelNotionApi\Entities\Blocks\Paragraph;
1515
use FiveamCode\LaravelNotionApi\Entities\Blocks\Pdf;
16+
use FiveamCode\LaravelNotionApi\Entities\Blocks\Quote;
1617
use FiveamCode\LaravelNotionApi\Entities\Blocks\ToDo;
1718
use FiveamCode\LaravelNotionApi\Entities\Blocks\Toggle;
1819
use FiveamCode\LaravelNotionApi\Entities\Blocks\Video;
@@ -100,7 +101,7 @@ public function it_returns_block_collection_with_children_as_correct_instances()
100101
$blockChildrenCollection = $blockChildren->asCollection();
101102
$this->assertContainsOnly(Block::class, $blockChildrenCollection);
102103
$this->assertIsIterable($blockChildrenCollection);
103-
$this->assertCount(13, $blockChildrenCollection);
104+
$this->assertCount(14, $blockChildrenCollection);
104105

105106
// check paragraph
106107
$blockChild = $blockChildrenCollection[0];
@@ -201,6 +202,13 @@ public function it_returns_block_collection_with_children_as_correct_instances()
201202
$this->assertEquals('TestCaption', $blockChild->getCaption()->getPlainText());
202203
$this->assertEquals('external', $blockChild->getHostingType());
203204
$this->assertEquals('https://notion.so/testpdf.pdf', $blockChild->getUrl());
205+
206+
// check quote
207+
$blockChild = $blockChildrenCollection[13];
208+
$this->assertInstanceOf(Quote::class, $blockChild);
209+
$this->assertEquals('quote', $blockChild->getType());
210+
$this->assertFalse($blockChild->hasChildren());
211+
$this->assertEquals('quote_block', $blockChild->getContent()->getPlainText());
204212
}
205213

206214
/** @test */
@@ -251,6 +259,7 @@ public function it_returns_parent_block_in_which_new_blocks_have_been_successful
251259
$file = File::create('https://images.unsplash.com/photo-1593642533144-3d62aa4783ec?ixlib=rb-1.2.1&q=85&fm=jpg&crop=entropy&cs=srgb', 'Testcaption');
252260
$video = Video::create('https://www.w3schools.com/html/mov_bbb.mp4', 'TestCaption');
253261
$pdf = Pdf::create('https://notion.so/testpdf.pdf', 'TestCaption');
262+
$quote = Quote::create('New TextBlock');
254263

255264
$parentBlock = Notion::block('1d719dd1-563b-4387-b74f-20da92b827fb')->append($paragraph);
256265
$this->assertInstanceOf(Block::class, $parentBlock);
@@ -291,7 +300,10 @@ public function it_returns_parent_block_in_which_new_blocks_have_been_successful
291300
$parentBlock = Notion::block('1d719dd1-563b-4387-b74f-20da92b827fb')->append($pdf);
292301
$this->assertInstanceOf(Block::class, $parentBlock);
293302

294-
$parentBlock = Notion::block('1d719dd1-563b-4387-b74f-20da92b827fb')->append([$paragraph, $bulletedListItem, $headingOne, $headingTwo, $headingThree, $numberedListItem, $toDo, $toggle, $embed, $image, $video, $pdf]);
303+
$parentBlock = Notion::block('1d719dd1-563b-4387-b74f-20da92b827fb')->append($quote);
304+
$this->assertInstanceOf(Block::class, $parentBlock);
305+
306+
$parentBlock = Notion::block('1d719dd1-563b-4387-b74f-20da92b827fb')->append([$paragraph, $bulletedListItem, $headingOne, $headingTwo, $headingThree, $numberedListItem, $toDo, $toggle, $embed, $image, $video, $pdf, $quote]);
295307
$this->assertInstanceOf(Block::class, $parentBlock);
296308
}
297309

@@ -309,6 +321,7 @@ public function classProvider(): array
309321
[Paragraph::class],
310322
[ToDo::class],
311323
[Toggle::class],
324+
[Quote::class],
312325
];
313326
}
314327

@@ -322,7 +335,7 @@ public function classProvider(): array
322335
public function it_throws_an_handling_exception_for_wrong_type($entityClass)
323336
{
324337
$this->expectException(HandlingException::class);
325-
$paragraph = $entityClass::create(new \stdClass());
338+
$entityClass::create(new \stdClass());
326339
}
327340

328341
/** @test */

tests/stubs/endpoints/blocks/response_specific_supported_blocks_200.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,35 @@
400400
"url": "https://notion.so/testpdf.pdf"
401401
}
402402
}
403+
},
404+
{
405+
"object": "block",
406+
"id": "7b9d7473-bfa2-4914-bdcf-87244597d342",
407+
"created_time": "2023-06-20T11:50:00.000Z",
408+
"last_edited_time": "2023-06-20T11:50:00.000Z",
409+
"has_children": false,
410+
"type": "quote",
411+
"quote": {
412+
"text": [
413+
{
414+
"type": "text",
415+
"text": {
416+
"content": "quote_block",
417+
"link": null
418+
},
419+
"annotations": {
420+
"bold": false,
421+
"italic": false,
422+
"strikethrough": false,
423+
"underline": false,
424+
"code": false,
425+
"color": "default"
426+
},
427+
"plain_text": "quote_block",
428+
"href": null
429+
}
430+
]
431+
}
403432
}
404433
],
405434
"next_cursor": null,

0 commit comments

Comments
 (0)