/**
  * Tests path.
  *
  * @param array $parameters
  * @param int   $page
  *
  * @dataProvider testPathDataProvider
  */
 public function testPath(array $parameters, $page)
 {
     $route = 'route_name';
     $this->router->expects($this->once())->method('generate')->will($this->returnValue('/'));
     $result = $this->pagerExtension->path($route, $page, $parameters);
     $this->assertEquals('/', $result);
 }
 public function testGetUrl()
 {
     $this->router->expects($this->once())->method('generate')->with($this->equalTo('sonata_cache_opcode'), $this->equalTo(array('token' => 'token')))->will($this->returnValue('/sonata/cache/opcode/token'));
     $method = new \ReflectionMethod($this->cache, 'getUrl');
     $method->setAccessible(true);
     $this->assertEquals('/sonata/cache/opcode/token', $method->invoke($this->cache));
 }
 public function testSingle()
 {
     $this->channelRouter->register(new ChannelType('homepage', 'homepage', 'single'));
     $this->router->expects($this->once())->method('generate')->with($this->equalTo('homepage'));
     $channel = new Channel();
     $channel->setType('homepage');
     $this->channelRouter->getUrl($channel);
 }
 public function testFilterValueWithRedirectUriFalse()
 {
     $this->router->expects($this->once())->method('generate')->with('foo', array(), false)->will($this->returnValue('/test/bar'));
     $this->column->setName('action');
     $this->column->initOptions();
     $extension = new DefaultColumnOptionsExtension();
     $extension->initOptions($this->column);
     $this->column->setOption('actions', array('edit' => array('route_name' => 'foo', 'absolute' => false, 'redirect_uri' => false)));
     $this->assertSame(array('edit' => array('content' => 'edit', 'field_mapping_values' => array('foo' => 'bar'), 'url_attr' => array('href' => '/test/bar'))), $this->column->filterValue(array('foo' => 'bar')));
 }
 public function testCreateUserFormDataValidWillReturn201Response()
 {
     $request = $this->createExampleRequest();
     $this->formMock->expects($this->once())->method('isValid')->will($this->returnValue(true));
     $this->routerMock->expects($this->once())->method('generate')->will($this->returnValue('http://example.com'));
     $view = $this->controller->createUserAction($request);
     $this->assertInstanceOf(User::class, $view->getData());
     $this->assertSame(201, $view->getStatusCode());
     $this->assertSame(['http://example.com'], $view->getHeaders()['location']);
 }
 public function testOnKernelRequestSetup()
 {
     $this->router->expects($this->once())->method('generate')->with('ezpublishSetup')->will($this->returnValue('/setup'));
     $this->router->expects($this->once())->method('getContext')->will($this->returnValue($this->getMock('Symfony\\Component\\Routing\\RequestContext')));
     $event = $this->createEvent('/foo/bar');
     $this->getListener('setup')->onKernelRequestSetup($event);
     $this->assertTrue($event->hasResponse());
     /** @var RedirectResponse $response */
     $response = $event->getResponse();
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\RedirectResponse', $response);
     $this->assertSame('/setup', $response->getTargetUrl());
 }
 protected function setUp()
 {
     $this->router = $this->getMock('\\Symfony\\Component\\Routing\\RouterInterface');
     $this->router->expects($this->any())->method('generate')->willReturnCallback(function ($route, $params) {
         return serialize($params);
     });
     /** @var \Twig_Environment|\PHPUnit_Framework_MockObject_MockObject $twig */
     $twig = $this->getMockBuilder('\\Twig_Environment')->disableOriginalConstructor()->getMock();
     $twig->expects($this->any())->method('render')->willReturnCallback(function ($template, $params) {
         return serialize($params);
     });
     $this->managerRegistry = $this->getMockBuilder('\\Symfony\\Bridge\\Doctrine\\ManagerRegistry')->disableOriginalConstructor()->getMock();
     $this->extension = new DeleteMessageTextGenerator($this->router, $twig, $this->managerRegistry);
 }
