/** * @covers RecordsMan\Record::drop */ public function testDrop() { // Drop only test $itemsCount = Item::all()->count(); /** @var Item $item */ $item = Item::load(8); $item->drop(); $this->assertEquals('new test item', $item->title); $this->assertTrue(!$item->id); $this->assertEquals($itemsCount - 1, Item::all()->count()); // Auto-counting test /** @var SubItem $subitem */ $subitem = SubItem::load(1); $parentItem = $subitem->item; $countBefore = $parentItem->subitems_count; $subitem->drop(); $parentItem->reload(); $this->assertEquals($countBefore - 1, $parentItem->subitems_count); // Related item deleting test $this->assertFalse(SubItem::find('item_id = 2')->isEmpty()); $this->assertFalse(Item::find('parent_id = 2')->isEmpty()); Item::load(2)->drop(); $this->assertTrue(SubItem::find('item_id = 2')->isEmpty()); $this->assertTrue(Item::find('parent_id = 2')->isEmpty()); }