public function testGetPathWithBasePathThatDoesNotMatch()
 {
     $this->request->expects($this->once())->method('getRequestUri')->will($this->returnValue('/bar'));
     $extractorFactory = new ExtractorFactory('/foo');
     $extractor = $extractorFactory->createPathExtractor();
     $this->assertSame('', $extractor($this->request));
 }
 /**
  * @covers Kunstmaan\LanguageChooserBundle\LocaleGuesser\UrlLocaleGuesser::guessLocale
  */
 public function testInvalidLocaleFound()
 {
     $this->metaValidator->expects($this->once())->method('isAllowed')->will($this->returnValue(false));
     $this->request->expects($this->once())->method('getPathInfo')->will($this->returnValue('/en/another-path'));
     $this->assertFalse($this->object->guessLocale($this->request));
     $this->assertEquals(null, $this->object->getIdentifiedLocale());
 }
 /**
  * @dataProvider getIncludeSubcategoriesChoiceDataProvider
  *
  * @param $value
  * @param $expected
  */
 public function testGetIncludeSubcategoriesChoice($value, $expected)
 {
     $this->requestProductHandler->setRequest($this->request);
     $this->request->expects($this->once())->method('get')->with(RequestProductHandler::INCLUDE_SUBCATEGORIES_KEY)->willReturn($value);
     $actual = $this->requestProductHandler->getIncludeSubcategoriesChoice();
     $this->assertEquals($expected, $actual);
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->placesAutocompleteHelperMock = $this->getMockBuilder('Ivory\\GoogleMap\\Helper\\Places\\AutocompleteHelper')->disableOriginalConstructor()->getMock();
     $this->requestMock = $this->getMock('Symfony\\Component\\HttpFoundation\\Request');
     $this->requestMock->expects($this->any())->method('getLocale')->will($this->returnValue('en'));
     $this->placesAutocompleteType = new PlacesAutocompleteType($this->placesAutocompleteHelperMock, $this->requestMock);
     $this->factory = Forms::createFormFactoryBuilder()->addType($this->placesAutocompleteType)->getFormFactory();
 }
Example #5
0
 public function testPageException()
 {
     $this->request->expects($this->once())->method('getPathInfo')->will($this->returnValue('/fail'));
     $this->twig->expects($this->at(0))->method('render')->with('page/fail.html.twig')->will($this->throwException(new Twig_Error_Loader('Unable to find template')));
     $this->twig->expects($this->at(1))->method('render')->with('error/404.html.twig');
     $result = $this->controller->page($this->request);
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $result);
     $this->assertSame(404, $result->getStatusCode());
 }
 /**
  * Test isActivePath method
  */
 public function testIsActivePath()
 {
     $this->request->expects($this->any())->method('getRequestUri')->will($this->returnValue('some/request/uri'));
     $this->container->expects($this->any())->method('get')->with($this->equalTo('request'))->will($this->returnValue($this->request));
     $this->extension->setActivePaths(array('some/specific/path'));
     $this->assertEquals(array('some/specific/path'), $this->extension->getActivePaths(), 'setActivePaths: Should return an array with "some/specific/path"');
     $this->assertTrue($this->extension->isActivePath('some/specific/path'), 'isActivePath: Should return true');
     $this->assertTrue($this->extension->isActivePath('some/request/uri'), 'isActivePath: Should return false');
 }