Example #8
0
 /**
  * @dataProvider filebrowserProvider
  */
 public function testRenderReplaceWithFileBrowserHandler($filebrowser)
 {
     $this->routerMock->expects($this->once())->method('generate')->with($this->equalTo('browse_route'), $this->equalTo(array('foo' => 'bar')), $this->equalTo(true))->will($this->returnValue('browse_url'));
     $this->assertSame(sprintf('CKEDITOR.replace("foo", {"filebrowser%sUrl":"browse_url"});', $filebrowser), $this->helper->renderReplace('foo', array('filebrowser' . $filebrowser . 'Handler' => function (RouterInterface $router) {
         return $router->generate('browse_route', array('foo' => 'bar'), true);
     })));
 }
 public function testGenerateWithPageAliasFromHybridPage()
 {
     $page = $this->getMock('Sonata\\PageBundle\\Model\\PageInterface');
     $page->expects($this->exactly(5))->method('isHybrid')->will($this->returnValue(true));
     $page->expects($this->exactly(5))->method('getRouteName')->will($this->returnValue('test_route'));
     $site = $this->getMock('Sonata\\PageBundle\\Model\\SiteInterface');
     $this->siteSelector->expects($this->exactly(5))->method('retrieve')->will($this->returnValue($site));
     $cmsManager = $this->getMock('Sonata\\PageBundle\\CmsManager\\CmsManagerInterface');
     $cmsManager->expects($this->exactly(5))->method('getPageByPageAlias')->will($this->returnValue($page));
     $this->cmsSelector->expects($this->exactly(5))->method('retrieve')->will($this->returnValue($cmsManager));
     $this->defaultRouter->expects($this->at(0))->method('generate')->with($this->equalTo('test_route'), $this->equalTo(array('key' => 'value')), $this->equalTo(UrlGeneratorInterface::ABSOLUTE_PATH))->will($this->returnValue('/test/key/value'));
     $this->defaultRouter->expects($this->at(1))->method('generate')->with($this->equalTo('test_route'), $this->equalTo(array('key' => 'value')), $this->equalTo(UrlGeneratorInterface::ABSOLUTE_PATH))->will($this->returnValue('/test/key/value'));
     $this->defaultRouter->expects($this->at(2))->method('generate')->with($this->equalTo('test_route'), $this->equalTo(array('key' => 'value')), $this->equalTo(UrlGeneratorInterface::RELATIVE_PATH))->will($this->returnValue('test/key/value'));
     $this->defaultRouter->expects($this->at(3))->method('generate')->with($this->equalTo('test_route'), $this->equalTo(array('key' => 'value')), $this->equalTo(UrlGeneratorInterface::ABSOLUTE_URL))->will($this->returnValue('http://localhost/test/key/value'));
     $this->defaultRouter->expects($this->at(4))->method('generate')->with($this->equalTo('test_route'), $this->equalTo(array('key' => 'value')), $this->equalTo(UrlGeneratorInterface::NETWORK_PATH))->will($this->returnValue('//localhost/test/key/value'));
     $url = $this->router->generate('_page_alias_homepage', array('key' => 'value'));
     $this->assertEquals('/test/key/value', $url);
     $url = $this->router->generate('_page_alias_homepage', array('key' => 'value'), UrlGeneratorInterface::ABSOLUTE_PATH);
     $this->assertEquals('/test/key/value', $url);
     $url = $this->router->generate('_page_alias_homepage', array('key' => 'value'), UrlGeneratorInterface::RELATIVE_PATH);
     $this->assertEquals('test/key/value', $url);
     $url = $this->router->generate('_page_alias_homepage', array('key' => 'value'), UrlGeneratorInterface::ABSOLUTE_URL);
     $this->assertEquals('http://localhost/test/key/value', $url);
     $url = $this->router->generate('_page_alias_homepage', array('key' => 'value'), UrlGeneratorInterface::NETWORK_PATH);
     $this->assertEquals('//localhost/test/key/value', $url);
 }
 protected function setUp()
 {
     parent::setUp();
     \Locale::setDefault('en');
     $this->dispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $this->router = $this->getMock('Symfony\\Component\\Routing\\RouterInterface');
     $this->requestStack = new RequestStack();
     /* @var Request $request */
     $request = $this->getMock('Symfony\\Component\\HttpFoundation\\Request');
     $this->requestStack->push($request);
     $this->router->expects($this->any())->method('generate')->will($this->returnCallback(function ($param) {
         return '/' . $param;
     }));
     $this->factory = Forms::createFormFactoryBuilder()->addExtensions($this->getExtensions())->addTypeExtension(new ChoiceSelect2TypeExtension($this->dispatcher, $this->requestStack, $this->router, $this->getExtensionTypeName(), 10))->getFormFactory();
     $this->dispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $this->builder = new FormBuilder(null, null, $this->dispatcher, $this->factory);
 }
 /**
  * @test
  */
 public function getUserUrl()
 {
     $user = new User();
     $user->setId(1);
     $url = '/user/view/4';
     $this->router->expects($this->once())->method('generate')->with('oro_user_view', ['id' => $user->getId()])->will($this->returnValue($url));
     $this->twigExtension->getUserUrl($user);
 }
 /**
  * @expectedException \Usoft\IDealBundle\Exceptions\IDealExecuteException
  *
  * @throws \Usoft\IDealBundle\Exceptions\IDealExecuteException
  */
 public function testExecuteException()
 {
     $this->router->expects($this->once())->method('generate')->with('confirm_route')->willReturn('http://www.awesome-app.com/foo/bar?token=foobar');
     $this->mollieAPIClient->payments = $this->payments;
     $this->bank->expects($this->once())->method('getId')->willReturn(666);
     $this->payments->expects($this->once())->method('create')->with(["amount" => 12.43, "description" => 'awesome test', "redirectUrl" => 'http://www.awesome-app.com/foo/bar?token=foobar', "method" => Mollie_API_Object_Method::IDEAL, "issuer" => 666])->willThrowException(new \Exception());
     $this->eventDispatcher->expects($this->never())->method('dispatch');
     $this->mollieDriver->execute($this->bank, 12.43, 'confirm_route');
 }
 public function testFormTypeEntityToJson()
 {
     $entity = new Entity(1);
     $className = get_class($entity);
     $formData = array('auto' => '1');
     $routeName = 'routename';
     $this->router->expects($this->once())->method('generate')->with($routeName)->willReturn('/route/name');
     $this->entityMgr->expects($this->once())->method('getReference')->with($className, 1)->willReturn($entity);
     $form = $this->factory->createBuilder()->add('auto', AutocompleterType::class, array('route' => $routeName, 'class' => $className, 'method' => 'GET'))->getForm();
     $view = $form->createView();
     $form->submit($formData);
     $data = $form['auto']->getData();
     $this->assertEquals($data, $entity);
     $this->assertInstanceOf($className, $data);
     $this->assertArrayHasKey('auto', $view);
     $this->assertArrayHasKey('attr', $view['auto']->vars);
     $this->assertArrayHasKey('data-autocompleteUrl', $view['auto']->vars['attr']);
     $this->assertEquals($view['auto']->vars['attr']['data-autocompleteUrl'], '/route/name');
     $this->assertContains('GET', $view['auto']->vars['attr']['data-options']);
 }
