BookStack/tests/Settings/FooterLinksTest.php
Dan Brown 88c698796b
Fixed issue with HTML tags in custom head scripts
Fixes a strange issue of HTML tags within script tags being malformed
when part of the HTML custom head content due to the PHP parsing we do.
DOMDocument seemed to cause this upon load.
Adding LIBXML_SCHEMA_CREATE to the ->loadHTML call seems to fix this but
not really sure why. Doesn't seem to cause further issues though.
Tested with multiple scripts and styles and comments and meta tags.

- Also added new testing class to cover.
- As part of testing, added new folder within tests to house setting
  specific tests.

For #2914
2021-09-05 23:52:39 +01:00

61 lines
2.4 KiB
PHP

<?php namespace Tests\Settings;
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');
}
}