getEntityManager(); $shortcutRepo = self::getContainer()->get(CShortcutRepository::class); $forumRepo = self::getContainer()->get(CForumRepository::class); $courseRepo = self::getContainer()->get(CourseRepository::class); $course = $this->createCourse('new'); $teacher = $this->createUser('teacher'); $resource = (new CForum()) ->setTitle('forum') ->setParent($course) ->setCreator($teacher) ->addCourseLink($course) ; $em->persist($resource); $em->flush(); $shortcut = (new CShortcut()) ->setTitle($resource->getResourceName()) ->setShortCutNode($resource->getResourceNode()) ->setCreator($teacher) ->setParent($resource) ->addCourseLink($course) ; $this->assertHasNoEntityViolations($shortcut); $em->persist($shortcut); $em->flush(); $this->assertSame(1, $shortcutRepo->count([])); $this->assertSame($resource->getResourceName(), (string) $shortcut); $this->assertNotNull($shortcut->getUrl()); $this->assertNotNull($shortcut->getTool()); $shortcut = $shortcutRepo->getShortcutFromResource($resource); $this->assertInstanceOf(CShortcut::class, $shortcut); $shortcutRepo->removeShortCut($resource); $this->assertSame(0, $shortcutRepo->count([])); $this->assertSame(1, $forumRepo->count([])); $shortcutRepo->addShortCut($resource, $teacher, $course); $this->assertSame(1, $shortcutRepo->count([])); $course = $this->getCourse($course->getId()); $courseRepo->delete($course); $this->assertSame(0, $shortcutRepo->count([])); $this->assertSame(0, $courseRepo->count([])); } }