/** * Creates a new bookmark and forwards to show action * * @param Tx_PtExtlist_Domain_Model_Bookmark_Bookmark $bookmark */ public function createAction(Tx_PtExtlist_Domain_Model_Bookmark_Bookmark $bookmark) { // Check whether user is allowed to create public bookmarks if ($this->request->hasArgument('isPublic') && $this->request->getArgument('isPublic') == '1') { if ($this->userIsAllowedToCreatePublicBookmarks()) { $bookmark->setIsPublic(true); } else { // TODO show some message, that user is not allowed to create public bookmarks $this->forward('show'); } } // Check, whether user is allowed to create group bookmarks if ($this->request->hasArgument('feGroup') && $this->request->getArgument('feGroup') > 0) { if ($this->userIsAllowedToCreateGroupBookmarks()) { $bookmark->setFeGroup($this->request->getArgument('feGroup')); } else { $this->forward('show'); } } $bookmark->setPid($this->settings['bookmarks']['bookmarksPid']); $this->bookmarkManager->addContentToBookmark($bookmark); $this->bookmarksRepository->add($bookmark); $this->persistenceManager->persistAll(); $this->forward('show'); }
/** * @test */ public function addContentToBookmark() { $bookmarkMock = $this->getMockBuilder('Tx_PtExtlist_Domain_Model_Bookmark_Bookmark')->disableOriginalClone()->getMock(); $sessionPersistenceManagerMock = $this->getMockBuilder('Tx_PtExtbase_State_Session_SessionPersistenceManager')->setMethods(array('getSessionData'))->disableOriginalConstructor()->getMock(); $sessionPersistenceManagerMock->expects($this->once())->method('getSessionData')->will($this->returnValue(array('sessionData'))); $bookmarkStrategyMock = $this->getMockBuilder('Tx_PtExtlist_Domain_Model_Bookmark_BookmarkStrategy')->setMethods(array('addContentToBookmark'))->getMock(); $bookmarkStrategyMock->expects($this->once())->method('addContentToBookmark')->with($bookmarkMock, $this->configurationBuilderMock, array('sessionData')); $this->proxy->_set('sessionPersistenceManager', $sessionPersistenceManagerMock); $this->proxy->_set('bookmarkStrategy', $bookmarkStrategyMock); $this->proxy->_set('configurationBuilder', $this->configurationBuilderMock); $this->proxy->addContentToBookmark($bookmarkMock); }