Example #14
0
 public function testGetEntitiesMetadata()
 {
     $this->entityProvider->expects($this->at(0))->method('getEntity')->will($this->returnvalue($this->entityConfig1));
     $this->entityProvider->expects($this->at(1))->method('getEntity')->will($this->returnvalue($this->entityConfig2));
     $this->entityProvider->expects($this->at(2))->method('getEntity')->will($this->returnvalue($this->entityConfig3));
     $extendConfigModel = $this->getMock('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigInterface');
     $extendConfigModel->expects($this->any())->method('get')->with($this->equalTo('owner'))->will($this->returnValue('Custom'));
     $extendProvider = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock();
     $extendProvider->expects($this->once())->method('map')->will($this->returnValue([]));
     $extendProvider->expects($this->any())->method('getConfig')->will($this->returnValue($extendConfigModel));
     $this->configManager->expects($this->any())->method('getProvider')->with($this->equalTo('extend'))->will($this->returnValue($extendProvider));
     $this->configManager->expects($this->any())->method('getConfigEntityModel')->will($this->onConsecutiveCalls($this->entityConfigModel1, $this->entityConfigModel2));
     $this->router->expects($this->exactly(4))->method('generate');
     /** @var MetadataProvider $provider */
     $provider = new MetadataProvider($this->settingsProvider, $this->entityProvider, $this->configManager, $this->router);
     $result = $provider->getEntitiesMetadata();
     for ($i = 1; $i < 3; $i++) {
         $expectedConfig = $this->getExpectedConfig($i);
         $entityName = $expectedConfig['name'];
         $this->assertEquals($expectedConfig, $result[$entityName]);
     }
 }
 public function testGenerateWithPageAliasFromHybridPage()
 {
     $page = $this->getMock('Sonata\\PageBundle\\Model\\PageInterface');
     $page->expects($this->any())->method('isHybrid')->will($this->returnValue(true));
     $page->expects($this->once())->method('getRouteName')->will($this->returnValue('test_route'));
     $site = $this->getMock('Sonata\\PageBundle\\Model\\SiteInterface');
     $this->siteSelector->expects($this->once())->method('retrieve')->will($this->returnValue($site));
     $cmsManager = $this->getMock('Sonata\\PageBundle\\CmsManager\\CmsManagerInterface');
     $cmsManager->expects($this->once())->method('getPageByPageAlias')->will($this->returnValue($page));
     $this->cmsSelector->expects($this->once())->method('retrieve')->will($this->returnValue($cmsManager));
     $this->defaultRouter->expects($this->once())->method('generate')->with($this->equalTo('test_route'), $this->equalTo(array('key' => 'value')), $this->equalTo(true))->will($this->returnValue('http://localhost/test/key/value'));
     $url = $this->router->generate('_page_alias_homepage', array('key' => 'value'), true);
     $this->assertEquals('http://localhost/test/key/value', $url);
 }
 public function testRemoveContentTypeDraftWithRedirection()
 {
     $redirectRoute = 'foo';
     $redirectUrl = 'http://foo.com/bar';
     $contentTypeDraft = new ContentTypeDraft();
     $event = new FormActionEvent($this->getMock('\\Symfony\\Component\\Form\\FormInterface'), new ContentTypeData(['contentTypeDraft' => $contentTypeDraft]), 'removeDraft', ['languageCode' => 'eng-GB']);
     $this->contentTypeService->expects($this->once())->method('deleteContentType')->with($contentTypeDraft);
     $this->router->expects($this->once())->method('generate')->with($redirectRoute)->willReturn($redirectUrl);
     $expectedRedirectResponse = new RedirectResponse($redirectUrl);
     $formProcessor = new ContentTypeFormProcessor($this->contentTypeService, $this->router, ['redirectRouteAfterPublish' => $redirectRoute]);
     $formProcessor->processRemoveContentTypeDraft($event);
     self::assertTrue($event->hasResponse());
     self::assertEquals($expectedRedirectResponse, $event->getResponse());
 }
 /**
  * @param mixed $configRoute
  * @param string $expectedRoute
  *
  * @dataProvider routeProvider
  */
 public function testGetGridMetadataWorks($configRoute, $expectedRoute)
 {
     $gridName = 'test-grid';
     $gridScope = 'test-scope';
     $gridFullName = 'test-grid:test-scope';
     $params = ['foo' => 'bar'];
     $url = '/datagrid/test-grid?test-grid-test-scope=foo=bar';
     /** @var \PHPUnit_Framework_MockObject_MockObject|DatagridInterface $grid */
     $grid = $this->getMock('Oro\\Bundle\\DataGridBundle\\Datagrid\\DatagridInterface');
     $metadata = $this->getMockBuilder('Oro\\Bundle\\DataGridBundle\\Datagrid\\Common\\MetadataObject')->disableOriginalConstructor()->getMock();
     $grid->expects($this->once())->method('getMetadata')->will($this->returnValue($metadata));
     $grid->expects($this->once())->method('getName')->will($this->returnValue($gridName));
     $grid->expects($this->once())->method('getScope')->will($this->returnValue($gridScope));
     $this->nameStrategy->expects($this->once())->method('buildGridFullName')->with($gridName, $gridScope)->will($this->returnValue($gridFullName));
     $this->router->expects($this->once())->method('generate')->with($expectedRoute, ['gridName' => $gridFullName, $gridFullName => $params])->will($this->returnValue($url));
     $metadata->expects($this->once())->method('offsetAddToArray')->with('options', ['url' => $url, 'urlParams' => $params]);
     $metadata->expects($this->any())->method('offsetGetByPath')->with()->will($this->returnValueMap([['[options][route]', $configRoute]]));
     $metadataArray = ['metadata-array'];
     $metadata->expects($this->once())->method('toArray')->will($this->returnValue($metadataArray));
     $this->assertSame($metadataArray, $this->twigExtension->getGridMetadata($grid, $params));
 }
 /**
  * @dataProvider hasInCacheDataProvider
  * @param boolean $hasInCache
  */
 public function testUriCaching($hasInCache)
 {
     $cacheKey = md5('uri_acl:#');
     $cache = $this->getMockBuilder('Doctrine\\Common\\Cache\\ArrayCache')->getMock();
     $cache->expects($this->once())->method('contains')->with($cacheKey)->will($this->returnValue($hasInCache));
     if ($hasInCache) {
         $cache->expects($this->once())->method('fetch')->with($cacheKey)->will($this->returnValue('controller::action'));
     } else {
         $cache->expects($this->once())->method('save')->with($cacheKey, 'controller::action');
     }
     $this->factoryExtension->setCache($cache);
     $options = array('uri' => '#');
     if ($hasInCache) {
         $this->router->expects($this->never())->method('match');
     } else {
         $this->router->expects($this->once())->method('match')->will($this->returnValue(array('_controller' => 'controller::action')));
     }
     $this->securityFacade->expects($this->once())->method('isClassMethodGranted')->with('controller', 'action')->will($this->returnValue(true));
     $item = $this->factory->createItem('test', $options);
     $this->assertTrue($item->getExtra('isAllowed'));
     $this->assertInstanceOf('Knp\\Menu\\MenuItem', $item);
 }
 public function testGetFileBrowserPathHelper()
 {
     $this->routerMock->expects($this->once())->method('generate')->will($this->returnValue('bar'));
     $this->assertSame('bar', $this->helper->getFileBrowserPathHelper());
 }
 /**
  * @dataProvider getUrlProvider
  *
  * @param ExtReference $extReference extref object
  * @param string       $routeId      name of route that should get loaded
  * @param string       $url          url we expect to result from the conversion
  *
  * @return void
  */
 public function testGetUrl(ExtReference $extReference, $routeId, $url)
 {
     $this->router->expects($this->once())->method('generate')->with($routeId, ['id' => $extReference->getId()])->will($this->returnValue($url));
     $converter = new ExtReferenceConverter($this->router, ['App' => 'graviton.core.rest.app', 'Language' => 'graviton.i18n.rest.language', 'ShowCase' => 'gravitondyn.showcase.rest.showcase']);
     $this->assertEquals($url, $converter->getUrl($extReference));
 }