BookStack/tests/FooterLinksTest.php
Dan Brown 44c41e9e4d Updated footer links to be a configurable list
Made so footer link ordering, names and urls can be set.
Cleaned up some of the setting-service and added support for array
setting types, which are cleaned on entry and stored as json with a new
type indicator column on the settings table for auto-decode.
Also added testing to cover this feature.

Related to #1973 and #854
2021-01-31 00:23:15 +00:00

61 lines
2.4 KiB
PHP

<?php
use Tests\TestCase;
class FooterLinksTest extends TestCase
{
public function test_saving_setting()
{
$resp = $this->asAdmin()->post("/settings", [
'setting-app-footer-links' => [
['label' => 'My custom link 1', 'url' => 'https://example.com/1'],
['label' => 'My custom link 2', 'url' => 'https://example.com/2'],
],
]);
$resp->assertRedirect('/settings');
$result = setting('app-footer-links');
$this->assertIsArray($result);
$this->assertCount(2, $result);
$this->assertEquals('My custom link 2', $result[1]['label']);
$this->assertEquals('https://example.com/1', $result[0]['url']);
}
public function test_set_options_visible_on_settings_page()
{
$this->setSettings(['app-footer-links' => [
['label' => 'My custom link', 'url' => 'https://example.com/link-a'],
['label' => 'Another Link', 'url' => 'https://example.com/link-b'],
]]);
$resp = $this->asAdmin()->get('/settings');
$resp->assertSee('value="My custom link"');
$resp->assertSee('value="Another Link"');
$resp->assertSee('value="https://example.com/link-a"');
$resp->assertSee('value="https://example.com/link-b"');
}
public function test_footer_links_show_on_pages()
{
$this->setSettings(['app-footer-links' => [
['label' => 'My custom link', 'url' => 'https://example.com/link-a'],
['label' => 'Another Link', 'url' => 'https://example.com/link-b'],
]]);
$this->get('/login')->assertElementContains('footer a[href="https://example.com/link-a"]', 'My custom link');
$this->asEditor()->get('/')->assertElementContains('footer a[href="https://example.com/link-b"]', 'Another link');
}
public function test_using_translation_system_for_labels()
{
$this->setSettings(['app-footer-links' => [
['label' => 'trans::common.privacy_policy', 'url' => 'https://example.com/privacy'],
['label' => 'trans::common.terms_of_service', 'url' => 'https://example.com/terms'],
]]);
$resp = $this->get('/login');
$resp->assertElementContains('footer a[href="https://example.com/privacy"]', 'Privacy Policy');
$resp->assertElementContains('footer a[href="https://example.com/terms"]', 'Terms of Service');
}
}