/** * @test */ public function it_allows_choice_no_category() { $this->actingAs(User::first()); // create a page with a category $this->visit(route('backend.page.create'))->type('Hallo', 'title')->type('hallo', 'slug')->select('', 'category_id')->type('Content', 'body')->press('Save')->see('alert-success'); $page = Page::whereSlug('hallo')->first(); $this->assertNotNull($page); $this->assertEquals($page->category_id, '', 'Category id saved in page'); }
/** * @test */ public function it_allows_update_frontpage() { // log in $adminUser = User::first(); $this->actingAs($adminUser); // update a page without slug $this->visit('/backend/page/1/edit')->type('My Cool CMF System', 'title')->type('Soo cool', 'body')->press(trans('crud::crud.save'))->see('alert-success'); $this->assertNotNull(Page::whereSlug('')->first(), 'Page slug was created on update'); }
protected function getPage($pageSlug, $topicSlug = null) { if (is_null($topicSlug)) { $query = Page::whereSlug($pageSlug); } else { $query = Topic::slug($topicSlug)->firstOrFail()->pages()->whereSlug($pageSlug); } if (Auth::check() === false || Auth::user()->hasRole('admin') === false) { $query->whereActive(true); } $page = $query->get()->first(); if (is_null($page)) { throw (new ModelNotFoundException())->setModel(Page::class); } return $page; }
/** * Updates a entry. * * @param $id * @param array $data * * @return bool|int */ public function updateEntry($id, array $data) { $entry = $this->getEntry($id); $data['active'] = isset($data['active']); if (empty($data['category_id'])) { $data['category_id'] = null; } if (empty($data['topic_id'])) { $data['topic_id'] = null; } if (empty($data['slug'])) { if (!empty($entry->slug) && Page::whereSlug('')->first() !== null) { $data['slug'] = app('slugify')->slugify($data['title']); } } $status = $entry->update($data); return $status; }