/** * @test * @return void */ public function previousNeighbourCanBeFound() { $this->news->_setProperty('uid', 106); $fo = $this->mockedViewHelper->_call('getNeighbours', $this->news, '', 'datetime'); $exp = [0 => ['uid' => 105, 'title' => NULL], 1 => ['uid' => 106, 'title' => NULL]]; $this->assertEquals($exp, $fo); }
/** * Test if default file format works * * @test * @return void */ public function viewHelperReturnsCorrectJs() { $newsItem = new News(); $newsItem->setTitle('fobar'); $language = 'en'; $viewHelper = new DisqusViewHelper(); $settingsService = $this->getAccessibleMock('GeorgRinger\\News\\Service\\SettingsService'); $settingsService->expects($this->any())->method('getSettings')->will($this->returnValue(array('disqusLocale' => $language))); $viewHelper->injectSettingsService($settingsService); $actualResult = $viewHelper->render($newsItem, 'abcdef', 'http://typo3.org/dummy/fobar.html'); $expectedCode = '<script type="text/javascript"> var disqus_shortname = ' . GeneralUtility::quoteJSvalue('abcdef', TRUE) . '; var disqus_identifier = ' . GeneralUtility::quoteJSvalue('news_' . $newUid, TRUE) . '; var disqus_url = ' . GeneralUtility::quoteJSvalue('http://typo3.org/dummy/fobar.html') . '; var disqus_title = ' . GeneralUtility::quoteJSvalue('fobar', TRUE) . '; var disqus_config = function () { this.language = ' . GeneralUtility::quoteJSvalue($language) . '; }; (function() { var dsq = document.createElement("script"); dsq.type = "text/javascript"; dsq.async = true; dsq.src = "//" + disqus_shortname + ".disqus.com/embed.js"; (document.getElementsByTagName("head")[0] || document.getElementsByTagName("body")[0]).appendChild(dsq); })(); </script>'; $this->assertEquals($expectedCode, $actualResult); }
/** * @test * @return void */ public function thenChildIsCalledWithCorrectArguments() { $_GET['tx_news_pi1']['news'] = '789'; $newsItem = new News(); $newsItem->_setProperty('uid', 789); $this->viewHelper->expects($this->once())->method('renderThenChild'); $this->viewHelper->render($newsItem); }
/** * @test * @return void */ public function elseChildIsCalledWithWrongGetArguments() { $_GET['tx_news_pi1']['news'] = 456; $newsItem = new News(); $newsItem->_setProperty('uid', 123); $this->viewHelper->expects($this->once())->method('renderElseChild'); $this->viewHelper->render($newsItem); }
/** * @test */ public function externalUrlIsUsed() { $url = 'http://www.typo3.org'; $result = ['parameter' => $url]; $this->mockedContentObjectRenderer->expects($this->once())->method('typoLink_URL')->with($result); $this->newsItem->setType(2); $this->newsItem->setExternalurl($url); $this->mockedViewHelper->render($this->newsItem); }
/** * Render everything * * @param \GeorgRinger\News\Domain\Model\News $object current news object * @param string $as name of property which holds the text * @param integer $currentPage Selected page * @param string $token Token used to split the text * @return string */ public function render(\GeorgRinger\News\Domain\Model\News $object, $as, $currentPage, $token = '###more###') { $parts = GeneralUtility::trimExplode($token, $object->getBodytext(), true); $numberOfPages = count($parts); if ($numberOfPages === 1) { $result = $parts[0]; } else { $currentPage = (int) $currentPage; if ($currentPage < 1) { $currentPage = 1; } elseif ($currentPage > $numberOfPages) { $currentPage = $numberOfPages; } $tagsToOpen = array(); $tagsToClose = array(); for ($j = 0; $j < $currentPage; $j++) { $chunk = $parts[$j]; while ($chunk = mb_strstr($chunk, '<')) { $tag = $this->extractTag($chunk); $tagStrLen = mb_strlen($tag); if ($this->isOpeningTag($tag)) { if ($j < $currentPage - 1) { $tagsToOpen[] = $tag; } $tagsToClose[] = $tag; } elseif ($this->isClosingTag($tag)) { if ($j < $currentPage - 1) { array_pop($tagsToOpen); } elseif (mb_strpos($parts[$j], $chunk) === 0) { $parts[$j] = mb_substr($parts[$j], $tagStrLen); array_pop($tagsToOpen); } array_pop($tagsToClose); } $chunk = mb_substr($chunk, $tagStrLen); } } $result = join('', $tagsToOpen) . $parts[$currentPage - 1]; while ($tag = array_pop($tagsToClose)) { $result .= $this->getClosingTagByOpeningTag($tag); } } $pages = array(); for ($i = 1; $i <= $numberOfPages; $i++) { $pages[] = array('number' => $i, 'isCurrent' => $i === $currentPage); } $pagination = array('pages' => $pages, 'numberOfPages' => $numberOfPages, 'current' => $currentPage); if ($currentPage < $numberOfPages) { $pagination['nextPage'] = $currentPage + 1; } if ($currentPage > 1) { $pagination['previousPage'] = $currentPage - 1; } $this->templateVariableContainer->add($as, $result); $this->templateVariableContainer->add('pagination', $pagination); return $this->renderChildren(); }
public function render(\GeorgRinger\News\Domain\Model\News $newsItem) { $vars = GeneralUtility::_GET('tx_news_pi1'); if (isset($vars['news']) && (int) $newsItem->getUid() === (int) $vars['news']) { return $this->renderThenChild(); } else { return $this->renderElseChild(); } }
/** * Add the news uid to a global variable to be able to exclude it later * * @param \GeorgRinger\News\Domain\Model\News $newsItem current news item * @return void */ public function render(\GeorgRinger\News\Domain\Model\News $newsItem) { $uid = $newsItem->getUid(); if (empty($GLOBALS['EXT']['news']['alreadyDisplayed'])) { $GLOBALS['EXT']['news']['alreadyDisplayed'] = array(); } $GLOBALS['EXT']['news']['alreadyDisplayed'][$uid] = $uid; // Add localized uid as well $originalUid = (int) $newsItem->_getProperty('_localizedUid'); if ($originalUid > 0) { $GLOBALS['EXT']['news']['alreadyDisplayed'][$originalUid] = $originalUid; } }
/** * Output different objects * * @param \GeorgRinger\News\Domain\Model\News $newsItem current newsitem * @param string $as output variable * @param string $className custom class which handles the new objects * @param string $extendedTable table which is extended * @return string output */ public function render(\GeorgRinger\News\Domain\Model\News $newsItem, $as, $className, $extendedTable = 'tx_news_domain_model_news') { $rawRecord = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('*', $extendedTable, 'uid=' . (int) $newsItem->getUid()); $rawRecord = $GLOBALS['TSFE']->sys_page->getRecordOverlay($extendedTable, $rawRecord, $GLOBALS['TSFE']->sys_language_content, $GLOBALS['TSFE']->sys_language_contentOL); $objectManager = GeneralUtility::makeInstance(ObjectManager::class); /* @var $dataMapper DataMapper */ $dataMapper = $objectManager->get(DataMapper::class); $records = $dataMapper->map($className, array($rawRecord)); $record = array_shift($records); $this->templateVariableContainer->add($as, $record); $output = $this->renderChildren(); $this->templateVariableContainer->remove($as); return $output; }
/** * @param array $importData * @param \GeorgRinger\News\Domain\Model\News $news * @return void */ public function postHydrate(array $importData, $news) { /** @var \GeorgRinger\Eventnews\Domain\Model\News $news */ if (is_array($importData['_dynamicData'])) { if (isset($importData['_dynamicData']['location'])) { $news->setLocationSimple(trim($importData['_dynamicData']['location'])); } if (!empty($importData['_dynamicData']['datetime_end'])) { $date = new \DateTime(); $date->setTimestamp($importData['_dynamicData']['datetime_end']); $news->setEventEnd($date); } } }
/** * Test if default file format works * * @test * @return void */ public function viewHelperReturnsCorrectJavaScriptLink() { $viewHelper = new MultiEditLinkViewHelper(); $newsItem1 = new News(); $newsItem1->setTitle('Item 1'); $newsItem1->_setProperty('uid', 3); $newsItem2 = new News(); $newsItem2->setTitle('Item 2'); $newsItem2->_setProperty('uid', 9); $newsItems = new \SplObjectStorage(); $newsItems->attach($newsItem1); $newsItems->attach($newsItem2); $columns = 'title,description'; $actualResult = $viewHelper->render($newsItems, $columns); $content = 'window.location.href=\'alt_doc.php?returnUrl=\'+T3_THIS_LOCATION+\'&edit[tx_news_domain_model_news][' . '3,9' . ']=edit&columnsOnly=title,description&disHelp=1\';return false;'; $this->assertEquals($content, $actualResult); }
/** * Render disqus thread * * @param \GeorgRinger\News\Domain\Model\News $newsItem news item * @param string $shortName shortname * @param string $link link * @return string */ public function render(\GeorgRinger\News\Domain\Model\News $newsItem, $shortName, $link) { $tsSettings = $this->pluginSettingsService->getSettings(); $code = '<script type="text/javascript"> var disqus_shortname = ' . GeneralUtility::quoteJSvalue($shortName, TRUE) . '; var disqus_identifier = \'news_' . $newsItem->getUid() . '\'; var disqus_url = ' . GeneralUtility::quoteJSvalue($link, TRUE) . '; var disqus_title = ' . GeneralUtility::quoteJSvalue($newsItem->getTitle(), TRUE) . '; var disqus_config = function () { this.language = ' . GeneralUtility::quoteJSvalue($tsSettings['disqusLocale']) . '; }; (function() { var dsq = document.createElement("script"); dsq.type = "text/javascript"; dsq.async = true; dsq.src = "http://" + disqus_shortname + ".disqus.com/embed.js"; (document.getElementsByTagName("head")[0] || document.getElementsByTagName("body")[0]).appendChild(dsq); })(); </script>'; return $code; }
/** * @test * @return void */ public function newsIsAddedToExcludedList() { $viewHelper = new ExcludeDisplayedNewsViewHelper(); $this->assertEquals($GLOBALS['EXT']['news']['alreadyDisplayed'], NULL); $newsItem1 = new News(); $newsItem1->_setProperty('uid', '123'); $viewHelper->render($newsItem1); $this->assertEquals($GLOBALS['EXT']['news']['alreadyDisplayed'], array('123' => '123')); $newsItem1 = new News(); $newsItem1->_setProperty('uid', '123'); $this->assertEquals($GLOBALS['EXT']['news']['alreadyDisplayed'], array('123' => '123')); $newsItem2 = new News(); $newsItem2->_setProperty('uid', '12'); $viewHelper->render($newsItem2); $this->assertEquals($GLOBALS['EXT']['news']['alreadyDisplayed'], array('123' => '123', '12' => '12')); $newsItem3 = new News(); $newsItem3->_setProperty('uid', '12'); $newsItem3->_setProperty('_localizedUid', '456'); $viewHelper->render($newsItem3); $this->assertEquals($GLOBALS['EXT']['news']['alreadyDisplayed'], array('123' => '123', '12' => '12', '456' => '456')); }
/** * @test */ public function checkPidOfNewsRecordWorks() { $mockedSignalDispatcher = $this->getAccessibleMock('\\TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher', ['dummy']); $mockedController = $this->getAccessibleMock('GeorgRinger\\News\\Controller\\NewsController', ['dummy']); $mockedController->_set('signalSlotDispatcher', $mockedSignalDispatcher); $news = new News(); // No startingpoint $mockedController->_set('settings', ['startingpoint' => '']); $news->setPid(45); $this->assertEquals($news, $mockedController->_call('checkPidOfNewsRecord', $news)); // startingpoint defined $mockedController->_set('settings', ['startingpoint' => '1,2,123,456']); $news->setPid(123); $this->assertEquals($news, $mockedController->_call('checkPidOfNewsRecord', $news)); // startingpoint is different $mockedController->_set('settings', ['startingpoint' => '123,456']); $news->setPid(45); $this->assertEquals(NULL, $mockedController->_call('checkPidOfNewsRecord', $news)); }
/** * Handles the blogpost visits * * @param \GeorgRinger\News\Domain\Model\News $news * @return void */ public function detailActionSlot(\GeorgRinger\News\Domain\Model\News $news = null) { $sessionKey = $this->extensionName . '_visits_news'; $excludedIps = $this->settings['excludedIpsForVisits']; $this->isExcludedIp = in_array($GLOBALS['_SERVER']['REMOTE_ADDR'], GeneralUtility::trimExplode(',', $excludedIps, true)); $viewedNewsArray = $this->feSession->get($sessionKey); // Increases view count, updates news object, remembers object UID in session for unique views if ((!is_array($viewedNewsArray) || is_array($viewedNewsArray) && !in_array($news->getUid(), $viewedNewsArray)) && !$this->isExcludedIp) { $viewedNewsArray[] = $news->getUid(); /** @var \Ecom\EcomToolbox\Domain\Model\News $news */ $news->setEcomBlogpostVisits($news->getEcomBlogpostVisits() + 1); $this->newsRepository->update($news); $this->feSession->store($sessionKey, $viewedNewsArray); } }
/** * @param \GeorgRinger\News\Domain\Model\News $news * @param integer $currentPage */ public function detailActionSlot($news, $currentPage) { $plenigoFields = $this->getPlenigoFields($news->getUid()); // \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($plenigoFields); if (empty($plenigoFields)) { $GLOBALS['TSFE']->pageUnavailableAndExit("Plenigo Extension not configured yet or Error reading Data", 'HTTP/1.1 500 Internal Server Error'); throw new \Exception("Plenigo Extension not configured yet or Error reading Data from News-Table"); return true; } $this->plenigoSettings = $this->getPlenigoSettings(); if (is_null($this->plenigoSettings)) { $GLOBALS['TSFE']->pageUnavailableAndExit("Plenigo Extension not configured yet or Error reading Data", 'HTTP/1.1 500 Internal Server Error'); } $hasUserBought = null; // $secret = $plenigoSetting->getCompanyPrivateKey(); // $companyId = $plenigoSetting->getCompanyID(); // $isTestMode = $plenigoSetting->isTestMode(); $this->connect(); // is there a category if ($plenigoFields['plenigo_category']) { $category = $this->getPlenigoCategory($plenigoFields['plenigo_category']); $productID = 'item-' . $news->getUid(); // is it bought already? $hasUserBought = \plenigo\services\UserService::hasUserBought($productID); if (!$hasUserBought) { //creating the product ($productId, $productTitle, $price, $currency) try { // new custom ProductID (https://github.com/plenigo/plenigo_php_sdk/wiki/Checkout#other-products) $product = new \plenigo\models\ProductBase($productID, $news->getTitle()); $product->setCategoryId($category['plenigo_i_d']); } catch (\Exception $e) { $GLOBALS['TSFE']->pageUnavailableAndExit("Could not create Plenigo-Product", 'HTTP/1.1 500 Internal Server Error'); } } } // its not bought yet, but we have an associated product if (!$hasUserBought && $plenigoFields['plenigo_product']) { $productData = $this->getPlenigoProduct($plenigoFields['plenigo_product']); // ist it bought? $hasUserBought = \plenigo\services\UserService::hasUserBought($productData['product_i_d']); if (!$hasUserBought) { // https://github.com/plenigo/plenigo_php_sdk/wiki/Checkout#plenigo-managed-product try { $product = new \plenigo\models\ProductBase($productData['product_i_d']); // \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($productData); } catch (\Exception $e) { $GLOBALS['TSFE']->pageUnavailableAndExit("Could not create Plenigo-Product", 'HTTP/1.1 500 Internal Server Error'); } } } if (FALSE === $hasUserBought) { // inject our js-sdk into html-header $this->buildHeader(); if (!is_object($product)) { $GLOBALS['TSFE']->pageUnavailableAndExit("Product is not bought, but no productidentity given", 'HTTP/1.1 500 Internal Server Error'); throw new \Exception("no Product given!"); } $curtain = new Curtain($this->plenigoSettings); $checkout = new \plenigo\builders\CheckoutSnippetBuilder($product); $builder = new \plenigo\builders\LoginSnippetBuilder(); //This will generate the login snippet of the following format: //plenigo.login(); $curtain->setLoginButton($builder->build()); $curtain->setCheckoutCode($checkout->build()); $news->setBodytext($this->getPaymentInfo($news->getBodytext()) . $curtain->getCode()); } // else displaying normal news }
/** * Gets detailPid from categories of the given news item. First will be return. * * @param array $settings * @param \GeorgRinger\News\Domain\Model\News $newsItem * @return int */ protected function getDetailPidFromCategories($settings, $newsItem) { $detailPid = 0; if ($newsItem->getCategories()) { foreach ($newsItem->getCategories() as $category) { if ($detailPid = (int) $category->getSinglePid()) { break; } } } return $detailPid; }
/** * @test */ public function falMediaPreviewsAreReturned() { $news = new News(); $mockedElement1 = $this->getAccessibleMock('GeorgRinger\\News\\Domain\\Model\\FileReference', array('getProperty')); $mockedElement1->_set('uid', 1); $mockedElement1->_set('showinpreview', TRUE); $mockedElement1->expects($this->any())->method('getProperty')->will($this->returnValue(TRUE)); $mediaItem1 = new FileReference(); $mediaItem1->_setProperty('originalResource', $mockedElement1); $news->addFalMedia($mediaItem1); $mockedElement2 = $this->getAccessibleMock('GeorgRinger\\News\\Domain\\Model\\FileReference', array('getProperty')); $mockedElement2->_set('uid', 2); $mockedElement2->_set('showinpreview', TRUE); $mockedElement2->expects($this->any())->method('getProperty')->will($this->returnValue(FALSE)); $mediaItem2 = new FileReference(); $mediaItem2->_setProperty('originalResource', $mockedElement2); $news->addFalMedia($mediaItem2); $mockedElement3 = $this->getAccessibleMock('GeorgRinger\\News\\Domain\\Model\\FileReference', array('getProperty')); $mockedElement3->_set('uid', 3); $mockedElement3->_set('showinpreview', TRUE); $mockedElement3->expects($this->any())->method('getProperty')->will($this->returnValue(TRUE)); $mediaItem3 = new FileReference(); $mediaItem3->_setProperty('originalResource', $mockedElement3); $news->addFalMedia($mediaItem3); $this->assertEquals(2, count($news->getFalMediaPreviews())); $this->assertEquals(1, count($news->getFalMediaNonPreviews())); $this->assertEquals(3, count($news->getFalMedia())); }
/** * Get an existing related link object * * @param \GeorgRinger\News\Domain\Model\News $news * @param string $uri * @return bool|Link */ protected function getRelatedLinkIfAlreadyExists(\GeorgRinger\News\Domain\Model\News $news, $uri) { $result = FALSE; $links = $news->getRelatedLinks(); if (!empty($links) && $links->count() !== 0) { foreach ($links as $link) { if ($link->getUri() === $uri) { $result = $link; break; } } } return $result; }
/** * @test * @return void */ public function getDetailPidFromCategoriesReturnsCorrectValue() { $viewHelper = $this->getAccessibleMock('GeorgRinger\\News\\ViewHelpers\\LinkViewHelper', ['dummy']); $newsItem = new \GeorgRinger\News\Domain\Model\News(); $categories = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); $category1 = new Category(); $categories->attach($category1); $category2 = new Category(); $category2->setSinglePid('123'); $categories->attach($category2); $category3 = new Category(); $category3->setSinglePid('456'); $categories->attach($category3); $newsItem->setCategories($categories); $result = $viewHelper->_call('getDetailPidFromCategories', [], $newsItem); $this->assertEquals(123, $result); }
/** * @param \GeorgRinger\News\Domain\Model\News $news * @param $pidList * @param $sortField * @return array */ protected function getNeighbours(\GeorgRinger\News\Domain\Model\News $news, $pidList, $sortField) { $pidList = empty($pidList) ? $news->getPid() : $pidList; $select = 'SELECT tx_news_domain_model_news.uid,tx_news_domain_model_news.title '; $from = 'FROM tx_news_domain_model_news'; $whereClause = 'tx_news_domain_model_news.pid IN(' . $this->databaseConnection->cleanIntList($pidList) . ') ' . $this->getEnableFieldsWhereClauseForTable(); $query = $select . $from . ' WHERE ' . $whereClause . ' && ' . $sortField . ' >= (SELECT MAX(' . $sortField . ') ' . $from . ' WHERE ' . $whereClause . ' AND ' . $sortField . ' < (SELECT ' . $sortField . ' FROM tx_news_domain_model_news WHERE tx_news_domain_model_news.uid = ' . $news->getUid() . ')) ORDER BY ' . $sortField . ' ASC LIMIT 3'; $query2 = $select . $from . ' WHERE ' . $whereClause . ' AND ' . $sortField . '= (SELECT MIN(' . $sortField . ') FROM tx_news_domain_model_news WHERE ' . $whereClause . ' AND ' . $sortField . ' > (SELECT ' . $sortField . ' FROM tx_news_domain_model_news WHERE tx_news_domain_model_news.uid = ' . $news->getUid() . ')) '; $res = $this->databaseConnection->sql_query($query); $out = array(); while ($row = $this->databaseConnection->sql_fetch_assoc($res)) { $out[] = $row; } $this->databaseConnection->sql_free_result($res); if (count($out) === 0) { $res = $this->databaseConnection->sql_query($query2); while ($row = $this->databaseConnection->sql_fetch_assoc($res)) { $out[] = $row; } $this->databaseConnection->sql_free_result($res); return $out; } return $out; }
/** * Checks if the news pid could be found in the startingpoint settings of the detail plugin and * if the pid could not be found it return NULL instead of the news object. * * @param \GeorgRinger\News\Domain\Model\News $news * @return NULL|\GeorgRinger\News\Domain\Model\News */ protected function checkPidOfNewsRecord(\GeorgRinger\News\Domain\Model\News $news) { $allowedStoragePages = GeneralUtility::trimExplode(',', Page::extendPidListByChildren($this->settings['startingpoint'], $this->settings['recursive']), true); if (count($allowedStoragePages) > 0 && !in_array($news->getPid(), $allowedStoragePages)) { $this->signalSlotDispatcher->dispatch(__CLASS__, 'checkPidOfNewsRecordFailedInDetailAction', ['news' => $news, 'newsController' => $this]); $news = null; } return $news; }