Example #7
0
 public function testProcess()
 {
     $this->form->expects($this->once())->method('setData')->with($this->entity);
     $this->request->expects($this->once())->method('getMethod')->will($this->returnValue('POST'));
     $this->form->expects($this->once())->method('submit');
     $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true));
     $this->manager->expects($this->once())->method('persist')->with($this->entity);
     $this->manager->expects($this->once())->method('flush');
     $this->assertTrue($this->handler->process($this->entity));
 }
 /**
  * @dataProvider buildKernelProvider
  */
 public function testOnBuildKernelHandler($sessionName, $isStarted, $storageKey, $hasPreviousSession)
 {
     $this->session->expects($this->once())->method('getName')->will($this->returnValue($sessionName));
     $this->session->expects($this->once())->method('isStarted')->will($this->returnValue($isStarted));
     $this->request->expects($this->once())->method('hasPreviousSession')->will($this->returnValue($hasPreviousSession));
     $sessionMapper = new SessionMapper($this->sessionStorage, $storageKey, $this->session);
     $sessionMapper->setRequest($this->request);
     $event = new PreBuildKernelEvent(new ParameterBag(), $this->request);
     $sessionMapper->onBuildKernelHandler($event);
     $this->assertSame(array('session' => array('configured' => true, 'started' => $isStarted, 'name' => $sessionName, 'namespace' => $storageKey, 'has_previous' => $hasPreviousSession, 'storage' => $this->sessionStorage), 'injected-settings' => array('site.ini/Session/CookieTimeout' => false, 'site.ini/Session/CookiePath' => false, 'site.ini/Session/CookieDomain' => false, 'site.ini/Session/CookieSecure' => false, 'site.ini/Session/CookieHttponly' => false)), $event->getParameters()->all());
 }
 public function testProcessExistingShoppingList()
 {
     $this->shoppingList->expects($this->once())->method('getId')->willReturn(1);
     $this->request->expects($this->once())->method('getMethod')->will($this->returnValue('PUT'));
     $this->form->expects($this->once())->method('submit')->with($this->request);
     $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true));
     /** @var \PHPUnit_Framework_MockObject_MockObject|ObjectManager $manager */
     $manager = $this->getMock('Doctrine\\Common\\Persistence\\ObjectManager');
     $manager->expects($this->once())->method('persist');
     $manager->expects($this->once())->method('flush');
     $this->registry->expects($this->once())->method('getManagerForClass')->with(self::SHOPPING_LIST_SHORTCUT)->will($this->returnValue($manager));
     $handler = new ShoppingListHandler($this->form, $this->request, $this->manager, $this->registry);
     $this->assertTrue($handler->process($this->shoppingList));
 }
 /**
  * @return PHPUnit_Framework_MockObject_MockObject|Request
  */
 protected function getRequestMock()
 {
     if (!isset($this->requestMock)) {
         $this->requestMock = $this->getMock('Symfony\\Component\\HttpFoundation\\Request');
         $this->requestMock->attributes = $this->getRequestAttributesMock();
         $this->requestMock->headers = $this->getRequestHeadersMock();
         if ($this->requestMethod === false) {
             $this->requestMock->expects($this->never())->method('getMethod');
         } else {
             $this->requestMock->expects($this->atLeastOnce())->method('getMethod')->will($this->returnValue($this->requestMethod));
         }
     }
     return $this->requestMock;
 }
 /**
  * @dataProvider getAccountDataProvider
  *
  * @param string $method
  * @param string $class
  * @param string $param
  */
 public function testGetAccount($method, $class, $param)
 {
     $entity = $this->getEntity($class, 42);
     $this->request->expects($this->once())->method('get')->with(OrderType::NAME)->willReturn([$param => $entity->getId()]);
     $this->objectManager->expects($this->once())->method('find')->with($class, $entity->getId())->willReturn($entity);
     $this->assertSame($entity, $this->handler->{$method}());
 }
