Skip to content

Commit d4043fc

Browse files
Olivia Madridmarkharding
Olivia Madrid
authored andcommitted
Store custom page default text in engine minds#4652
1 parent e83c1c1 commit d4043fc

File tree

7 files changed

+429
-4
lines changed

7 files changed

+429
-4
lines changed

Core/MultiTenant/CustomPages/Defaults/CustomPageDefaultContent.php

+411
Large diffs are not rendered by default.

Core/MultiTenant/CustomPages/Repository.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Minds\Core\Data\MySQL\AbstractRepository;
88
use Minds\Core\MultiTenant\CustomPages\Enums\CustomPageTypesEnum;
99
use Minds\Core\MultiTenant\CustomPages\Types\CustomPage;
10+
use Minds\Core\MultiTenant\CustomPages\Defaults\CustomPageDefaultContent;
1011
use Minds\Core\Data\MySQL\Client as MySQLClient;
1112
use Selective\Database\Operator;
1213
use Selective\Database\RawExp;
@@ -46,6 +47,7 @@ public function getCustomPageByType(CustomPageTypesEnum $pageType): ?CustomPage
4647
pageType: $pageType,
4748
content: null,
4849
externalLink: null,
50+
defaultContent: CustomPageDefaultContent::get()[$pageType->value] ?? null,
4951
tenantId: $tenantId
5052
);
5153
}
@@ -95,11 +97,15 @@ public function setCustomPage(CustomPageTypesEnum $pageType, ?string $content, ?
9597
*/
9698
private function buildCustomPage(array $row): CustomPage
9799
{
100+
$pageType = CustomPageTypesEnum::from($row['page_type']);
101+
$defaultContent = CustomPageDefaultContent::get()[$pageType->value] ?? null;
102+
98103
return new CustomPage(
99-
pageType: CustomPageTypesEnum::from($row['page_type']),
104+
pageType: $pageType,
100105
content: $row['content'] ?? null,
101106
externalLink: $row['external_link'] ?? null,
102-
tenantId: $row['tenant_id']
107+
defaultContent: $defaultContent,
108+
tenantId: $row['tenant_id'],
103109
);
104110
}
105111
}

Core/MultiTenant/CustomPages/Types/CustomPage.php

+2
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ class CustomPage implements NodeInterface
2121
* @param CustomPageTypesEnum $pageType
2222
* @param string|null $content
2323
* @param string|null $externalLink
24+
* @param string|null $defaultContent
2425
* @param int $tenantId
2526
*/
2627
public function __construct(
2728
#[Field] public readonly CustomPageTypesEnum $pageType,
2829
#[Field] public readonly ?string $content,
2930
#[Field] public readonly ?string $externalLink,
31+
#[Field] public readonly ?string $defaultContent,
3032
int $tenantId
3133
) {
3234
$this->tenantId = $tenantId;

OK

Whitespace-only changes.

Spec/Core/MultiTenant/CustomPages/Controllers/ControllerSpec.php

+2
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ public function it_should_get_a_custom_page(Service $service)
2626
$pageType = CustomPageTypesEnum::PRIVACY_POLICY;
2727
$content = 'Sample Content';
2828
$externalLink = 'https://example.com';
29+
$defaultContent = 'Default privacy policy text';
2930
$tenantId = 1;
3031

3132
$mockCustomPage = new CustomPage(
3233
$pageType,
3334
$content,
3435
$externalLink,
36+
$defaultContent,
3537
$tenantId
3638
);
3739

Spec/Core/MultiTenant/CustomPages/RepositorySpec.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Minds\Core\Data\MySQL\MySQLConnectionEnum;
77
use Minds\Core\Di\Di;
88
use Minds\Core\MultiTenant\CustomPages\Repository;
9+
use Minds\Core\MultiTenant\CustomPages\Defaults\CustomPageDefaultContent;
910
use Minds\Core\Data\MySQL\Client as MySQLClient;
1011
use Minds\Core\MultiTenant\CustomPages\Enums\CustomPageTypesEnum;
1112
use PDO;
@@ -48,8 +49,10 @@ public function it_is_initializable()
4849
$this->shouldHaveType(Repository::class);
4950
}
5051

51-
public function it_should_return_a_page(PDOStatement $stmtMock)
52+
public function it_should_return_a_page_with_default_content(PDOStatement $stmtMock)
5253
{
54+
$defaultContent = CustomPageDefaultContent::get()[CustomPageTypesEnum::COMMUNITY_GUIDELINES->value] ?? null;
55+
5356
$this->mysqlReplicaMock->quote(Argument::any())->willReturn("");
5457
$this->mysqlReplicaMock->prepare(Argument::any())->willReturn($stmtMock);
5558

@@ -71,6 +74,7 @@ public function it_should_return_a_page(PDOStatement $stmtMock)
7174
$response = $this->getCustomPageByType(CustomPageTypesEnum::COMMUNITY_GUIDELINES);
7275
$response->content->shouldBe("i am content");
7376
$response->pageType->shouldBe(CustomPageTypesEnum::COMMUNITY_GUIDELINES);
77+
$response->defaultContent->shouldBe($defaultContent);
7478
}
7579

7680
public function it_should_save_page(PDOStatement $stmtMock)

Spec/Core/MultiTenant/CustomPages/Services/ServiceSpec.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function it_is_initializable()
2424
public function it_should_get_a_custom_page(Repository $repository)
2525
{
2626
$pageType = CustomPageTypesEnum::PRIVACY_POLICY;
27-
$customPage = new CustomPage($pageType, 'Sample Content', null, 1);
27+
$customPage = new CustomPage($pageType, 'Sample Content', null, 'Default content', 1);
2828

2929
$repository->getCustomPageByType($pageType)->willReturn($customPage);
3030

0 commit comments

Comments
 (0)