public function testCreateAndGetPageWithAssets() { Shortcodes::register(new Tweet()); $page = new Page(); $page->content = "[tweet id=\"20\"]"; $page->save(); $this->assertContains("twttr.widgets.createTweet", $page->html_content); $this->assertEquals(1, count(Assets::all())); $asset = Assets::all()[0]; $this->assertEquals('script', $asset->getType()); $this->assertEquals('//platform.twitter.com/widgets.js', $asset->getLocation()); $page = new Page(); $page->content = '# datatext'; $page->save(); $fetched = Pages::getPage($page->id); $this->assertEquals('<h1>datatext</h1>', $fetched['page']['html_content']); }
public function testShortCodesAreRendered() { Shortcodes::register(new Identity()); $page = new Page(); $page->content = <<<'MARKDOWN' [identity]hello[/identity] MARKDOWN; $this->assertEquals("<p>hello</p>", $page->toArray()['html_content']); }
public function getPage($id) { $page = Page::findOrFail($id); $assets = Assets::all(); return ["page" => $page, "assets" => $assets]; }
public static function boot() { parent::boot(); static::creating(function ($page) { $slugifier = new Slugify(); $page->setJsonAttribute('metadata', 'author', UserProvider::getCurrentUserId()); $page->setJsonAttribute('metadata', 'slug', $slugifier->slugify($page->title)); }); static::created(function ($page) { $revision = new PageRevision(); $revision->page_id = $page->id; $revision->revision_id = 0; $dmp = new DiffMatchPatch(); // Content patch $contentPatches = $dmp->patch_make("", $page->content); $revision->content_patch = $dmp->patch_toText($contentPatches); // Metadata patch $revision->metadata_patch = json_encode(JsonPatch::diff([], json_decode($page->metadata, 1))); $revision->author = UserProvider::getCurrentUserId(); $revision->created_at = Carbon::now(); $revision->save(); }); static::updating(function ($updatingPage) { // Get the page again from DB so we are sure we have up-to-date content to make the diff from $page = Page::find($updatingPage->id); $lastRevision = PageRevision::where('page_id', $page->id)->orderBy('revision_id', 'DESC')->firstOrFail(); $revision = new PageRevision(); $revision->page_id = $page->id; $revision->revision_id = $lastRevision->revision_id + 1; $dmp = new DiffMatchPatch(); // Content patch $contentPatches = $dmp->patch_make($page->getOriginal('content'), $updatingPage->content); $revision->content_patch = $dmp->patch_toText($contentPatches); // Metadata patch $revision->metadata_patch = json_encode(JsonPatch::diff(json_decode($page->metadata, 1), json_decode($updatingPage->metadata, 1))); $revision->author = UserProvider::getCurrentUserId(); $revision->created_at = Carbon::now(); $revision->save(); }); }