Пример #1
0
 public function run()
 {
     DB::table('categories')->delete();
     MultiScopedCategory::unguard();
     MultiScopedCategory::create(array('id' => 1, 'company_id' => 1, 'language' => 'en', 'name' => 'Root 1', 'lft' => 1, 'rgt' => 10, 'depth' => 0));
     MultiScopedCategory::create(array('id' => 2, 'company_id' => 1, 'language' => 'en', 'name' => 'Child 1', 'lft' => 2, 'rgt' => 3, 'depth' => 1, 'parent_id' => 1));
     MultiScopedCategory::create(array('id' => 3, 'company_id' => 1, 'language' => 'en', 'name' => 'Child 2', 'lft' => 4, 'rgt' => 7, 'depth' => 1, 'parent_id' => 1));
     MultiScopedCategory::create(array('id' => 4, 'company_id' => 1, 'language' => 'en', 'name' => 'Child 2.1', 'lft' => 5, 'rgt' => 6, 'depth' => 2, 'parent_id' => 3));
     MultiScopedCategory::create(array('id' => 5, 'company_id' => 1, 'language' => 'en', 'name' => 'Child 3', 'lft' => 8, 'rgt' => 9, 'depth' => 1, 'parent_id' => 1));
     MultiScopedCategory::create(array('id' => 6, 'company_id' => 2, 'language' => 'en', 'name' => 'Root 2', 'lft' => 1, 'rgt' => 10, 'depth' => 0));
     MultiScopedCategory::create(array('id' => 7, 'company_id' => 2, 'language' => 'en', 'name' => 'Child 4', 'lft' => 2, 'rgt' => 3, 'depth' => 1, 'parent_id' => 6));
     MultiScopedCategory::create(array('id' => 8, 'company_id' => 2, 'language' => 'en', 'name' => 'Child 5', 'lft' => 4, 'rgt' => 7, 'depth' => 1, 'parent_id' => 6));
     MultiScopedCategory::create(array('id' => 9, 'company_id' => 2, 'language' => 'en', 'name' => 'Child 5.1', 'lft' => 5, 'rgt' => 6, 'depth' => 2, 'parent_id' => 8));
     MultiScopedCategory::create(array('id' => 10, 'company_id' => 2, 'language' => 'en', 'name' => 'Child 6', 'lft' => 8, 'rgt' => 9, 'depth' => 1, 'parent_id' => 6));
     MultiScopedCategory::create(array('id' => 11, 'company_id' => 3, 'language' => 'fr', 'name' => 'Racine 1', 'lft' => 1, 'rgt' => 10, 'depth' => 0));
     MultiScopedCategory::create(array('id' => 12, 'company_id' => 3, 'language' => 'fr', 'name' => 'Enfant 1', 'lft' => 2, 'rgt' => 3, 'depth' => 1, 'parent_id' => 11));
     MultiScopedCategory::create(array('id' => 13, 'company_id' => 3, 'language' => 'fr', 'name' => 'Enfant 2', 'lft' => 4, 'rgt' => 7, 'depth' => 1, 'parent_id' => 11));
     MultiScopedCategory::create(array('id' => 14, 'company_id' => 3, 'language' => 'fr', 'name' => 'Enfant 2.1', 'lft' => 5, 'rgt' => 6, 'depth' => 2, 'parent_id' => 13));
     MultiScopedCategory::create(array('id' => 15, 'company_id' => 3, 'language' => 'fr', 'name' => 'Enfant 3', 'lft' => 8, 'rgt' => 9, 'depth' => 1, 'parent_id' => 11));
     MultiScopedCategory::create(array('id' => 16, 'company_id' => 3, 'language' => 'es', 'name' => 'Raiz 1', 'lft' => 1, 'rgt' => 10, 'depth' => 0));
     MultiScopedCategory::create(array('id' => 17, 'company_id' => 3, 'language' => 'es', 'name' => 'Hijo 1', 'lft' => 2, 'rgt' => 3, 'depth' => 1, 'parent_id' => 16));
     MultiScopedCategory::create(array('id' => 18, 'company_id' => 3, 'language' => 'es', 'name' => 'Hijo 2', 'lft' => 4, 'rgt' => 7, 'depth' => 1, 'parent_id' => 16));
     MultiScopedCategory::create(array('id' => 19, 'company_id' => 3, 'language' => 'es', 'name' => 'Hijo 2.1', 'lft' => 5, 'rgt' => 6, 'depth' => 2, 'parent_id' => 18));
     MultiScopedCategory::create(array('id' => 20, 'company_id' => 3, 'language' => 'es', 'name' => 'Hijo 3', 'lft' => 8, 'rgt' => 9, 'depth' => 1, 'parent_id' => 16));
     MultiScopedCategory::reguard();
     if (DB::connection()->getDriverName() === 'pgsql') {
         $tablePrefix = DB::connection()->getTablePrefix();
         $sequenceName = $tablePrefix . 'categories_id_seq';
         DB::connection()->statement('ALTER SEQUENCE ' . $sequenceName . ' RESTART WITH 21');
     }
 }
 public function testRebuildWithMultipleScopes()
 {
     MultiScopedCategory::query()->delete();
     $root1 = MultiScopedCategory::create(array('name' => 'TL1', 'company_id' => 1, 'language' => 'en'));
     $child11 = MultiScopedCategory::create(array('name' => 'C11', 'company_id' => 1, 'language' => 'en'));
     $child12 = MultiScopedCategory::create(array('name' => 'C12', 'company_id' => 1, 'language' => 'en'));
     $child11->makeChildOf($root1);
     $child12->makeChildOf($root1);
     $root2 = MultiScopedCategory::create(array('name' => 'TL2', 'company_id' => 2, 'language' => 'en'));
     $child21 = MultiScopedCategory::create(array('name' => 'C21', 'company_id' => 2, 'language' => 'en'));
     $child22 = MultiScopedCategory::create(array('name' => 'C22', 'company_id' => 2, 'language' => 'en'));
     $child21->makeChildOf($root2);
     $child22->makeChildOf($root2);
     $this->assertTrue(MultiScopedCategory::isValidNestedSet());
     $tree = MultiScopedCategory::query()->orderBy($root1->getKeyName())->get()->all();
     MultiScopedCategory::query()->update(array('lft' => null, 'rgt' => null));
     MultiScopedCategory::rebuild();
     $this->assertTrue(MultiScopedCategory::isValidNestedSet());
     $this->assertEquals($tree, MultiScopedCategory::query()->orderBy($root1->getKeyName())->get()->all());
 }
Пример #3
0
 public function testFullSubtreeMovementsMultiple()
 {
     $this->assertTrue(MultiScopedCategory::isValidNestedSet());
     $root2 = MultiScopedCategory::create(array('name' => 'Raiz 2', 'company_id' => 3, 'language' => 'es'));
     $this->assertTrue(MultiScopedCategory::isValidNestedSet());
     $this->categories('Raiz 1', 'MultiScopedCategory')->makeChildOf($root2);
     $this->assertTrue(MultiScopedCategory::isValidNestedSet());
     $root2->reload();
     $expected = array($this->categories('Raiz 1', 'MultiScopedCategory'), $this->categories('Hijo 1', 'MultiScopedCategory'), $this->categories('Hijo 2', 'MultiScopedCategory'), $this->categories('Hijo 2.1', 'MultiScopedCategory'), $this->categories('Hijo 3', 'MultiScopedCategory'));
     $this->assertEquals($expected, $root2->getDescendants()->all());
 }