コード例 #1
0
ファイル: RouteListenerTest.php プロジェクト: reliv/Rcm
 /**
  * Setup for tests
  *
  * @return void
  */
 public function setup()
 {
     $this->domains = ['reliv.com' => ['domain' => 'local.reliv.com', 'primaryDomain' => null, 'languageId' => 'eng', 'siteId' => 1, 'countryId' => 'USA'], 'www.reliv.com' => ['domain' => 'local.reliv.com', 'primaryDomain' => 'reliv.com', 'languageId' => 'eng', 'siteId' => 1, 'countryId' => 'USA']];
     $this->redirects = ['/requestOne' => ['requestUrl' => '/requestOne', 'redirectUrl' => 'reliv.com/redirectOne'], '/requestTwo' => ['requestUrl' => '/requestTwo', 'redirectUrl' => 'reliv.com/redirectTwo']];
     $config = [];
     $this->currentSite = new Site();
     $this->currentSite->setSiteId(1);
     $this->currentSite->setStatus(Site::STATUS_ACTIVE);
     $domain = new Domain();
     $domain->setDomainId(1);
     $domain->setDomainName('reliv.com');
     $this->currentSite->setDomain($domain);
     $this->redirectRepo = $this->getMockBuilder('\\Rcm\\Repository\\Redirect')->disableOriginalConstructor()->getMock();
     $map = [];
     foreach ($this->redirects as $key => $redirect) {
         $redirectEntity = new Redirect();
         $redirectEntity->setRedirectUrl($redirect['requestUrl']);
         $redirectEntity->setRedirectUrl($redirect['redirectUrl']);
         $map[] = [$key, $this->currentSite->getSiteId(), $redirectEntity];
     }
     $this->redirectRepo->expects($this->any())->method('getRedirect')->will($this->returnValueMap($map));
     //////////////
     $this->siteServiceMock = $this->getMockBuilder(SiteService::class)->disableOriginalConstructor()->getMock();
     $this->siteServiceMock->expects($this->any())->method('getCurrentSite')->will($this->returnValue($this->currentSite));
     $this->siteServiceMock->expects($this->any())->method('isConsoleRequest')->will($this->returnValue(false));
     $this->redirectServiceMock = $this->getMockBuilder(RedirectService::class)->disableOriginalConstructor()->getMock();
     $this->domainRedirectServiceMock = $this->getMockBuilder(DomainRedirectService::class)->disableOriginalConstructor()->getMock();
     $this->localeServiceMock = $this->getMockBuilder(LocaleService::class)->disableOriginalConstructor()->getMock();
     $this->routeListener = new RouteListener($this->siteServiceMock, $this->redirectServiceMock, $this->domainRedirectServiceMock, $this->localeServiceMock);
 }
コード例 #2
0
ファイル: Redirect.php プロジェクト: reliv/rcm
 /**
  * save
  *
  * @param RedirectEntity $redirect
  * @return void
  */
 public function save(\Rcm\Entity\Redirect $redirect)
 {
     /** @var \Rcm\Entity\Redirect $result */
     $result = $this->findOneBy(['requestUrl' => $redirect->getRequestUrl(), 'redirectUrl' => $redirect->getRedirectUrl(), 'siteId' => $redirect->getSiteId()]);
     if (!empty($result) && $result->getRedirectId() !== $redirect->getRedirectId()) {
         throw new RedirectException('Duplicate redirects not allowed');
     }
     if ($redirect->getSiteId() !== null) {
         $siteRepo = $this->getEntityManager()->getRepository('Rcm\\Entity\\Site');
         $site = $siteRepo->find($redirect->getSiteId());
         if (empty($site)) {
             throw new RedirectException('Valid site required');
         }
         $redirect->setSite($site);
     }
     $this->getEntityManager()->persist($redirect);
     $this->getEntityManager()->flush($redirect);
 }
コード例 #3
0
ファイル: RouteListenerTest.php プロジェクト: reliv/rcm
 /**
  * Setup for tests
  *
  * @return void
  */
 public function setup()
 {
     $this->domains = ['reliv.com' => ['domain' => 'local.reliv.com', 'primaryDomain' => null, 'languageId' => 'eng', 'siteId' => 1, 'countryId' => 'USA'], 'www.reliv.com' => ['domain' => 'local.reliv.com', 'primaryDomain' => 'reliv.com', 'languageId' => 'eng', 'siteId' => 1, 'countryId' => 'USA']];
     $this->redirects = ['/requestOne' => ['requestUrl' => '/requestOne', 'redirectUrl' => 'reliv.com/redirectOne'], '/requestTwo' => ['requestUrl' => '/requestTwo', 'redirectUrl' => 'reliv.com/redirectTwo']];
     $config = [];
     $this->currentSite = new Site();
     $this->currentSite->setSiteId(1);
     $this->currentSite->setStatus('A');
     $domain = new Domain();
     $domain->setDomainId(1);
     $domain->setDomainName('reliv.com');
     $this->currentSite->setDomain($domain);
     $this->redirectRepo = $this->getMockBuilder('\\Rcm\\Repository\\Redirect')->disableOriginalConstructor()->getMock();
     $map = [];
     foreach ($this->redirects as $key => $redirect) {
         $redirectEntity = new Redirect();
         $redirectEntity->setRedirectUrl($redirect['requestUrl']);
         $redirectEntity->setRedirectUrl($redirect['redirectUrl']);
         $map[] = [$key, $this->currentSite->getSiteId(), $redirectEntity];
     }
     $this->redirectRepo->expects($this->any())->method('getRedirect')->will($this->returnValueMap($map));
     $this->routeListener = new RouteListener($this->currentSite, $this->redirectRepo, new \Zend\Validator\Ip(), $config);
 }
コード例 #4
0
ファイル: RedirectTest.php プロジェクト: reliv/rcm
 public function testToArray()
 {
     $unit = new Redirect();
     $site = new Site();
     $domain = new Domain();
     $site->setSiteId(28);
     $domain->setDomainName('test.com');
     $site->setDomain($domain);
     $unit->setSite($site);
     $result = $unit->toArray();
     $this->assertEquals('test.com', $result['domain']);
     $this->assertEquals(28, $result['siteId']);
 }
コード例 #5
0
 /**
  * create
  *
  * @param mixed $data
  * @return \Reliv\RcmApiLib\Http\ApiResponse
  */
 public function create($data)
 {
     if (!$this->rcmIsAllowed('sites', 'admin')) {
         return $this->getApiResponse(null, 401);
     }
     $inputFilter = new RedirectInputFilter();
     $inputFilter->setData($data);
     if (!$inputFilter->isValid()) {
         return $this->getApiResponse(null, 400, $inputFilter);
     }
     $data = $inputFilter->getValues();
     $newRedirect = new Redirect();
     // @TODO filter data
     $newRedirect->populate($data);
     $entityManager = $this->getEntityManager();
     try {
         $redirectRepo = $entityManager->getRepository('\\Rcm\\Entity\\Redirect');
         $redirectRepo->save($newRedirect);
     } catch (RedirectException $e) {
         return $this->getApiResponse(null, 400, $e);
     }
     return $this->getApiResponse($newRedirect);
 }