function it_delete() { $this->delete(1)->shouldBe(true); $this->finder()->count()->shouldBe(0); if (\BX\News\NewsCategoryLink::finder()->count() > 0) { throw new \RuntimeException('Test fall'); } }
/** * Delete news category * * @param integer $id * @return array */ public function delete($id) { $repo = $this->store()->getRepository('news_category'); $repo->appendLockTables(['tbl_news', 'tbl_news_category_link']); $entity = $this->finder()->filter(['ID' => $id])->get(); if ($entity === false) { $repo->rollback(); throw new \RuntimeException("Error news category is not found."); } $event = $this->store()->getEvent(); if ($this->string()->length($event) > 0) { $event = 'OnPost' . $this->string()->ucwords($event) . 'Delete'; Event::on($event, function ($id) { if (!NewsCategoryLink::deleteAllByCategoryId($id)) { throw new \RuntimeException("Error delete link on news category."); } }); } return $this->store()->delete($repo, $entity); }