use BookStack\Entities\Models\Page;
use BookStack\Entities\Tools\PageContent;
use Tests\TestCase;
-use Tests\Uploads\UsesImages;
class PageContentTest extends TestCase
{
- use UsesImages;
-
protected $base64Jpeg = '/9j/2wBDAAMCAgICAgMCAgIDAwMDBAYEBAQEBAgGBgUGCQgKCgkICQkKDA8MCgsOCwkJDRENDg8QEBEQCgwSExIQEw8QEBD/yQALCAABAAEBAREA/8wABgAQEAX/2gAIAQEAAD8A0s8g/9k=';
public function test_page_includes()
$htmlContent->assertSee('my cat is awesome and scratchy');
}
+ public function test_page_includes_can_be_nested_up_to_three_times()
+ {
+ $page = $this->entities->page();
+ $tag = "{{@{$page->id}#bkmrk-test}}";
+ $page->html = '<p id="bkmrk-test">Hello Barry ' . $tag . '</p>';
+ $page->save();
+
+ $pageResp = $this->asEditor()->get($page->getUrl());
+ $this->withHtml($pageResp)->assertElementContains('#bkmrk-test', 'Hello Barry Hello Barry Hello Barry Hello Barry ' . $tag);
+ $this->withHtml($pageResp)->assertElementNotContains('#bkmrk-test', 'Hello Barry Hello Barry Hello Barry Hello Barry Hello Barry ' . $tag);
+ }
+
public function test_page_content_scripts_removed_by_default()
{
$this->asEditor();
{
$page = $this->entities->page();
- $this->actingAs($this->getAdmin())
+ $this->actingAs($this->users->admin())
->put($page->getUrl(''), [
'name' => 'Testing',
'html' => '<p>"Hello & welcome"</p>',
$imageFile = public_path($imagePath);
$this->assertEquals(base64_decode($this->base64Jpeg), file_get_contents($imageFile));
- $this->deleteImage($imagePath);
+ $this->files->deleteAtRelativePath($imagePath);
}
public function test_base64_images_get_extracted_when_containing_whitespace()
$imageFile = public_path($imagePath);
$this->assertEquals(base64_decode($base64PngWithoutWhitespace), file_get_contents($imageFile));
- $this->deleteImage($imagePath);
+ $this->files->deleteAtRelativePath($imagePath);
}
public function test_base64_images_within_html_blanked_if_not_supported_extension_for_extract()
$imageFile = public_path($imagePath);
$this->assertEquals(base64_decode($this->base64Jpeg), file_get_contents($imageFile));
- $this->deleteImage($imagePath);
+ $this->files->deleteAtRelativePath($imagePath);
}
public function test_markdown_base64_extract_not_limited_by_pcre_limits()
$imageFile = public_path($imagePath);
$this->assertEquals($content, file_get_contents($imageFile));
- $this->deleteImage($imagePath);
+ $this->files->deleteAtRelativePath($imagePath);
ini_set('pcre.backtrack_limit', $pcreBacktrackLimit);
ini_set('pcre.recursion_limit', $pcreRecursionLimit);
}
$this->assertStringContainsString('<p id="bkmrk-%C2%A0"> </p>', $page->refresh()->html);
}
+
+ public function test_page_save_with_many_headers_and_links_is_reasonable()
+ {
+ $page = $this->entities->page();
+
+ $content = '';
+ for ($i = 0; $i < 500; $i++) {
+ $content .= "<table><tbody><tr><td><h5 id='header-{$i}'>Simple Test</h5><a href='#header-{$i}'></a></td></tr></tbody></table>";
+ }
+
+ $time = time();
+ $this->asEditor()->put($page->getUrl(), [
+ 'name' => $page->name,
+ 'html' => $content,
+ ])->assertRedirect();
+
+ $timeElapsed = time() - $time;
+ $this->assertLessThan(3, $timeElapsed);
+ }
}