/** * Load all blocks from database and events. * Blocks collection will stored in this class. * * return void */ private function initBlocks() { // get block // $databaseBlocks = Block::with(['menu', 'menu.items'])->whereActive(true)->orderBy('range', 'asc')->get(); $databaseBlocks = Block::with(['menu', 'menu.items'])->orderBy('range', 'asc')->get(); $eventBlocks = event('loadEventBlocks'); // TODO maybe use here the filter function // merge event blocks foreach ($eventBlocks as $eventBlock) { if (is_null($eventBlock)) { continue; } if ($eventBlock->active == false) { // not active continue; } $databaseBlocks->push($eventBlock); } // group by area $this->blocks = $databaseBlocks->filter(function ($block) { if (is_null($block)) { return false; } // check exception rule $ex = new Exception($block); return $ex->isViewable(); })->sortBy('range')->groupBy('area'); }
/** * @test */ public function it_has_only_access_on() { $block = factory(\Alpaca\Block\Models\Block::class)->make(['exception_rule' => Block::EXCEPTION_ONLY, 'exception' => 'blog/*']); $this->get('demo'); $ex = new Exception($block); $this->assertFalse($ex->isViewable()); $this->get('blog/alpaca'); $ex = new Exception($block); $this->assertTrue($ex->isViewable()); }