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 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()); }