markTestSkipped('projectsend/community-modules is not installed in this environment.'); } // A staff user has to exist or EnsureSetupIsComplete redirects // everything to /setup. $this->staff = User::factory()->create(); }); function makeAsset(array $overrides = []): CustomAsset { return CustomAsset::query()->create(array_merge([ 'title' => 'Snippet', 'language' => 'js', 'content' => 'window.__asset_marker = 1;', 'surfaces' => ['staff'], 'position' => 'head', 'enabled' => true, 'created_by' => 1, ], $overrides)); } test('an enabled asset is emitted into its slot for a matching surface', function () { config()->set('projectsend.edition', Edition::Community); makeAsset(['position' => 'head', 'surfaces' => ['staff']]); $html = $this->actingAs($this->staff)->get('/dashboard')->assertOk()->getContent(); expect($html)->toContain('window.__asset_marker = 1;') // In , not somewhere else in the document. ->and(substr($html, 0, strpos($html, '')))->toContain('window.__asset_marker = 1;'); }); test('each position lands in its own slot', function () { config()->set('projectsend.edition', Edition::Community); makeAsset(['position' => 'head', 'content' => 'HEAD_MARK', 'language' => 'html']); makeAsset(['position' => 'body_top', 'content' => 'TOP_MARK', 'language' => 'html']); makeAsset(['position' => 'body_bottom', 'content' => 'BOTTOM_MARK', 'language' => 'html']); $html = $this->actingAs($this->staff)->get('/dashboard')->assertOk()->getContent(); $head = strpos($html, 'HEAD_MARK'); $top = strpos($html, 'TOP_MARK'); $bottom = strpos($html, 'BOTTOM_MARK'); expect($head)->toBeLessThan(strpos($html, '')) ->and($top)->toBeGreaterThan(strpos($html, 'and($bottom)->toBeGreaterThan($top) ->and($bottom)->toBeLessThan(strpos($html, '')); }); test('an asset for another surface is not emitted', function () { config()->set('projectsend.edition', Edition::Community); makeAsset(['surfaces' => ['public'], 'content' => 'PUBLIC_ONLY', 'language' => 'html']); $html = $this->actingAs($this->staff)->get('/dashboard')->assertOk()->getContent(); expect($html)->not->toContain('PUBLIC_ONLY'); }); test('a disabled asset is not emitted', function () { config()->set('projectsend.edition', Edition::Community); makeAsset(['enabled' => false, 'content' => 'DISABLED_MARK', 'language' => 'html']); $html = $this->actingAs($this->staff)->get('/dashboard')->assertOk()->getContent(); expect($html)->not->toContain('DISABLED_MARK'); }); // The authoring gate is not the only thing keeping arbitrary markup out of // a hosted install: a row that predates it, arrives in a restored backup, // or is written straight to the table must still render nothing. test('nothing is emitted in the cloud edition, even for an asset already in the table', function () { config()->set('projectsend.edition', Edition::Cloud); makeAsset(['content' => 'LEFTOVER_MARK', 'language' => 'html']); $html = $this->actingAs($this->staff)->get('/dashboard')->assertOk()->getContent(); expect($html)->not->toContain('LEFTOVER_MARK'); });