Skip to content

Commit

Permalink
Merge branch 'release/v2.3.8'
Browse files Browse the repository at this point in the history
  • Loading branch information
appsol committed Jan 16, 2024
2 parents d1024dc + 6bd2db9 commit 7509f0e
Show file tree
Hide file tree
Showing 3 changed files with 181 additions and 2 deletions.
3 changes: 3 additions & 0 deletions app/Models/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public function toSearchableArray(): array
case 'cta':
$content[] = $this->makeSearchable($contentBlock['title'] . ' ' . $contentBlock['description']);
break;
case 'video':
$content[] = $this->makeSearchable($contentBlock['title']);
break;
default:
break;
}
Expand Down
27 changes: 25 additions & 2 deletions app/Rules/PageContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Support\Str;

class PageContent implements ValidationRule
{
Expand Down Expand Up @@ -50,8 +51,7 @@ public function validate(string $attribute, mixed $value, Closure $fail): void
$fail('Page content is required for introduction');
}

}
if ($value['type'] === 'cta') {
} elseif ($value['type'] === 'cta') {
if (empty($value['title']) || !is_string($value['title'])) {
$fail('Call to action title is required');
}
Expand All @@ -67,7 +67,30 @@ public function validate(string $attribute, mixed $value, Closure $fail): void
if (!empty($value['url']) && filter_var($value['url'], FILTER_VALIDATE_URL) === false) {
$fail('Call to action link must be a valid URL');
}
} elseif ($value['type'] === 'video') {
if (empty($value['title']) || !is_string($value['title'])) {
$fail('Video title is required');
}

if (empty($value['url']) || !is_string($value['url'])) {
$fail('Video url is required');
}

if (!empty($value['url'])) {
if (filter_var($value['url'], FILTER_VALIDATE_URL) === false) {
$fail('Video url must be a valid URL');
}

if (!Str::startsWith($value['url'], [
'https://www.youtube.com',
'https://player.vimeo.com',
'https://vimeo.com',
])) {
$fail('The video url must be provided by either YouTube or Vimeo.');
}
}
} else {
$fail('Invalid content type');
}
}
}
153 changes: 153 additions & 0 deletions tests/Feature/PagesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2084,6 +2084,7 @@ public function createInformationPageWithCallToActionAsContentAdmin422(): void

$parentPage = Page::factory()->create();

