Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
58e05e88ae | ||
|
|
8ebed89e73 | ||
|
|
e0767b65e6 | ||
|
|
19e6b1a332 | ||
|
|
d035a18ee6 | ||
|
|
d2802f728f | ||
|
|
5ffc191488 |
@@ -11,6 +11,7 @@ return [
|
||||
*/
|
||||
"general" => [
|
||||
"language" => "en",
|
||||
"timezone" => "UTC",
|
||||
"assets_url" => "/plugi-core/dist",
|
||||
"uploads_url" => "/uploads",
|
||||
],
|
||||
|
||||
@@ -8,9 +8,11 @@ The blog extension provides Website Manager post and category management plus tw
|
||||
2. Open Website Manager and apply the pending database definition update. Existing installations need this update to create or update the extension-owned post and category tables, including the optional featured-image field.
|
||||
3. Add categories if useful, then create posts as drafts or publish them from the Blog section.
|
||||
|
||||
Set `general.timezone` in the root `config.php` to the site's IANA timezone (for example, `Europe/Berlin`); it defaults to `UTC` and controls blog publication input and display. Publication dates are stored as site-local `DATETIME` values, so existing installations should configure the timezone that matches their existing post dates.
|
||||
|
||||
## Create the public pages
|
||||
|
||||
1. Create a regular Plugi page with the route `/blog` and add the **Published Posts** block. It lists published posts newest first; drafts are never shown.
|
||||
1. Create a regular Plugi page with the route `/blog` and add the **Published Posts** block. It lists published posts newest first; drafts are never shown. Public search matches titles, slugs, and excerpts (at least three characters), not full post bodies.
|
||||
2. Create another regular page with the route `/blog/{slug}` and add the **Blog Post** block. The core router supplies the named `slug` parameter to the block.
|
||||
3. Apply the site’s normal page layout and theme to both pages. Their presentation remains controlled by the page builder and theme.
|
||||
|
||||
|
||||
@@ -3,12 +3,14 @@
|
||||
namespace Plugi\Extensions\Blog;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use DateTimeZone;
|
||||
use InvalidArgumentException;
|
||||
use Plugi\Repositories\BaseRepository;
|
||||
|
||||
class PostsRepository extends BaseRepository
|
||||
{
|
||||
public const POSTS_PER_PAGE = 10;
|
||||
public const MIN_PUBLIC_SEARCH_LENGTH = 3;
|
||||
|
||||
protected $table = 'ext__blog_posts';
|
||||
|
||||
@@ -32,17 +34,6 @@ class PostsRepository extends BaseRepository
|
||||
return $this->db->select("SELECT * FROM {$this->table} ORDER BY updated_at DESC, id DESC", []);
|
||||
}
|
||||
|
||||
public function getPublishedForListing(): array
|
||||
{
|
||||
$categoriesTable = $_ENV['DATABASE_PREFIX'] . 'ext__blog_categories';
|
||||
$uploadsTable = $_ENV['DATABASE_PREFIX'] . 'uploads';
|
||||
$posts = $this->db->select(
|
||||
"SELECT posts.*, categories.name AS category_name, featured_image.public_id AS featured_image_public_id, featured_image.original_file AS featured_image_original_file, featured_image.alt_text AS featured_image_alt_text FROM {$this->table} posts LEFT JOIN {$categoriesTable} categories ON categories.id = posts.category_id LEFT JOIN {$uploadsTable} featured_image ON featured_image.public_id = posts.featured_image_id AND LOWER(featured_image.mime_type) LIKE 'image/%' WHERE posts.status = ? ORDER BY posts.published_at DESC, posts.id DESC",
|
||||
['published']
|
||||
);
|
||||
return array_map(fn(array $post): array => $this->resolveFeaturedImage($post), $posts);
|
||||
}
|
||||
|
||||
public function getPageForAdmin(string $search, int $page): array
|
||||
{
|
||||
return $this->getPostPage($search, $page, false);
|
||||
@@ -55,6 +46,11 @@ class PostsRepository extends BaseRepository
|
||||
|
||||
private function getPostPage(string $search, int $page, bool $publishedOnly): array
|
||||
{
|
||||
$search = trim($search);
|
||||
if ($publishedOnly && $search !== '' && mb_strlen($search) < self::MIN_PUBLIC_SEARCH_LENGTH) {
|
||||
return ['posts' => [], 'total' => 0];
|
||||
}
|
||||
|
||||
$categoriesTable = $_ENV['DATABASE_PREFIX'] . 'ext__blog_categories';
|
||||
$uploadsTable = $_ENV['DATABASE_PREFIX'] . 'uploads';
|
||||
$from = $publishedOnly
|
||||
@@ -68,9 +64,14 @@ class PostsRepository extends BaseRepository
|
||||
$parameters[] = 'published';
|
||||
}
|
||||
if (trim($search) !== '') {
|
||||
$filters[] = '(posts.title LIKE ? ESCAPE \'!\' OR posts.slug LIKE ? ESCAPE \'!\' OR posts.excerpt LIKE ? ESCAPE \'!\' OR posts.body LIKE ? ESCAPE \'!\')';
|
||||
$filters[] = $publishedOnly
|
||||
? '(posts.title LIKE ? ESCAPE \'!\' OR posts.slug LIKE ? ESCAPE \'!\' OR posts.excerpt LIKE ? ESCAPE \'!\')'
|
||||
: '(posts.title LIKE ? ESCAPE \'!\' OR posts.slug LIKE ? ESCAPE \'!\' OR posts.excerpt LIKE ? ESCAPE \'!\' OR posts.body LIKE ? ESCAPE \'!\')';
|
||||
$pattern = '%' . str_replace(['!', '%', '_'], ['!!', '!%', '!_'], trim($search)) . '%';
|
||||
array_push($parameters, $pattern, $pattern, $pattern, $pattern);
|
||||
array_push($parameters, $pattern, $pattern, $pattern);
|
||||
if (!$publishedOnly) {
|
||||
$parameters[] = $pattern;
|
||||
}
|
||||
}
|
||||
|
||||
$where = $filters === [] ? '' : ' WHERE ' . implode(' AND ', $filters);
|
||||
@@ -194,8 +195,9 @@ class PostsRepository extends BaseRepository
|
||||
|
||||
private function validatedPublicationDate(mixed $value, string $status): ?string
|
||||
{
|
||||
$timezone = new DateTimeZone((string) (phpb_config('general.timezone') ?: 'UTC'));
|
||||
if ($value === null || $value === '') {
|
||||
return $status === 'published' ? date('Y-m-d H:i:s') : null;
|
||||
return $status === 'published' ? (new DateTimeImmutable('now', $timezone))->format('Y-m-d H:i:s') : null;
|
||||
}
|
||||
if (!is_string($value)) {
|
||||
throw new InvalidArgumentException('Enter a valid publication date.');
|
||||
@@ -203,12 +205,12 @@ class PostsRepository extends BaseRepository
|
||||
|
||||
$value = trim($value);
|
||||
$format = str_contains($value, 'T') ? 'Y-m-d\\TH:i' : 'Y-m-d H:i:s';
|
||||
$date = DateTimeImmutable::createFromFormat('!' . $format, $value);
|
||||
$date = DateTimeImmutable::createFromFormat('!' . $format, $value, $timezone);
|
||||
$errors = DateTimeImmutable::getLastErrors();
|
||||
if ($date === false || ($errors !== false && ($errors['warning_count'] > 0 || $errors['error_count'] > 0)) || $date->format($format) !== $value) {
|
||||
throw new InvalidArgumentException('Enter a valid publication date.');
|
||||
}
|
||||
if ($date > new DateTimeImmutable()) {
|
||||
if ($date > new DateTimeImmutable('now', $timezone)) {
|
||||
throw new InvalidArgumentException('Publication dates cannot be in the future.');
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ use Plugi\Extensions\Blog\PostsRepository;
|
||||
use Plugi\Repositories\UploadRepository;
|
||||
|
||||
$postsRepository = new PostsRepository();
|
||||
$timezone = new \DateTimeZone((string) (phpb_config('general.timezone') ?: 'UTC'));
|
||||
$post = [
|
||||
'title' => '',
|
||||
'slug' => '',
|
||||
@@ -19,7 +20,7 @@ if (isset($_GET['id']) && ctype_digit((string) $_GET['id'])) {
|
||||
$post = $postsRepository->findWithId($_GET['id']) ?? $post;
|
||||
}
|
||||
$isEditing = isset($post['id']);
|
||||
$publishedAt = $post['published_at'] ? date('Y-m-d\TH:i', strtotime($post['published_at'])) : '';
|
||||
$publishedAt = $post['published_at'] ? (new \DateTimeImmutable($post['published_at'], $timezone))->format('Y-m-d\TH:i') : '';
|
||||
$categories = (new CategoriesRepository())->getAllForAdmin();
|
||||
$imageUploads = array_values(array_filter((new UploadRepository())->getAll(), static fn($file): bool => is_string($file->mime_type ?? null) && str_starts_with(strtolower($file->mime_type), 'image/')));
|
||||
?>
|
||||
@@ -147,7 +148,7 @@ $imageUploads = array_values(array_filter((new UploadRepository())->getAll(), st
|
||||
<div>
|
||||
<label for="post-published-at" class="label"><span class="label-text font-medium">Publication date</span></label>
|
||||
<input id="post-published-at" type="datetime-local" name="published_at" value="<?= phpb_e($publishedAt) ?>" class="input w-full" aria-describedby="post-published-at-help">
|
||||
<p id="post-published-at-help" class="mt-1 text-sm text-base-content/60">Leave blank to use the current time when publishing. Future dates are not supported.</p>
|
||||
<p id="post-published-at-help" class="mt-1 text-sm text-base-content/60">Times use the site timezone (<?= phpb_e($timezone->getName()) ?>). Leave blank to use the current time when publishing. Future dates are not supported.</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -73,7 +73,7 @@ foreach ($categories as $category) {
|
||||
<th>Title</th>
|
||||
<th>Category</th>
|
||||
<th>Status</th>
|
||||
<th>Published</th>
|
||||
<th>Published (site time)</th>
|
||||
<th class="w-40 text-right">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
$slug = phpb_route_parameter('slug');
|
||||
$timezone = new \DateTimeZone((string) (phpb_config('general.timezone') ?: 'UTC'));
|
||||
$post = is_string($slug) && $slug !== ''
|
||||
? (new \Plugi\Extensions\Blog\PostsRepository())->findPublishedBySlug($slug)
|
||||
: null;
|
||||
@@ -20,9 +21,9 @@ $post = is_string($slug) && $slug !== ''
|
||||
<span class="badge badge-outline"><?= phpb_e($post['category_name']) ?></span>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($post['published_at'])): ?>
|
||||
<?php $publishedTimestamp = strtotime($post['published_at']); ?>
|
||||
<?php if ($publishedTimestamp !== false): ?>
|
||||
<time datetime="<?= phpb_e(date('c', $publishedTimestamp)) ?>"><?= phpb_e(date('F j, Y', $publishedTimestamp)) ?></time>
|
||||
<?php $publishedDate = date_create($post['published_at'], $timezone); ?>
|
||||
<?php if ($publishedDate !== false): ?>
|
||||
<time datetime="<?= phpb_e($publishedDate->format('c')) ?>"><?= phpb_e($publishedDate->format('F j, Y')) ?></time>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
<?php
|
||||
|
||||
$postsRepository = new \Plugi\Extensions\Blog\PostsRepository();
|
||||
$timezone = new \DateTimeZone((string) (phpb_config('general.timezone') ?: 'UTC'));
|
||||
$search = is_string($_GET['q'] ?? null) ? trim($_GET['q']) : '';
|
||||
$pageValue = $_GET['page'] ?? null;
|
||||
$page = is_string($pageValue) ? filter_var($pageValue, FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]]) : false;
|
||||
$page = $page === false ? 1 : $page;
|
||||
$listingPath = isset($_SERVER['SERVER_NAME'], $_SERVER['REQUEST_URI']) ? phpb_full_url(phpb_current_relative_url(true)) : '/';
|
||||
$pageResult = $postsRepository->getPageForListing($search, $page);
|
||||
$searchTooShort = $search !== '' && mb_strlen($search) < \Plugi\Extensions\Blog\PostsRepository::MIN_PUBLIC_SEARCH_LENGTH;
|
||||
$totalPages = max(1, (int) ceil($pageResult['total'] / \Plugi\Extensions\Blog\PostsRepository::POSTS_PER_PAGE));
|
||||
if ($page > $totalPages) {
|
||||
$page = $totalPages;
|
||||
@@ -17,13 +19,15 @@ $searchParameters = $search === '' ? [] : ['q' => $search];
|
||||
<section class="space-y-6" aria-label="Blog posts">
|
||||
<form class="flex flex-col gap-3 sm:flex-row sm:items-end" method="get" action="<?= phpb_e($listingPath) ?>">
|
||||
<label class="flex w-full max-w-md flex-col gap-2">
|
||||
<span class="text-sm font-medium">Search posts</span>
|
||||
<span class="text-sm font-medium">Search titles, slugs, and excerpts (3+ characters)</span>
|
||||
<input class="input w-full" type="search" name="q" value="<?= phpb_e($search) ?>" />
|
||||
</label>
|
||||
<button class="btn" type="submit">Search</button>
|
||||
</form>
|
||||
|
||||
<?php if ($pageResult['total'] === 0): ?>
|
||||
<?php if ($searchTooShort): ?>
|
||||
<div class="alert alert-info" role="status">Enter at least <?= \Plugi\Extensions\Blog\PostsRepository::MIN_PUBLIC_SEARCH_LENGTH ?> characters to search.</div>
|
||||
<?php elseif ($pageResult['total'] === 0): ?>
|
||||
<div class="alert alert-info" role="status">
|
||||
<?= $search === '' ? 'No published posts yet.' : 'No published posts match "' . phpb_e($search) . '".' ?>
|
||||
</div>
|
||||
@@ -43,9 +47,9 @@ $searchParameters = $search === '' ? [] : ['q' => $search];
|
||||
<span class="badge badge-outline"><?= phpb_e($post['category_name']) ?></span>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($post['published_at'])): ?>
|
||||
<?php $publishedTimestamp = strtotime($post['published_at']); ?>
|
||||
<?php if ($publishedTimestamp !== false): ?>
|
||||
<time datetime="<?= phpb_e(date('c', $publishedTimestamp)) ?>"><?= phpb_e(date('F j, Y', $publishedTimestamp)) ?></time>
|
||||
<?php $publishedDate = date_create($post['published_at'], $timezone); ?>
|
||||
<?php if ($publishedDate !== false): ?>
|
||||
<time datetime="<?= phpb_e($publishedDate->format('c')) ?>"><?= phpb_e($publishedDate->format('F j, Y')) ?></time>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
@@ -141,6 +141,9 @@ function renderBlogEditor(int $postId): string
|
||||
}
|
||||
|
||||
$_ENV['DATABASE_PREFIX'] = 'test_';
|
||||
$siteTimezone = 'Pacific/Kiritimati';
|
||||
date_default_timezone_set('Pacific/Pago_Pago');
|
||||
$phpb_config = ['website_manager' => ['url' => '/website-manager'], 'general' => ['uploads_url' => '/uploads', 'timezone' => $siteTimezone]];
|
||||
$phpb_db = new BlogTestDatabase();
|
||||
$phpb_db->createSchema();
|
||||
assertBlog(isset($phpb_db->getDBDefinition()['ext__blog_posts'], $phpb_db->getDBDefinition()['ext__blog_categories']), 'The blog tables should be included in the core database definition.');
|
||||
@@ -183,6 +186,8 @@ $post = $posts->create([
|
||||
]);
|
||||
assertBlog(is_array($post) && $post['status'] === 'published', 'A valid published post should be created.');
|
||||
assertBlog($post['published_at'] !== null, 'Publishing without a date should set the current publication timestamp.');
|
||||
$storedPublication = \DateTimeImmutable::createFromFormat('!Y-m-d H:i:s', $post['published_at'], new \DateTimeZone($siteTimezone));
|
||||
assertBlog($storedPublication !== false && abs($storedPublication->getTimestamp() - time()) < 60, 'The automatic publication timestamp should use the configured site timezone.');
|
||||
assertBlog($post['featured_image_id'] === 'blog-cover-1', 'A valid image upload reference should be persisted on the post.');
|
||||
expectBlogValidation(fn() => $posts->create([
|
||||
'title' => 'Missing featured image', 'slug' => 'missing-featured-image', 'excerpt' => '', 'body' => 'Body', 'featured_image_id' => 'missing-upload', 'category_id' => '', 'status' => 'draft', 'published_at' => '',
|
||||
@@ -200,7 +205,7 @@ $olderPost = $posts->create([
|
||||
'status' => 'published',
|
||||
'published_at' => '2020-01-01T00:00',
|
||||
]);
|
||||
$pastPublication = date('Y-m-d\\TH:i', time() - 3600);
|
||||
$pastPublication = (new \DateTimeImmutable('now', new \DateTimeZone($siteTimezone)))->modify('-1 hour')->format('Y-m-d\\TH:i');
|
||||
$datedPost = $posts->create([
|
||||
'title' => 'Dated draft',
|
||||
'slug' => 'dated-draft',
|
||||
@@ -220,13 +225,9 @@ $secondPost = $posts->create([
|
||||
'published_at' => '',
|
||||
]);
|
||||
$_ENV['BASE_URL'] = 'https://blog.example';
|
||||
$phpb_config = ['website_manager' => ['url' => '/website-manager'], 'general' => ['uploads_url' => '/uploads']];
|
||||
$publishedPosts = $posts->getPublishedForListing();
|
||||
assertBlog(count($publishedPosts) === 2, 'The public listing should exclude drafts.');
|
||||
assertBlog($publishedPosts[0]['slug'] === $post['slug'] && $publishedPosts[0]['category_name'] === 'News', 'Published posts should be newest first and include their category name.');
|
||||
assertBlog($publishedPosts[1]['slug'] === $olderPost['slug'], 'Older published posts should follow newer posts.');
|
||||
|
||||
$editorHtml = renderBlogEditor((int) $post['id']);
|
||||
assertBlog(str_contains($editorHtml, 'site timezone (Pacific/Kiritimati)'), 'The editor should identify the timezone used for publication dates.');
|
||||
assertBlog(str_contains($editorHtml, '<textarea id="post-body" name="body"') && str_contains($editorHtml, 'Post body'), 'The visible fallback textarea should retain and submit the stored body value.');
|
||||
assertBlog(str_contains($editorHtml, 'id="post-body-toolbar"') && str_contains($editorHtml, 'data-format="bold"') && str_contains($editorHtml, 'data-format="heading"'), 'The editor should provide accessible Markdown formatting controls.');
|
||||
assertBlog(str_contains($editorHtml, 'data-format="list"') && str_contains($editorHtml, 'data-format="ordered-list"') && str_contains($editorHtml, 'data-format="quote"') && str_contains($editorHtml, 'data-format="horizontal-rule"') && str_contains($editorHtml, 'data-format="code-block"'), 'The editor toolbar should offer unordered and ordered lists, quotes, horizontal rules, and code blocks.');
|
||||
@@ -240,10 +241,12 @@ assertBlog(str_contains($editorHtml, 'selectionStart') && str_contains($editorHt
|
||||
assertBlog(str_contains($editorHtml, 'window.blogMarkdownEditor.insertAtCursor(markdown)'), 'The inline picker should insert at the CodeMirror cursor when the editor is initialized.');
|
||||
$listingHtml = renderBlogListing();
|
||||
assertBlog(str_contains($listingHtml, 'href="https://blog.example/blog/first-post"'), 'The listing should link to the configured post detail URL.');
|
||||
assertBlog(str_contains($listingHtml, 'datetime="2020-01-01T00:00:00+14:00"'), 'Public listing dates should use the configured site timezone.');
|
||||
assertBlog(str_contains($listingHtml, 'src="https://blog.example/uploads/blog-cover-1/cover.jpg" alt="A "featured" & <cover>"'), 'The public listing should display a featured image with escaped alt text.');
|
||||
assertBlog(strpos($listingHtml, 'first-post') < strpos($listingHtml, 'older-published-post'), 'The rendered listing should preserve newest-first order.');
|
||||
assertBlog(!str_contains($listingHtml, 'dated-draft') && !str_contains($listingHtml, 'second-post'), 'Draft posts should not appear in the rendered listing.');
|
||||
$detailHtml = renderBlogDetail('older-published-post');
|
||||
assertBlog(str_contains($detailHtml, 'datetime="2020-01-01T00:00:00+14:00"'), 'Public detail dates should use the configured site timezone.');
|
||||
assertBlog(str_contains($detailHtml, '<h1 class="text-3xl font-bold tracking-tight text-base-content sm:text-4xl">Older published post</h1>'), 'The detail block should resolve a published post from the named slug route parameter.');
|
||||
assertBlog(str_contains($detailHtml, '<h2 class="text-2xl font-bold tracking-tight">Markdown heading</h2>') && str_contains($detailHtml, '<strong>bold</strong>') && str_contains($detailHtml, '<em>emphasized</em>'), 'The detail block should render Markdown headings and emphasis.');
|
||||
assertBlog(str_contains($detailHtml, '<a class="link link-hover" href="https://example.com">safe link</a>') && !str_contains($detailHtml, 'href="javascript:') && !str_contains($detailHtml, 'href="java'), 'The detail block should render safe links and reject unsafe protocols.');
|
||||
@@ -283,7 +286,7 @@ expectBlogValidation(fn() => $posts->create([
|
||||
'title' => 'Invalid date', 'slug' => 'invalid-date', 'excerpt' => '', 'body' => '', 'category_id' => '', 'status' => 'draft', 'published_at' => 'not-a-date',
|
||||
]), 'Invalid publication dates should be rejected.');
|
||||
expectBlogValidation(fn() => $posts->create([
|
||||
'title' => 'Future date', 'slug' => 'future-date', 'excerpt' => '', 'body' => '', 'category_id' => '', 'status' => 'draft', 'published_at' => date('Y-m-d\\TH:i', time() + 86400),
|
||||
'title' => 'Future date', 'slug' => 'future-date', 'excerpt' => '', 'body' => '', 'category_id' => '', 'status' => 'draft', 'published_at' => (new \DateTimeImmutable('now', new \DateTimeZone($siteTimezone)))->modify('+1 day')->format('Y-m-d\\TH:i'),
|
||||
]), 'Future publication dates should be rejected.');
|
||||
|
||||
$updated = $posts->update(['id' => $post['id']], [
|
||||
@@ -331,7 +334,7 @@ assertBlog($posts->destroy($olderPost['id']) === true, 'An older published post
|
||||
assertBlog($posts->destroy($post['id']) === true, 'The remaining draft should be deleted.');
|
||||
assertBlog($categories->findWithId($category['id']) === null && $posts->findWithId($secondPost['id']) === null, 'Deleted records should no longer be found.');
|
||||
assertBlog(str_contains(renderBlogListing(), 'No published posts yet.'), 'The listing should show an empty state when no posts are published.');
|
||||
$phpb_config = ['website_manager' => ['url' => '/website-manager']];
|
||||
$phpb_config = ['website_manager' => ['url' => '/website-manager'], 'general' => ['uploads_url' => '/uploads', 'timezone' => $siteTimezone]];
|
||||
$_GET = [];
|
||||
assertBlog(str_contains(renderBlogAdminList(), 'No posts yet'), 'The admin list should show its empty-list state when no posts exist.');
|
||||
|
||||
@@ -370,8 +373,13 @@ foreach ([
|
||||
$adminMatch = $posts->getPageForAdmin($term, 1);
|
||||
$publicMatch = $posts->getPageForListing($term, 1);
|
||||
assertBlog($adminMatch['total'] === 1 && $adminMatch['posts'][0]['slug'] === $fieldPost['slug'], 'Admin search should match the ' . $field . ' field.');
|
||||
assertBlog($publicMatch['total'] === 1 && $publicMatch['posts'][0]['slug'] === $fieldPost['slug'], 'Public search should match the ' . $field . ' field.');
|
||||
assertBlog($field === 'body' ? $publicMatch['total'] === 0 : $publicMatch['total'] === 1 && $publicMatch['posts'][0]['slug'] === $fieldPost['slug'], 'Public search should match only title, slug, and excerpt fields.');
|
||||
}
|
||||
$shortPublicSearch = $posts->getPageForListing('po', 1);
|
||||
assertBlog($shortPublicSearch['total'] === 0 && $shortPublicSearch['posts'] === [], 'Public search should ignore queries shorter than three characters.');
|
||||
$_GET = ['q' => 'po'];
|
||||
assertBlog(str_contains(renderBlogListing(), 'Enter at least 3 characters to search.'), 'The public listing should explain the minimum search length.');
|
||||
$_GET = [];
|
||||
|
||||
foreach ([
|
||||
['term' => '100%', 'match' => 'literal-percent', 'title' => 'Price 100% complete', 'decoy' => 'wildcard-percent-decoy', 'decoyTitle' => 'Price 100X complete'],
|
||||
|
||||
Reference in New Issue
Block a user