/** * @covers ::setPathAndUpdateDescendants * @covers ::updateDescendants * @covers ::getChildrenPath */ public function testPath() { $root = Category::find(1); $sub = Category::find(6); $leaf1 = Category::find(7); $leaf2 = Category::find(8); $this->assertEquals('1', $root->getChildrenPath()); $this->assertEquals('1/3/6', $sub->getChildrenPath()); $sub->parentId = 2; $sub->setPathAndUpdateDescendants('1/2'); Category::saveArray([$sub, $leaf1, $leaf2]); $this->assertEquals('1/2', $sub->path); $this->assertEquals('1/2/6', $sub->getChildrenPath()); $this->assertEquals('1/2/6', $leaf1->path); $this->assertEquals('1/2/6', $leaf2->path); $sub->parentId = 0; $sub->setPathAndUpdateDescendants(''); Category::saveArray([$sub, $leaf1, $leaf2]); $this->assertEquals('', $sub->path); $this->assertEquals('6', $leaf1->path); $this->assertEquals('6', $leaf2->path); }