Files
projectsend/tests/Feature/Files/BreadcrumbBuilderTest.php
ignacionelson 6e47d76ba6 ProjectSend 2.0.0
Client file sharing, rebuilt from the ground up: a private area per
client, resumable uploads, folders, groups and categories, sharing with
expiry dates and download limits, comments, file versions, an activity
log, a REST API, and sixteen languages.

This repository begins here. ProjectSend 2 was developed privately, and
that development history is not published — the previous generation
remains available, with its own history, at projectsend/legacy.

Free software under the GNU General Public License v2, or (at your
option) any later version.
2026-08-14 01:38:12 -03:00

72 lines
2.3 KiB
PHP

<?php
declare(strict_types=1);
use App\Models\User;
use App\Modules\Files\Folders\BreadcrumbBuilder;
use Illuminate\Support\Facades\Storage;
beforeEach(function () {
Storage::fake('files');
User::factory()->create();
$this->breadcrumbs = app(BreadcrumbBuilder::class);
});
test('no folder means no trail', function () {
expect($this->breadcrumbs->for(null))->toBe([])
->and($this->breadcrumbs->visible(null, []))->toBe([]);
});
test('a root folder is a trail of one', function () {
$root = makeFolder('Reports');
expect($this->breadcrumbs->for($root))->toBe([['id' => $root->id, 'name' => 'Reports']]);
});
// The reason this is worth a test at all: the trail is fetched with a single
// whereIn(), which returns rows in whatever order the database likes, and is
// then put back into ancestor order by hand. A breadcrumb out of order is
// nonsense, and nothing else would notice.
test('a nested trail comes back root-first, not in whatever order the query returned', function () {
$top = makeFolder('Clients');
$middle = makeFolder('Acme', $top);
$leaf = makeFolder('2026', $middle);
expect($this->breadcrumbs->for($leaf))->toBe([
['id' => $top->id, 'name' => 'Clients'],
['id' => $middle->id, 'name' => 'Acme'],
['id' => $leaf->id, 'name' => '2026'],
]);
});
test('the visible trail starts at the first ancestor the viewer can see', function () {
$top = makeFolder('Clients');
$middle = makeFolder('Acme', $top);
$leaf = makeFolder('2026', $middle);
// Shared from "Acme" down: the client has no business seeing "Clients".
$trail = $this->breadcrumbs->visible($leaf, [$middle->id, $leaf->id]);
expect($trail)->toBe([
['id' => $middle->id, 'name' => 'Acme'],
['id' => $leaf->id, 'name' => '2026'],
]);
});
test('a viewer who can see nothing above the folder gets the folder alone', function () {
$top = makeFolder('Clients');
$leaf = makeFolder('Acme', $top);
expect($this->breadcrumbs->visible($leaf, []))->toBe([
['id' => $leaf->id, 'name' => 'Acme'],
]);
});
test('a fully visible trail matches the unrestricted one', function () {
$top = makeFolder('Clients');
$leaf = makeFolder('Acme', $top);
expect($this->breadcrumbs->visible($leaf, [$top->id, $leaf->id]))
->toBe($this->breadcrumbs->for($leaf));
});