Example #12
0
 /**
  * @param \PHPUnit_Framework_MockObject_MockObject|Form $form
  * @param object $entity
  * @param string $wid
  * @return array
  */
 protected function assertSaveData($form, $entity, $wid = 'WID')
 {
     $this->request->expects($this->atLeastOnce())->method('get')->with('_wid', false)->will($this->returnValue($wid));
     $formView = $this->getMockBuilder('Symfony\\Component\\Form\\FormView')->disableOriginalConstructor()->getMock();
     $form->expects($this->any())->method('createView')->will($this->returnValue($formView));
     return ['entity' => $entity, 'form' => $formView, 'isWidgetContext' => true];
 }
 public function testGetShowTierPricesWithRequestAndSaveState()
 {
     $this->handler->setRequest($this->request);
     $this->request->expects($this->exactly(3))->method('get')->willReturnMap([[FrontendPriceListRequestHandler::TIER_PRICES_KEY, null, false, '1'], [FrontendPriceListRequestHandler::SAVE_STATE_KEY, null, false, true]]);
     $this->session->expects($this->once())->method('set')->with(FrontendPriceListRequestHandler::TIER_PRICES_KEY, true);
     $this->assertEquals(true, $this->handler->getShowTierPrices());
 }
 public function testVisitDatasource()
 {
     /** @var \PHPUnit_Framework_MockObject_MockObject|DatagridConfiguration $config */
     $config = $this->getMockBuilder('Oro\\Bundle\\DataGridBundle\\Datagrid\\Common\\DatagridConfiguration')->disableOriginalConstructor()->getMock();
     $config->expects($this->any())->method('getName')->will($this->returnValue(AccountUserByAccountExtension::SUPPORTED_GRID));
     $this->request->expects($this->any())->method('get')->with(AccountUserByAccountExtension::ACCOUNT_KEY)->will($this->returnValue(1));
     $expr = $this->getMockBuilder('Doctrine\\ORM\\Query\\Expr')->disableOriginalConstructor()->getMock();
     $qb = $this->getMockBuilder('Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->getMock();
     $qb->expects($this->once())->method('andWhere')->will($this->returnSelf());
     $qb->expects($this->once())->method('setParameter')->with('account', 1)->will($this->returnSelf());
     $qb->expects($this->once())->method('getRootAliases')->will($this->returnValue(['au']));
     $qb->expects($this->once())->method('expr')->will($this->returnValue($expr));
     /** @var \PHPUnit_Framework_MockObject_MockObject|OrmDatasource $datasource */
     $datasource = $this->getMockBuilder('Oro\\Bundle\\DataGridBundle\\Datasource\\Orm\\OrmDatasource')->disableOriginalConstructor()->getMock();
     $datasource->expects($this->once())->method('getQueryBuilder')->will($this->returnValue($qb));
     $this->extension->visitDatasource($config, $datasource);
 }
 public function testConfirmException()
 {
     $this->request->expects($this->once())->method('get')->with('token')->willReturn('awesome-token');
     $this->filesystem->expects($this->once())->method('exists')->with(sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'awesome-token' . '.txt')->willReturn(true);
     $this->mollieAPIClient->payments = $this->payments;
     $this->payments->expects($this->once())->method('get')->with('test')->willThrowException(new Mollie_API_Exception());
     $this->assertFalse($this->mollieDriver->confirm($this->request));
 }
 /**
  * Creates request mock object
  *
  * @return Request
  */
 private function getRequest()
 {
     $this->request = $this->getMock('Symfony\\Component\\HttpFoundation\\Request');
     $this->request->expects($this->once())->method('getRequestFormat')->will($this->returnValue('html'));
     $this->request->expects($this->once())->method('getMethod')->will($this->returnValue('GET'));
     $this->request->expects($this->any())->method('get')->will($this->returnValueMap(array(array('_route', 'test_route'), array('_route_params', array()), array('id', 1))));
     return $this->request;
 }
 /**
  * Creates request mock object
  *
  * @return Request
  */
 private function getRequest()
 {
     $this->request = $this->getMock('Symfony\\Component\\HttpFoundation\\Request');
     $this->request->expects($this->once())->method('getRequestFormat')->will($this->returnValue('html'));
     $this->request->expects($this->once())->method('getMethod')->will($this->returnValue('GET'));
     $this->request->expects($this->once())->method('get')->with('_route')->will($this->returnValue('test_route'));
     return $this->request;
 }
 /**
  * Test case to cover the showResignedAction with filter value as post
  *
  * @covers Skyrocket\LoginBundle\Controller\DefaultController::showResignedAction
  */
 public function testShowResignedWithFilterAction()
 {
     $dummyResultArray = $this->getResignedDummyFilterArray();
     $this->mockController->expects($this->once())->method('getRequest')->will($this->returnValue($this->mockRequest));
     $this->mockRequest->expects($this->any())->method('getMethod')->will($this->returnValue('POST'));
     $this->mockRequest->expects($this->at(1))->method('get')->with($this->equalTo('fromDate'))->will($this->returnValue('08/04/2015'));
     $this->mockRequest->expects($this->at(2))->method('get')->with($this->equalTo('toDate'))->will($this->returnValue('08/06/2015'));
     $this->mockController->expects($this->once())->method('getDoctrine')->will($this->returnValue($this->mockRegistry));
     $this->mockRegistry->expects($this->once())->method('getManager')->will($this->returnValue($this->mockEntityManager));
     $this->mockEntityManager->expects($this->once())->method('getRepository')->with($this->equalTo('SkyrocketLoginBundle:Employee'))->will($this->returnValue($this->mockRepository));
     $this->mockRepository->expects($this->once())->method('getFilteredEmployeesResigned')->with($this->equalTo(1), $this->equalTo('2015-08-04 00:00:00'), $this->equalTo('2015-08-06 00:00:00'))->will($this->returnValue($dummyResultArray));
     $this->mockController->showResignedAction();
 }
 public function testOnKernelRequestUserHash()
 {
     $hash = '123abc';
     $this->hashGenerator->expects($this->once())->method('generate')->will($this->returnValue($hash));
     $this->request->headers->add(array('X-HTTP-Override' => 'AUTHENTICATE', 'Accept' => Kernel::USER_HASH_ACCEPT_HEADER));
     $this->request->expects($this->once())->method('hasSession')->will($this->returnValue(true));
     $this->assertNull($this->requestEventListener->onKernelRequestUserHash($this->event));
     $this->assertTrue($this->event->isPropagationStopped());
     $this->assertTrue($this->event->hasResponse());
     $response = $this->event->getResponse();
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $response);
     $this->assertTrue($response->headers->has('X-User-Hash'));
     $this->assertSame($hash, $response->headers->get('X-User-Hash'));
 }
