Exemplo n.º 1
0
 public function testSiteRequest()
 {
     $request = new SiteRequest();
     $request->setBaseUrl('folder/app_dev.php');
     $request->setPathInfo('/path-info');
     $this->assertEquals('folder/app_dev.php', $request->getBaseUrl());
     $this->assertEquals('/path-info', $request->getPathInfo());
 }
 /**
  * Perform the actual handleKernelSiteRequest method test
  */
 protected function performHandleKernelRequestTest($url)
 {
     $kernel = $this->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface');
     $request = SiteRequest::create($url);
     $event = new GetResponseEvent($kernel, $request, 'master');
     $siteManager = $this->getMock('Sonata\\PageBundle\\Model\\SiteManagerInterface');
     $decoratorStrategy = $this->getMock('Sonata\\PageBundle\\CmsManager\\DecoratorStrategyInterface');
     $seoPage = $this->getMock('Sonata\\SeoBundle\\Seo\\SeoPageInterface');
     $siteSelector = new HostPathSiteSelector($siteManager, $decoratorStrategy, $seoPage);
     // Stash the request object in the siteSelector request property
     $ref = new \ReflectionObject($siteSelector);
     $property = $ref->getProperty('request');
     $property->setAccessible(true);
     $property->setValue($siteSelector, $request);
     $property = $ref->getProperty('request');
     $property->setAccessible(false);
     // Look for the first site matched that is enabled, has started, and has not expired.
     // localhost is a possible match, but only if no other sites match.
     $siteSelector->handleKernelRequest($event);
     // The site found is stored in the protected property "site", so we use Reflection to access it.
     $ref = new \ReflectionObject($siteSelector);
     $property = $ref->getProperty('site');
     $property->setAccessible(true);
     $site = $property->getValue($siteSelector);
     return array($site, $event);
 }
 /**
  * Tests handleKernelRequest method selects the site /fr
  */
 public function testHandleKernelRequestSelectsFr()
 {
     $kernel = $this->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface');
     $request = SiteRequest::create('http://www.example.com', 'GET', array(), array(), array(), array('HTTP_ACCEPT_LANGUAGE' => 'fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4'));
     // Ensure request locale is null
     $this->assertNull($request->attributes->get('_locale'));
     $event = new GetResponseEvent($kernel, $request, 'master');
     $this->siteSelector->expects($this->once())->method('getSites')->with($request)->will($this->returnValue($this->getSites()));
     $this->siteSelector->handleKernelRequest($event);
     // Ensure request locale is fr
     $this->assertEquals('fr', $request->attributes->get('_locale'));
     $site = $this->getSite();
     // Ensure we retrieved the site "/fr"
     $this->assertEquals('/fr', $site->getRelativePath());
 }
 /**
  * Perform the actual handleKernelSiteRequest method test.
  */
 protected function performHandleKernelRequestTest($url)
 {
     $kernel = $this->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface');
     $request = SiteRequest::create($url);
     // Ensure request locale is null
     $this->assertNull($request->attributes->get('_locale'));
     $event = new GetResponseEvent($kernel, $request, 'master');
     $siteManager = $this->getMock('Sonata\\PageBundle\\Model\\SiteManagerInterface');
     $decoratorStrategy = $this->getMock('Sonata\\PageBundle\\CmsManager\\DecoratorStrategyInterface');
     $seoPage = $this->getMock('Sonata\\SeoBundle\\Seo\\SeoPageInterface');
     $siteSelector = new HostPathSiteSelector($siteManager, $decoratorStrategy, $seoPage);
     // Look for the first site matched that is enabled, has started, and has not expired.
     // localhost is a possible match, but only if no other sites match.
     $siteSelector->handleKernelRequest($event);
     $site = $siteSelector->retrieve();
     return array($site, $event);
 }
 /**
  * Tests handleKernelRequest method redirects to /fr.
  */
 public function testHandleKernelRequestRedirectsToFr()
 {
     $kernel = $this->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface');
     $request = SiteRequest::create('http://www.example.com', 'GET', array(), array(), array(), array('HTTP_ACCEPT_LANGUAGE' => 'fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4'));
     // Ensure request locale is null
     $this->assertNull($request->attributes->get('_locale'));
     $event = new GetResponseEvent($kernel, $request, 'master');
     $this->siteSelector->expects($this->once())->method('getSites')->with($request)->will($this->returnValue($this->getSites()));
     $this->siteSelector->handleKernelRequest($event);
     // Ensure request locale is still null
     $this->assertNull($request->attributes->get('_locale'));
     $site = $this->getSite();
     // Ensure no site was retrieved
     $this->assertNull($site);
     // Retrieve the event's response object
     $response = $event->getResponse();
     // Ensure the response was a redirect to the default site
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\RedirectResponse', $response);
     // Ensure the redirect url is for "/fr"
     $this->assertEquals('/fr', $response->getTargetUrl());
 }
Exemplo n.º 6
0
<?php

die("You are not allowed to access to the API. Check " . basename(__FILE__) . " for more information.");
require_once __DIR__ . '/../app/bootstrap.php.cache';
require_once __DIR__ . '/../app/ApiKernel.php';
//require_once __DIR__.'/../app/AppCache.php';
//$kernel = new AppCache(new ApiKernel('prod', false));
$kernel = new ApiKernel('prod', false);
//$kernel->loadClassCache();
// if you want to use the SonataPageBundle with multisite
// using different relative paths, you must change the request
// object to use the SiteRequest
use Sonata\PageBundle\Request\SiteRequest as Request;
//use Symfony\Component\HttpFoundation\Request;
$kernel->handle(Request::createFromGlobals())->send();
Exemplo n.º 7
0
/**
 * @param $env
 * @param $debug
 *
 * @return Symfony\Component\HttpFoundation\Response
 */
function sonata_handle($env, $debug)
{
    $request = Request::createFromGlobals();
    $kernel = sonata_bootstrap(sonata_get_app($request), $env, $debug);
    return $kernel->handle($request);
}