Ejemplo n.º 1
0
 /**
  * Returns banners for the given parameters if given Hmac validation succeeds
  *
  * @param string $categories
  * @param string $startingPoint
  * @param string $displayMode
  * @param int $currentPageUid
  * @param string $hmac
  * @return string
  */
 public function getBannersAction($categories = '', $startingPoint = '', $displayMode = 'all', $currentPageUid = 0, $hmac = '')
 {
     $compareString = $currentPageUid . $categories . $startingPoint . $displayMode;
     if ($this->hashService->validateHmac($compareString, $hmac)) {
         /** @var \DERHANSEN\SfBanners\Domain\Model\BannerDemand $demand */
         $demand = $this->objectManager->get('DERHANSEN\\SfBanners\\Domain\\Model\\BannerDemand');
         $demand->setCategories($categories);
         $demand->setStartingPoint($startingPoint);
         $demand->setDisplayMode($displayMode);
         $demand->setCurrentPageUid($currentPageUid);
         /* Get banners */
         $banners = $this->bannerRepository->findDemanded($demand);
         /* Update Impressions */
         $this->bannerRepository->updateImpressions($banners);
         /* Collect identifier based on uids for all banners */
         $ident = $GLOBALS['TSFE']->id . $GLOBALS['TSFE']->sys_language_uid;
         foreach ($banners as $banner) {
             $ident .= $banner->getUid();
         }
         $ret = $this->cacheInstance->get(sha1($ident));
         if ($ret === false || $ret === null) {
             $this->view->assign('banners', $banners);
             $this->view->assign('settings', $this->settings);
             $ret = $this->view->render();
             // Save value in cache
             $this->cacheInstance->set(sha1($ident), $ret, array('sf_banners'), $this->settings['cacheLifetime']);
         }
     } else {
         $ret = LocalizationUtility::translate('wrong_hmac', 'SfBanners');
     }
     return $ret;
 }
Ejemplo n.º 2
0
 /**
  * Test if records are not returned, if max clicks and/or max impressions reached
  *
  * @test
  * @return void
  */
 public function findRecordsWithMaxImpressionsAndMaxClicksTest()
 {
     /** @var \DERHANSEN\SfBanners\Domain\Model\BannerDemand $demand */
     $demand = $this->objectManager->get('DERHANSEN\\SfBanners\\Domain\\Model\\BannerDemand');
     $pid = 102;
     /* Set starting point */
     $demand->setStartingPoint($pid);
     /* Verify, that 1 record are returned */
     $this->assertEquals(1, (int) $this->bannerRepository->findDemanded($demand)->count());
 }
Ejemplo n.º 3
0
 /**
  * Test if no CSS link is returned if no banners given
  *
  * @test
  * @return void
  */
 public function getAdditionalCssLinkReturnsLinkTest()
 {
     $pid = 115;
     $this->testingFramework->createRecord('tx_sfbanners_domain_model_banner', array('pid' => $pid, 'margin_left' => 10, 'margin_right' => 10, 'sorting' => 1));
     /* Get banner from Repository */
     $this->demand->setStartingPoint($pid);
     $banners = $this->bannerRepository->findDemanded($this->demand);
     $result = $this->bannerService->getAdditionalCssLink($banners);
     $this->assertContains('<link rel="stylesheet" type="text/css" href=', $result);
     $this->assertContains('typo3temp/stylesheet_', $result);
     $this->assertContains('.css', $result);
     $this->assertContains('media="all" />', $result);
 }
Ejemplo n.º 4
0
 /**
  * Test if records are not returned, if max clicks and/or max impressions reached
  *
  * @test
  * @return void
  */
 public function findRecordsWithMaxImpressionsAndMaxClicksTest()
 {
     /** @var \DERHANSEN\SfBanners\Domain\Model\BannerDemand $demand  */
     $demand = $this->objectManager->get('DERHANSEN\\SfBanners\\Domain\\Model\\BannerDemand');
     $pid = 101;
     /* Create some banners */
     $this->testingFramework->createRecord('tx_sfbanners_domain_model_banner', array('pid' => $pid, 'impressions_max' => 0, 'impressions' => 10, 'clicks' => 0, 'clicks_max' => 10));
     $this->testingFramework->createRecord('tx_sfbanners_domain_model_banner', array('pid' => $pid, 'impressions_max' => 10, 'impressions' => 10, 'clicks' => 0, 'clicks_max' => 10));
     $this->testingFramework->createRecord('tx_sfbanners_domain_model_banner', array('pid' => $pid, 'impressions_max' => 0, 'impressions' => 10, 'clicks' => 10, 'clicks_max' => 10));
     $this->testingFramework->createRecord('tx_sfbanners_domain_model_banner', array('pid' => $pid, 'impressions_max' => 10, 'impressions' => 10, 'clicks' => 10, 'clicks_max' => 10));
     /* Set starting point */
     $demand->setStartingPoint($pid);
     /* Verify, that 2 records are returned */
     $this->assertEquals(1, (int) $this->fixture->findDemanded($demand)->count());
 }