Exemplo n.º 1
0
 public function run()
 {
     DB::table('categories')->delete();
     ScopedCategory::unguard();
     ScopedCategory::create(array('id' => 1, 'company_id' => 1, 'name' => 'Root 1', 'lft' => 1, 'rgt' => 10, 'depth' => 0));
     ScopedCategory::create(array('id' => 2, 'company_id' => 1, 'name' => 'Child 1', 'lft' => 2, 'rgt' => 3, 'depth' => 1, 'parent_id' => 1));
     ScopedCategory::create(array('id' => 3, 'company_id' => 1, 'name' => 'Child 2', 'lft' => 4, 'rgt' => 7, 'depth' => 1, 'parent_id' => 1));
     ScopedCategory::create(array('id' => 4, 'company_id' => 1, 'name' => 'Child 2.1', 'lft' => 5, 'rgt' => 6, 'depth' => 2, 'parent_id' => 3));
     ScopedCategory::create(array('id' => 5, 'company_id' => 1, 'name' => 'Child 3', 'lft' => 8, 'rgt' => 9, 'depth' => 1, 'parent_id' => 1));
     ScopedCategory::create(array('id' => 6, 'company_id' => 2, 'name' => 'Root 2', 'lft' => 1, 'rgt' => 10, 'depth' => 0));
     ScopedCategory::create(array('id' => 7, 'company_id' => 2, 'name' => 'Child 4', 'lft' => 2, 'rgt' => 3, 'depth' => 1, 'parent_id' => 6));
     ScopedCategory::create(array('id' => 8, 'company_id' => 2, 'name' => 'Child 5', 'lft' => 4, 'rgt' => 7, 'depth' => 1, 'parent_id' => 6));
     ScopedCategory::create(array('id' => 9, 'company_id' => 2, 'name' => 'Child 5.1', 'lft' => 5, 'rgt' => 6, 'depth' => 2, 'parent_id' => 8));
     ScopedCategory::create(array('id' => 10, 'company_id' => 2, 'name' => 'Child 6', 'lft' => 8, 'rgt' => 9, 'depth' => 1, 'parent_id' => 6));
     ScopedCategory::reguard();
     if (DB::connection()->getDriverName() === 'pgsql') {
         $tablePrefix = DB::connection()->getTablePrefix();
         $sequenceName = $tablePrefix . 'categories_id_seq';
         DB::connection()->statement('ALTER SEQUENCE ' . $sequenceName . ' RESTART WITH 11');
     }
 }
 public function testNewNestedSetQueryIncludesScopedColumns()
 {
     $category = new Category();
     $simpleQuery = $category->newNestedSetQuery()->getQuery();
     $this->assertNull($simpleQuery->wheres);
     $scopedCategory = new ScopedCategory();
     $scopedQuery = $scopedCategory->newNestedSetQuery()->getQuery();
     $this->assertCount(1, $scopedQuery->wheres);
     $this->assertEquals($scopedCategory->getScopedColumns(), array_map(function ($elem) {
         return $elem['column'];
     }, $scopedQuery->wheres));
     $multiScopedCategory = new MultiScopedCategory();
     $multiScopedQuery = $multiScopedCategory->newNestedSetQuery()->getQuery();
     $this->assertCount(2, $multiScopedQuery->wheres);
     $this->assertEquals($multiScopedCategory->getScopedColumns(), array_map(function ($elem) {
         return $elem['column'];
     }, $multiScopedQuery->wheres));
 }
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 testFullSubtreeMovements()
 {
     with(new ScopedCategorySeeder())->run();
     $this->assertTrue(ScopedCategory::isValidNestedSet());
     $root3 = ScopedCategory::create(array('name' => 'Root 3', 'company_id' => 2));
     $this->assertTrue(ScopedCategory::isValidNestedSet());
     $this->categories('Root 2', 'ScopedCategory')->makeChildOf($root3);
     $this->assertTrue(ScopedCategory::isValidNestedSet());
     $root3->reload();
     $expected = array($this->categories('Root 2', 'ScopedCategory'), $this->categories('Child 4', 'ScopedCategory'), $this->categories('Child 5', 'ScopedCategory'), $this->categories('Child 5.1', 'ScopedCategory'), $this->categories('Child 6', 'ScopedCategory'));
     $this->assertEquals($expected, $root3->getDescendants()->all());
 }