Example #20
0
 /**
  * @dataProvider pageProvider
  */
 public function testGetViewDataPagedLimit($page, $pageSize, $limitResult, $uuid, $expectedData, $hasNextPage)
 {
     $property = $this->getMockForAbstractClass('Sulu\\Component\\Content\\Compat\\PropertyInterface', [], '', true, true, true, ['getValue', 'getParams']);
     $structure = $this->getMockForAbstractClass('Sulu\\Component\\Content\\Compat\\StructureInterface');
     $this->request->expects($this->at(0))->method('get')->with($this->equalTo('p'), $this->equalTo(1), $this->equalTo(false))->willReturn($page);
     $config = ['limitResult' => $limitResult, 'dataSource' => $uuid];
     $this->contentDataProvider->resolveResourceItems(['tags' => [], 'categories' => [], 'websiteTags' => [], 'websiteTagsOperator' => 'OR', 'websiteCategories' => [], 'websiteCategoriesOperator' => 'OR', 'limitResult' => $limitResult, 'dataSource' => $uuid, 'page' => $page, 'hasNextPage' => $hasNextPage, 'excluded' => [$uuid]], ['provider' => new PropertyParameter('provider', 'content'), 'page_parameter' => new PropertyParameter('page_parameter', 'p'), 'tags_parameter' => new PropertyParameter('tags_parameter', 'tags'), 'categories_parameter' => new PropertyParameter('categories_parameter', 'categories'), 'website_categories_operator' => new PropertyParameter('website_categories_operator', 'OR'), 'website_tags_operator' => new PropertyParameter('website_tags_operator', 'OR'), 'sorting' => new PropertyParameter('sorting', [], 'collection'), 'present_as' => new PropertyParameter('present_as', [], 'collection'), 'category_root' => new PropertyParameter('category_root', null), 'display_options' => new PropertyParameter('display_options', ['tags' => new PropertyParameter('tags', true), 'categories' => new PropertyParameter('categories', true), 'sorting' => new PropertyParameter('sorting', true), 'limit' => new PropertyParameter('limit', true), 'presentAs' => new PropertyParameter('presentAs', true)], 'collection'), 'has' => ['datasource' => false, 'tags' => true, 'categories' => false, 'sorting' => false, 'limit' => true, 'presentAs' => true], 'datasource' => null, 'max_per_page' => new PropertyParameter('max_per_page', $pageSize)], ['webspaceKey' => null, 'locale' => null], $limitResult, $page, $pageSize)->willReturn(new DataProviderResult($expectedData, $hasNextPage, $expectedData));
     $property->expects($this->at(1))->method('getValue')->willReturn($config);
     $property->expects($this->any())->method('getValue')->willReturn(array_merge($config, ['page' => $page, 'hasNextPage' => $hasNextPage]));
     $property->expects($this->any())->method('getParams')->will($this->returnValue(['max_per_page' => new PropertyParameter('max_per_page', $pageSize)]));
     $property->expects($this->exactly(3))->method('getStructure')->will($this->returnValue($structure));
     $structure->expects($this->any())->method('getUuid')->will($this->returnValue($uuid));
     $viewData = $this->smartContent->getViewData($property);
     $this->assertEquals(array_merge(['dataSource' => null, 'includeSubFolders' => null, 'category' => null, 'tags' => [], 'sortBy' => null, 'sortMethod' => null, 'presentAs' => null, 'limitResult' => null, 'page' => null, 'hasNextPage' => null, 'paginated' => false, 'referencedUuids' => [], 'categoryRoot' => null, 'categoriesParameter' => 'categories', 'tagsParameter' => 'tags'], $config, ['page' => $page, 'hasNextPage' => $hasNextPage]), $viewData);
 }
 public function testProcessNotExistingLineItem()
 {
     $this->request->expects($this->once())->method('getMethod')->will($this->returnValue('PUT'));
     $this->form->expects($this->once())->method('submit')->with($this->request);
     $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true));
     $repository = $this->getMockBuilder('OroB2B\\Bundle\\ShoppingListBundle\\Entity\\Repository\\LineItemRepository')->disableOriginalConstructor()->getMock();
     $repository->expects($this->once())->method('findDuplicate')->with($this->lineItem)->will($this->returnValue(null));
     $manager = $this->getMock('Doctrine\\Common\\Persistence\\ObjectManager');
     $manager->expects($this->once())->method('getRepository')->with(self::LINE_ITEM_SHORTCUT)->will($this->returnValue($repository));
     $manager->expects($this->once())->method('persist')->with($this->lineItem);
     $manager->expects($this->once())->method('flush');
     $this->registry->expects($this->once())->method('getManagerForClass')->with(self::LINE_ITEM_SHORTCUT)->will($this->returnValue($manager));
     $handler = new LineItemHandler($this->form, $this->request, $this->registry);
     $this->assertTrue($handler->process($this->lineItem));
     $this->assertEquals([], $handler->updateSavedId([]));
 }
