public function createConfigFromRepository(ContentRepository $repo) { $collection = $repo->getAll(); return $collection->reduce(function ($data, $page) { $data['pages'][$page->name] = ['description' => $page->description]; $page->textblocks->each(function ($textblock) use(&$data, $page) { $data['pages'][$page->name]['textblocks'][$textblock->name] = ['description' => $textblock->description, 'allows_html' => !!$textblock->allows_html]; }); $page->galleries->each(function ($gallery) use(&$data, $page) { $data['pages'][$page->name]['galleries'][$gallery->name] = ['description' => $gallery->description, 'is_single' => !!$gallery->is_single]; }); return $data; }, ['pages' => []]); }
/** *@test */ public function the_content_repo_can_fetch_all_pages_with_textblocks_and_galleries() { $repo = new ContentRepository(); $home = Page::create(['name' => 'home', 'description' => 'The homepage']); $about = Page::create(['name' => 'about', 'description' => 'The about page']); $contact = Page::create(['name' => 'contact', 'description' => 'The contact page']); $home->addTextblock('intro', 'The homepage intro'); $home->addTextblock('spiel', 'Company story', true); $home->addGallery('slider', 'Homepage banner slide images'); $about->addTextblock('intro', 'The about page intro'); $about->addTextblock('spiel', 'My story', true); $about->addGallery('slider', 'About page banner slide images'); $collection = $repo->getAll(); $this->assertCount(3, $collection); $this->assertCount(2, $collection->where('name', 'home')->first()->textblocks); $this->assertCount(2, $collection->where('name', 'about')->first()->textblocks); $this->assertCount(0, $collection->where('name', 'contact')->first()->textblocks); $this->assertCount(1, $collection->where('name', 'home')->first()->galleries); $this->assertCount(1, $collection->where('name', 'about')->first()->galleries); $this->assertCount(0, $collection->where('name', 'contact')->first()->galleries); }