// Missing title
$data = [
'title' => $this->faker->sentence(),
'excerpt' => trim(substr($this->faker->paragraph(2), 0, 149)),
Expand Down Expand Up @@ -2111,6 +2112,7 @@ public function createInformationPageWithCallToActionAsContentAdmin422(): void

$response->assertStatus(Response::HTTP_UNPROCESSABLE_ENTITY);

// Missing description
$data = [
'title' => $this->faker->sentence(),
'excerpt' => trim(substr($this->faker->paragraph(2), 0, 149)),
Expand Down Expand Up @@ -2138,6 +2140,7 @@ public function createInformationPageWithCallToActionAsContentAdmin422(): void

$response->assertStatus(Response::HTTP_UNPROCESSABLE_ENTITY);

// Missing button text
$data = [
'title' => $this->faker->sentence(),
'excerpt' => trim(substr($this->faker->paragraph(2), 0, 149)),
Expand Down Expand Up @@ -2165,6 +2168,7 @@ public function createInformationPageWithCallToActionAsContentAdmin422(): void

$response->assertStatus(Response::HTTP_UNPROCESSABLE_ENTITY);

// Invalid URL
$data = [
'title' => $this->faker->sentence(),
'excerpt' => trim(substr($this->faker->paragraph(2), 0, 149)),
Expand Down Expand Up @@ -2236,6 +2240,49 @@ public function createInformationPageWithCallToActionAsContentAdmin200(): void
$response->assertStatus(Response::HTTP_OK);
}

/**
* @test
*/
public function createInformationPageWithVideoAsContentAdmin200(): void
{
/**
* @var \App\Models\User $user
*/
$user = User::factory()->create();
$user->makeContentAdmin();

Passport::actingAs($user);

$parentPage = Page::factory()->create();

$data = [
'title' => $this->faker->sentence(),
'excerpt' => trim(substr($this->faker->paragraph(2), 0, 149)),
'content' => [
'introduction' => [
'content' => [
[
'type' => 'copy',
'value' => $this->faker->realText(),
],
[
'type' => 'video',
'title' => $this->faker->sentence(),
'url' => 'https://www.youtube.com/watch?v=dummy_id',
],
],
],
],
'parent_id' => $parentPage->id,
'page_type' => 'information',
];
$response = $this->json('POST', '/core/v1/pages', $data);

$response->assertStatus(Response::HTTP_OK);

$response->assertJsonFragment($data);
}

/**
* @test
*/
Expand Down Expand Up @@ -2320,6 +2367,86 @@ public function createLandingPageWithCallToActionsAsContentAdmin200(): void
$response->assertStatus(Response::HTTP_OK);
}

/**
* @test
*/
public function createLandingPageWithVideosAsContentAdmin200(): void
{
/**
* @var \App\Models\User $user
*/
$user = User::factory()->create();
$user->makeContentAdmin();

Passport::actingAs($user);

$data = [
'title' => $this->faker->sentence(),
'excerpt' => trim(substr($this->faker->paragraph(2), 0, 149)),
'content' => [
'introduction' => [
'content' => [
[
'type' => 'copy',
'value' => $this->faker->realText(),
],
[
'type' => 'video',
'title' => $this->faker->sentence(),
'url' => 'https://www.youtube.com/watch?v=dummy_id',
],
],
],
'about' => [
'content' => [
[
'type' => 'copy',
'value' => $this->faker->realText(),
],
[
'type' => 'video',
'title' => $this->faker->sentence(),
'url' => 'https://www.youtube.com/watch?v=dummy_id',
],
[
'type' => 'copy',
'value' => $this->faker->realText(),
],
],
],
'info_pages' => [
'title' => $this->faker->sentence(),
'content' => [
[
'type' => 'copy',
'value' => $this->faker->realText(),
],
[
'type' => 'video',
'title' => $this->faker->sentence(),
'url' => 'https://www.youtube.com/watch?v=dummy_id',
],
],
],
'collections' => [
'title' => $this->faker->sentence(),
'content' => [
[
'type' => 'copy',
'value' => $this->faker->realText(),
],
],
],
],
'page_type' => Page::PAGE_TYPE_LANDING,
];
$response = $this->json('POST', '/core/v1/pages', $data);

$response->assertStatus(Response::HTTP_OK);

$response->assertJsonFragment($data);
}

/**
* @test
*/
Expand Down Expand Up @@ -2904,6 +3031,28 @@ public function updatePageAsContentAdmin200(): void
$data = [
'title' => 'New Title',
'enabled' => true,
'content' => [
'introduction' => [
'content' => [
[
'type' => 'copy',
'value' => $this->faker->realText(),
],
[
'type' => 'cta',
'title' => $this->faker->sentence(),
'description' => $this->faker->realText(),
'url' => $this->faker->url(),
'buttonText' => $this->faker->words(3, true),
],
[
'type' => 'video',
'title' => $this->faker->sentence(),
'url' => 'https://www.youtube.com/watch?v=dummy_id',
],
],
],
],
];

$response = $this->json('PUT', '/core/v1/pages/' . $page->id, $data);
Expand Down Expand Up @@ -2938,6 +3087,10 @@ public function updatePageAsContentAdmin200(): void
'title' => 'New Title',
'enabled' => true,
]);

$response = $this->json('GET', '/core/v1/pages/' . $page->id);

$response->assertJsonFragment($data);
}

/**
Expand Down

0 comments on commit 7509f0e

Please sign in to comment.