Example #22
0
 /**
  * @dataProvider pageProvider
  */
 public function testGetViewDataPagedLimit($page, $pageSize, $offset, $limitResult, $uuid, $data, $expectedData, $limit, $hasNextPage)
 {
     $property = $this->getMockForAbstractClass('Sulu\\Component\\Content\\Compat\\PropertyInterface', [], '', true, true, true, ['getValue', 'getParams']);
     $structure = $this->getMockForAbstractClass('Sulu\\Component\\Content\\Compat\\StructureInterface');
     $this->request->expects($this->any())->method('get')->will($this->returnValue($page));
     $config = ['limitResult' => $limitResult, 'dataSource' => '123-123-123'];
     if ($limit) {
         $this->contentQuery->expects($this->once())->method('execute')->with($this->equalTo(null), $this->equalTo([null]), $this->equalTo($this->contentQueryBuilder), $this->equalTo(true), $this->equalTo(-1), $this->equalTo($limit), $this->equalTo($offset))->will($this->returnValue($data));
     }
     $property->expects($this->at(1))->method('getValue')->willReturn($config);
     $property->expects($this->any())->method('getValue')->willReturn(array_merge($config, ['page' => $page, 'hasNextPage' => $hasNextPage]));
     $property->expects($this->exactly(1))->method('getParams')->will($this->returnValue(['max_per_page' => new PropertyParameter('max_per_page', $pageSize)]));
     $property->expects($this->exactly(3))->method('getStructure')->will($this->returnValue($structure));
     $structure->expects($this->any())->method('getUuid')->will($this->returnValue($uuid));
     $viewData = $this->smartContent->getViewData($property);
     $this->assertEquals(array_merge(['dataSource' => null, 'includeSubFolders' => null, 'category' => null, 'tags' => [], 'sortBy' => null, 'sortMethod' => null, 'presentAs' => null, 'limitResult' => null, 'page' => null, 'hasNextPage' => null], $config, ['page' => $page, 'hasNextPage' => $hasNextPage]), $viewData);
 }
 /**
  * @covers ::viewElements
  */
 public function testViewElements()
 {
     $entity_type_id = $this->randomMachineName();
     $bundle = $this->randomMachineName();
     $field_name = $this->randomMachineName();
     $destination_url = $this->randomMachineName();
     $currency_code = $this->randomMachineName();
     $plugin_id = $this->randomMachineName();
     $plugin_configuration = [$this->randomMachineName() => $this->randomMachineName()];
     $plugin_id_property = $this->getMock(TypedDataInterface::class);
     $plugin_id_property->expects($this->once())->method('getValue')->willReturn($plugin_id);
     $plugin_configuration_property = $this->getMock(TypedDataInterface::class);
     $plugin_configuration_property->expects($this->once())->method('getValue')->willReturn($plugin_configuration);
     $map = [['plugin_id', $plugin_id_property], ['plugin_configuration', $plugin_configuration_property]];
     $item = $this->getMockBuilder(PaymentFormFieldType::class)->disableOriginalConstructor()->getMock();
     $item->expects($this->exactly(2))->method('get')->willReturnMap($map);
     $entity = $this->getMock(EntityInterface::class);
     $entity->expects($this->atLeastOnce())->method('bundle')->willReturn($bundle);
     $entity->expects($this->atLeastOnce())->method('getEntityTypeId')->willReturn($entity_type_id);
     $iterator = new \ArrayIterator([$item]);
     $items = $this->getMockBuilder(FieldItemList::class)->disableOriginalConstructor()->setMethods(['getEntity', 'getIterator'])->getMock();
     $items->expects($this->atLeastOnce())->method('getEntity')->willReturn($entity);
     $items->expects($this->atLeastOnce())->method('getIterator')->willReturn($iterator);
     $this->fieldDefinition->expects($this->once())->method('getName')->willReturn($field_name);
     $this->fieldDefinition->expects($this->atLeastOnce())->method('getSetting')->with('currency_code')->willReturn($currency_code);
     $payment_type = $this->getMockBuilder(PaymentFormPaymentType::class)->disableOriginalConstructor()->getMock();
     $payment_type->expects($this->once())->method('setEntityTypeId')->with($entity_type_id);
     $payment_type->expects($this->once())->method('setBundle')->with($bundle);
     $payment_type->expects($this->once())->method('setFieldName')->with($field_name);
     $payment_type->expects($this->once())->method('setDestinationUrl')->with($destination_url);
     $payment = $this->getMock(PaymentInterface::class);
     $payment->expects($this->once())->method('setCurrencyCode')->with($currency_code);
     $payment->expects($this->once())->method('getPaymentType')->willReturn($payment_type);
     $payment_line_item = $this->getMock(PaymentLineItemInterface::class);
     $this->paymentLineItemManager->expects($this->once())->method('createInstance')->with($plugin_id, $plugin_configuration)->willReturn($payment_line_item);
     $this->paymentStorage->expects($this->once())->method('create')->with(['bundle' => 'payment_form'])->willReturn($payment);
     $this->request->expects($this->atLeastOnce())->method('getUri')->willReturn($destination_url);
     $form = ['#foo' => $this->randomMachineName()];
     $this->entityFormBuilder->expects($this->once())->method('getForm')->with($payment, 'payment_form')->willReturn($form);
     $this->assertSame($form, $this->sut->viewElements($items, 'en'));
 }
 /**
  * @param bool $result
  */
 protected function assertRequestGetCalled($result = true)
 {
     $this->request->expects($this->once())->method('get')->with(ProductDataStorage::STORAGE_KEY)->willReturn($result);
 }