Exemplo n.º 1
0
 public function testChildrenRelationObeysCustomOrdering()
 {
     with(new OrderedCategorySeeder())->run();
     $children = OrderedCategory::find(1)->children()->get()->all();
     $expected = array(OrderedCategory::find(5), OrderedCategory::find(2), OrderedCategory::find(3));
     $this->assertEquals($expected, $children);
 }
Exemplo n.º 2
0
 public function run()
 {
     DB::table('categories')->delete();
     OrderedCategory::unguard();
     OrderedCategory::create(array('id' => 1, 'name' => 'Root Z', 'lft' => 1, 'rgt' => 10, 'depth' => 0));
     OrderedCategory::create(array('id' => 2, 'name' => 'Child C', 'lft' => 2, 'rgt' => 3, 'depth' => 1, 'parent_id' => 1));
     OrderedCategory::create(array('id' => 3, 'name' => 'Child G', 'lft' => 4, 'rgt' => 7, 'depth' => 1, 'parent_id' => 1));
     OrderedCategory::create(array('id' => 4, 'name' => 'Child G.1', 'lft' => 5, 'rgt' => 6, 'depth' => 2, 'parent_id' => 3));
     OrderedCategory::create(array('id' => 5, 'name' => 'Child A', 'lft' => 8, 'rgt' => 9, 'depth' => 1, 'parent_id' => 1));
     OrderedCategory::create(array('id' => 6, 'name' => 'Root A', 'lft' => 11, 'rgt' => 12, 'depth' => 0));
     OrderedCategory::reguard();
     if (DB::connection()->getDriverName() === 'pgsql') {
         $tablePrefix = DB::connection()->getTablePrefix();
         $sequenceName = $tablePrefix . 'categories_id_seq';
         DB::connection()->statement('ALTER SEQUENCE ' . $sequenceName . ' RESTART WITH 7');
     }
 }
Exemplo n.º 3
0
 public function testIsScoped()
 {
     $category = new Category();
     $this->assertFalse($category->isScoped());
     $category = new ScopedCategory();
     $this->assertTrue($category->isScoped());
     $category = new MultiScopedCategory();
     $this->assertTrue($category->isScoped());
     $category = new OrderedCategory();
     $this->assertFalse($category->isScoped());
 }
Exemplo n.º 4
0
 public function testToHierarchyNestsCorrectlyWithOrder()
 {
     with(new OrderedCategorySeeder())->run();
     $expectedWhole = array('Root A' => null, 'Root Z' => array('Child A' => null, 'Child C' => null, 'Child G' => array('Child G.1' => null)));
     $this->assertArraysAreEqual($expectedWhole, hmap(OrderedCategory::all()->toHierarchy()->toArray()));
     $expectedSubtreeZ = array('Root Z' => array('Child A' => null, 'Child C' => null, 'Child G' => array('Child G.1' => null)));
     $this->assertArraysAreEqual($expectedSubtreeZ, hmap($this->categories('Root Z', 'OrderedCategory')->getDescendantsAndSelf()->toHierarchy()->toArray()));
 }
 public function testNewNestedSetQueryIsOrderedByCustom()
 {
     $category = new OrderedCategory();
     $builder = $category->newNestedSetQuery();
     $query = $builder->getQuery();
     $this->assertNull($query->wheres);
     $this->assertNotEmpty($query->orders);
     $this->assertEquals('name', $category->getOrderColumnName());
     $this->assertEquals('categories.name', $category->getQualifiedOrderColumnName());
     $this->assertEquals($category->getQualifiedOrderColumnName(), $query->orders[0]['column']);
 }