Skip to content

Commit 250e56e

Browse files
committed
feat: add support for verification page property
1 parent 20eb64f commit 250e56e

File tree

4 files changed

+207
-0
lines changed

4 files changed

+207
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Brd6\NotionSdkPhp\Resource\Page\PropertyValue;
6+
7+
use Brd6\NotionSdkPhp\Resource\Property\DateProperty;
8+
use Brd6\NotionSdkPhp\Resource\User\AbstractUser;
9+
10+
class VerificationPropertyValue extends AbstractPropertyValue
11+
{
12+
protected string $state = 'unverified';
13+
protected ?AbstractUser $verifiedBy = null;
14+
protected ?DateProperty $date = null;
15+
16+
protected function initialize(): void
17+
{
18+
$data = (array) $this->getRawData()[$this->getType()];
19+
$this->state = (string) $data['state'];
20+
21+
if (isset($data['verified_by']) && $data['verified_by'] !== null) {
22+
$this->verifiedBy = AbstractUser::fromRawData((array) $data['verified_by']);
23+
}
24+
25+
if (isset($data['date']) && $data['date'] !== null) {
26+
$this->date = DateProperty::fromRawData((array) $data['date']);
27+
}
28+
}
29+
30+
public function getState(): string
31+
{
32+
return $this->state;
33+
}
34+
35+
public function setState(string $state): self
36+
{
37+
$this->state = $state;
38+
39+
return $this;
40+
}
41+
42+
public function getVerifiedBy(): ?AbstractUser
43+
{
44+
return $this->verifiedBy;
45+
}
46+
47+
public function setVerifiedBy(?AbstractUser $verifiedBy): self
48+
{
49+
$this->verifiedBy = $verifiedBy;
50+
51+
return $this;
52+
}
53+
54+
public function getDate(): ?DateProperty
55+
{
56+
return $this->date;
57+
}
58+
59+
public function setDate(?DateProperty $date): self
60+
{
61+
$this->date = $date;
62+
63+
return $this;
64+
}
65+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"object": "page",
3+
"id": "1101fb68-d6f1-48c9-bdd4-25004315fda1",
4+
"created_time": "2022-03-26T18:52:00.000Z",
5+
"last_edited_time": "2022-03-26T19:10:00.000Z",
6+
"created_by": {
7+
"object": "user",
8+
"id": "7f03dda0-a132-49d7-b8b2-29c9ed1b1f0e"
9+
},
10+
"last_edited_by": {
11+
"object": "user",
12+
"id": "7f03dda0-a132-49d7-b8b2-29c9ed1b1f0e"
13+
},
14+
"cover": null,
15+
"icon": null,
16+
"parent": {
17+
"type": "database_id",
18+
"database_id": "c3b5ecd0-4402-4c55-a396-be829b2407b8"
19+
},
20+
"archived": false,
21+
"properties": {
22+
"Verification": {
23+
"id": "fpVq",
24+
"type": "verification",
25+
"verification": {
26+
"state": "unverified",
27+
"verified_by": null,
28+
"date": null
29+
}
30+
}
31+
},
32+
"url": "https://www.notion.so/Database-verification-1101fb68d6f148c9bdd425004315fda1"
33+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"object": "page",
3+
"id": "1101fb68-d6f1-48c9-bdd4-25004315fda1",
4+
"created_time": "2022-03-26T18:52:00.000Z",
5+
"last_edited_time": "2022-03-26T19:10:00.000Z",
6+
"created_by": {
7+
"object": "user",
8+
"id": "7f03dda0-a132-49d7-b8b2-29c9ed1b1f0e"
9+
},
10+
"last_edited_by": {
11+
"object": "user",
12+
"id": "7f03dda0-a132-49d7-b8b2-29c9ed1b1f0e"
13+
},
14+
"cover": null,
15+
"icon": null,
16+
"parent": {
17+
"type": "database_id",
18+
"database_id": "c3b5ecd0-4402-4c55-a396-be829b2407b8"
19+
},
20+
"archived": false,
21+
"properties": {
22+
"Verification": {
23+
"id": "fpVq",
24+
"type": "verification",
25+
"verification": {
26+
"state": "verified",
27+
"verified_by": {
28+
"object": "user",
29+
"id": "01e46064-d5fb-4444-8ecc-ad47d076f804",
30+
"name": "User Name",
31+
"avatar_url": null,
32+
"type": "person",
33+
"person": {}
34+
},
35+
"date": {
36+
"start": "2023-08-01T04:00:00.000Z",
37+
"end": "2023-10-30T04:00:00.000Z",
38+
"time_zone": null
39+
}
40+
}
41+
}
42+
},
43+
"url": "https://www.notion.so/Database-verification-1101fb68d6f148c9bdd425004315fda1"
44+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Brd6\Test\NotionSdkPhp\Resource\Page\PropertyValue;
6+
7+
use Brd6\NotionSdkPhp\Resource\Page;
8+
use Brd6\NotionSdkPhp\Resource\Page\PropertyValue\VerificationPropertyValue;
9+
use Brd6\NotionSdkPhp\Resource\Property\DateProperty;
10+
use Brd6\NotionSdkPhp\Resource\User\AbstractUser;
11+
use PHPUnit\Framework\TestCase;
12+
13+
use function file_get_contents;
14+
use function json_decode;
15+
16+
class VerificationPropertyValueTest extends TestCase
17+
{
18+
public function testUnverifiedProperty(): void
19+
{
20+
/** @var Page $page */
21+
$page = Page::fromRawData(
22+
(array) json_decode(
23+
(string) file_get_contents('tests/Fixtures/client_pages_retrieve_page_verification_unverified_200.json'),
24+
true,
25+
),
26+
);
27+
28+
$properties = $page->getProperties();
29+
/** @var VerificationPropertyValue $verification */
30+
$verification = $properties['Verification'];
31+
32+
$this->assertEquals('verification', $verification->getType());
33+
$this->assertEquals('unverified', $verification->getState());
34+
$this->assertNull($verification->getVerifiedBy());
35+
$this->assertNull($verification->getDate());
36+
}
37+
38+
public function testVerifiedProperty(): void
39+
{
40+
/** @var Page $page */
41+
$page = Page::fromRawData(
42+
(array) json_decode(
43+
(string) file_get_contents('tests/Fixtures/client_pages_retrieve_page_verification_verified_200.json'),
44+
true,
45+
),
46+
);
47+
48+
$properties = $page->getProperties();
49+
/** @var VerificationPropertyValue $verification */
50+
$verification = $properties['Verification'];
51+
52+
$this->assertEquals('verification', $verification->getType());
53+
$this->assertEquals('verified', $verification->getState());
54+
55+
$verifiedBy = $verification->getVerifiedBy();
56+
$this->assertInstanceOf(AbstractUser::class, $verifiedBy);
57+
$this->assertEquals('01e46064-d5fb-4444-8ecc-ad47d076f804', $verifiedBy->getId());
58+
$this->assertEquals('User Name', $verifiedBy->getName());
59+
60+
$date = $verification->getDate();
61+
$this->assertInstanceOf(DateProperty::class, $date);
62+
$this->assertNotNull($date->getStart());
63+
$this->assertNotNull($date->getEnd());
64+
}
65+
}

0 commit comments

Comments
 (0)