/** @test */ public function it_should_throw_an_exception_while_trying_to_get_the_page_for_the_specified_language_if_it_does_not_exists() { $this->setExpectedException(\Illuminate\Database\Eloquent\ModelNotFoundException::class); $page = Page::create(); $page->slugs()->create(['lang_code' => $this->lang, 'name' => 'generic page']); $page->getName('it'); }
/** @test */ public function it_should_throw_an_exception_if_the_page_corresponding_to_the_url_does_not_exists_in_the_requested_language() { $this->expectException(ModelNotFoundException::class); $root = Page::create(); $root->slugs()->create(['lang_code' => $this->lang, 'name' => 'root page']); $child = $root->children()->create([]); $child->slugs()->create(['lang_code' => $this->lang, 'name' => 'child page']); $page = Page::match('/root-page/child-page', 'it'); }
/** @test */ public function it_should_update_only_the_slug_of_an_existing_child_page_using_a_unique_slug() { $root = Page::create(); $root->slugs()->create(['lang_code' => $this->lang, 'name' => 'root page']); $child = $root->children()->create([]); $child->slugs()->create(['lang_code' => $this->lang, 'name' => 'child page']); $child2 = $root->children()->create([]); $child2->slugs()->create(['lang_code' => $this->lang, 'name' => 'second child page']); $child2->slug($this->lang)->setAttribute('slug', 'child page')->save(); $this->assertEquals('second child page', $child2->getName($this->lang)); $this->assertEquals('/root-page/child-page-1', $child2->getUrl($this->lang)); }
/** @test */ public function it_should_know_if_a_page_is_sibling_of_another_page_in_the_same_subtree() { $root = Page::create(); $root->slugs()->create(['lang_code' => $this->lang, 'name' => 'root page']); $child = $root->children()->create([]); $child->slugs()->create(['lang_code' => $this->lang, 'name' => 'child page']); $child2 = $root->children()->create([]); $child2->slugs()->create(['lang_code' => $this->lang, 'name' => 'second child page']); $grandchild = $child2->children()->create([]); $grandchild->slugs()->create(['lang_code' => $this->lang, 'name' => 'grandchild page']); $this->assertTrue($child->isSiblingOf($child2)); $this->assertFalse($child->isSiblingOf($grandchild)); }
/** @test */ public function it_should_return_a_nested_collection_representing_the_tree() { $root = Page::create(); $root->slugs()->create(['lang_code' => $this->lang, 'name' => 'root page']); $child = Page::create(); $child->slugs()->create(['lang_code' => $this->lang, 'name' => 'child page']); $child->makeChildOf($root); $grandchild = Page::create(); $grandchild->slugs()->create(['lang_code' => $this->lang, 'name' => 'grandchild page']); $grandchild->makeChildOf($child); $tree = $root->getTree(); $this->assertInstanceOf(\Illuminate\Database\Eloquent\Collection::class, $tree); $this->assertEquals(1, $tree->first()->children()->count()); $this->assertEquals(1, $tree->first()->children()->first()->children()->count()); $this->assertEquals('/root-page/child-page/grandchild-page', $tree->first()->children()->first()->children()->first()->getUrl($this->lang)); }
/** @test */ public function it_should_move_a_deep_nested_page_to_last_child_of_root() { $root = Page::create(); $root->slugs()->create(['lang_code' => $this->lang, 'name' => 'root page']); $child = Page::create(); $child->slugs()->create(['lang_code' => $this->lang, 'name' => 'child page']); $child->makeChildOf($root); $child2 = Page::create([]); $child2->slugs()->create(['lang_code' => $this->lang, 'name' => 'second child page']); $child2->makeChildOf($root); $child3 = Page::create(); $child3->slugs()->create(['lang_code' => $this->lang, 'name' => 'third child page']); $child3->makeChildOf($root); $this->assertTrue($child3->isExactlyBelow($child2)); $child2 = Page::find($child2->id); $child2->makeLastChildOf($root); $child3->reload(); $this->assertTrue($child2->isExactlyBelow($child3)); $this->assertEquals('/root-page/third-child-page', $child3->getUrl($this->lang)); }
/** @test */ public function it_should_use_a_user_function_to_generate_the_suffix_for_an_already_existing_slug() { app('config')->set('page-tree-manager.slug_suffix', function () { return 'random'; }); $root = Page::create(); $root->slugs()->create(['lang_code' => $this->lang, 'name' => 'root page']); $child = $root->children()->create([]); $child->slugs()->create(['lang_code' => $this->lang, 'name' => 'child page']); $child2 = $root->children()->create([]); $child2->slugs()->create(['lang_code' => $this->lang, 'name' => 'child page']); $this->assertEquals('/root-page/child-page', $child->getUrl($this->lang)); $this->assertEquals('/root-page/child-page-random', $child2->getUrl($this->lang)); }