protected function setUp() { $this->controller = $controller = $this->getMock("Thelia\\Controller\\BaseController", ["getParser", "render", "renderRaw"]); /** * Reset static :: $formDefinition on controllers */ $this->definitionReflection = $reflection = (new \ReflectionObject($this->controller))->getProperty('formDefinition'); $reflection->setAccessible(true); $this->formDefinition = $reflection->getValue(); $reflection->setValue(null); /** * Add the test type to the factory and * the form to the container */ $factory = new FormFactoryBuilder(); $factory->addExtension(new CoreExtension()); $factory->addType(new TestType()); /** * Construct the container */ $container = new Container(); $container->set("thelia.form_factory_builder", $factory); $container->set("thelia.translator", new Translator($container)); $container->setParameter("thelia.parser.forms", array("test_form" => "Thelia\\Tests\\Resources\\Form\\TestForm")); $request = new Request(); $request->setSession(new Session(new MockArraySessionStorage())); $container->set("request", $request); $container->set("thelia.forms.validator_builder", new ValidatorBuilder()); $container->set("event_dispatcher", new EventDispatcher()); $this->controller->setContainer($container); }
protected function getGetResponseEvent() { $request = new Request(); $request->setSession(new Session(new MockArraySessionStorage())); /** @var HttpKernelInterface $kernelMock */ $kernelMock = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\HttpKernelInterface')->disableOriginalConstructor()->getMock(); return new GetResponseEvent($kernelMock, $request, HttpKernelInterface::MASTER_REQUEST); }
public function getContainer() { $container = new \Symfony\Component\DependencyInjection\ContainerBuilder(); $container->set("event_dispatcher", $this->getDispatcher()); $request = new Request(); $request->setSession($this->session); $container->set("request", $request); return $container; }
public function setUp() { $this->request = new Request(); $this->session = new Session(new MockArraySessionStorage()); $this->request->setSession($this->session); $translator = new Translator($this->getMock('\\Symfony\\Component\\DependencyInjection\\ContainerInterface')); $this->cartAction = new \Thelia\Action\Cart($this->request, new TokenProvider($this->request, $translator, 'baba au rhum')); $this->dispatcherNull = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface'); $this->dispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface', array(), array(), '', true, true, true, false); $this->dispatcher->expects($this->any())->method('dispatch')->will($this->returnCallback(function ($type, $event) { $event->setDispatcher($this->dispatcher); if ($type == TheliaEvents::CART_RESTORE_CURRENT) { $this->cartAction->restoreCurrentCart($event); } elseif ($type == TheliaEvents::CART_CREATE_NEW) { $this->cartAction->createEmptyCart($event); } })); }
protected function init() { $container = $this->getContainer(); $request = new Request(); $request->setSession(new Session(new MockArraySessionStorage())); /** @var RequestStack $requestStack */ $requestStack = $container->get('request_stack'); $requestStack->push($request); }
public function setUp() { $session = new Session(new MockArraySessionStorage()); $request = new Request(); $request->setSession($session); $this->mailerFactory = $this->getMockBuilder("Thelia\\Mailer\\MailerFactory")->disableOriginalConstructor()->getMock(); $translator = new Translator(new Container()); $this->tokenProvider = new TokenProvider($request, $translator, 'test'); }
public function getContainer() { $container = new ContainerBuilder(); $container->set("event_dispatcher", $this->getDispatcher()); $request = new Request(); $request->setSession($this->session); $container->set("request", $request); return $container; }
public function setUp() { parent::setUp(); $session = new Session(new MockArraySessionStorage()); $request = new Request(); $request->setSession($session); $this->requestStack = new RequestStack(); $this->requestStack->push($request); }
public function getContainer() { $container = new \Symfony\Component\DependencyInjection\ContainerBuilder(); $dispatcher = $this->getMock("Symfony\\Component\\EventDispatcher\\EventDispatcherInterface"); $container->set("event_dispatcher", $dispatcher); $fileManager = new FileManager(["document.product" => "Thelia\\Model\\ProductDocument", "image.product" => "Thelia\\Model\\ProductImage", "document.category" => "Thelia\\Model\\CategoryDocument", "image.category" => "Thelia\\Model\\CategoryImage", "document.content" => "Thelia\\Model\\ContentDocument", "image.content" => "Thelia\\Model\\ContentImage", "document.folder" => "Thelia\\Model\\FolderDocument", "image.folder" => "Thelia\\Model\\FolderImage", "document.brand" => "Thelia\\Model\\BrandDocument", "image.brand" => "Thelia\\Model\\BrandImage"]); $container->set("thelia.file_manager", $this->getFileManager()); $request = new Request(); $request->setSession($this->session); $container->set("request", $request); return $container; }
public function getContainer() { $container = new \Symfony\Component\DependencyInjection\ContainerBuilder(); $container->set("thelia.translator", new Translator(new Container())); $dispatcher = $this->getMock("Symfony\\Component\\EventDispatcher\\EventDispatcherInterface"); $container->set("event_dispatcher", $dispatcher); $request = new Request(); $request->setSession($this->getSession()); $container->set("request", $request); $container->set("thelia.securitycontext", new SecurityContext($request)); $this->buildContainer($container); return $container; }
public function getContainer() { $container = new ContainerBuilder(); $container->set("thelia.translator", new Translator(new Container())); $dispatcher = $this->getMockEventDispatcher(); $container->set("event_dispatcher", $dispatcher); $request = new Request(); $request->setSession($this->getSession()); $container->set("request", $request); $requestStack = new RequestStack(); $requestStack->push($request); $container->set("request_stack", $requestStack); new Translator($container); $container->set("thelia.securitycontext", new SecurityContext($requestStack)); $this->buildContainer($container); return $container; }
public function setUp() { $this->container = new ContainerBuilder(); $this->container->setParameter("thelia.parser.loops", ["tested-loop" => $this->getTestedClassName()]); $session = new Session(new MockArraySessionStorage()); $request = new Request(); $requestStack = new RequestStack(); $request->setSession($session); /*$stubEventdispatcher = $this->getMockBuilder('\Symfony\Component\EventDispatcher\EventDispatcher') ->disableOriginalConstructor() ->getMock(); $stubSecurityContext = $this->getMockBuilder('\Thelia\Core\Security\SecurityContext') ->disableOriginalConstructor() ->getMock();*/ /*$stubAdapter->expects($this->any()) ->method('getTranslator') ->will($this->returnValue($stubTranslator));*/ /*$this->request = new Request(); $this->request->setSession(new Session(new MockArraySessionStorage())); $this->dispatcher = new EventDispatcher(); $this->securityContext = new SecurityContext($this->request);*/ $stubRouterAdmin = $this->getMockBuilder('\\Symfony\\Component\\Routing\\Router')->disableOriginalConstructor()->setMethods(array('getContext'))->getMock(); $stubRequestContext = $this->getMockBuilder('\\Symfony\\Component\\Routing\\RequestContext')->disableOriginalConstructor()->setMethods(array('getHost'))->getMock(); $stubRequestContext->expects($this->any())->method('getHost')->will($this->returnValue('localhost')); $stubRouterAdmin->expects($this->any())->method('getContext')->will($this->returnValue($stubRequestContext)); $requestStack->push($request); $this->container->set('request', $request); $this->container->set('request_stack', $requestStack); $this->container->set('event_dispatcher', new EventDispatcher()); $this->container->set('thelia.translator', new Translator($this->container)); $this->container->set('thelia.securityContext', new SecurityContext($requestStack)); $this->container->set('router.admin', $stubRouterAdmin); $this->container->set('thelia.url.manager', new URL($this->container)); $this->container->set('thelia.taxEngine', new TaxEngine($requestStack)); $this->instance = $this->getTestedInstance(); $this->instance->initializeArgs($this->getMandatoryArguments()); }
public function setUp() { $this->backup_mail_template = ConfigQuery::read('active-mail-template', 'default'); ConfigQuery::write('active-mail-template', 'test'); @mkdir(TemplateHelper::getInstance()->getActiveMailTemplate()->getAbsolutePath(), 0777, true); $container = new ContainerBuilder(); $session = new Session(new MockArraySessionStorage()); $request = new Request(); $dispatcher = $this->getMock("Symfony\\Component\\EventDispatcher\\EventDispatcherInterface"); $request->setSession($session); /* * public function __construct( Request $request, EventDispatcherInterface $dispatcher, ParserContext $parserContext, $env = "prod", $debug = false) */ $container->set("event_dispatcher", $dispatcher); $container->set('request', $request); $this->parser = new SmartyParser($request, $dispatcher, new ParserContext($request), 'dev', true); $this->parser->setTemplateDefinition(TemplateHelper::getInstance()->getActiveMailTemplate()); $container->set('thelia.parser', $this->parser); $this->container = $container; }
protected function setUp() { /** * Add the test type to the factory and * the form to the container */ $factory = new FormFactoryBuilder(); $factory->addExtension(new CoreExtension()); $factory->addType(new TestType()); /** * Construct the container */ $container = new Container(); $container->set("thelia.form_factory_builder", $factory); $container->set("thelia.translator", new Translator($container)); $container->setParameter("thelia.parser.forms", $definition = array("test_form" => "Thelia\\Tests\\Resources\\Form\\TestForm")); $request = new Request(); $request->setSession(new Session(new MockArraySessionStorage())); $container->set("request", $request); $container->set("thelia.forms.validator_builder", new ValidatorBuilder()); $container->set("event_dispatcher", new EventDispatcher()); $this->factory = new TheliaFormFactory($request, $container, $definition); }
public function setUp() { $session = new Session(new MockArraySessionStorage()); $request = new Request(); $request->setSession($session); $this->container = new ContainerBuilder(); $this->container->set("event_dispatcher", $this->getMockEventDispatcher()); $this->container->set('request', $request); $this->requestStack = new RequestStack(); $this->requestStack->push($request); $this->container->set('request_stack', $this->requestStack); $this->securityContext = new SecurityContext($this->requestStack); $this->orderEvent = new OrderEvent(new OrderModel()); $mailerFactory = new MailerFactory($this->getMockEventDispatcher(), $this->getMockParserInterface()); $this->orderAction = new Order($this->requestStack, $mailerFactory, $this->securityContext); /* load customer */ $this->customer = $this->loadCustomer(); if (null === $this->customer) { return; } /* fill cart */ $this->cart = $this->fillCart(); }
/** * @return string */ public function doExport() { /** * Define the cache */ $cache = []; $cache["brand"] = []; $cache["category"] = []; $cache["breadcrumb"] = []; $cache["feature"]["title"] = []; $cache["feature"]["value"] = []; $cache["attribute"]["title"] = []; $cache["attribute"]["value"] = []; $fakeCartItem = new CartItem(); $fakeCart = new Cart(); $fakeCart->addCartItem($fakeCartItem); /** @var \Thelia\Model\Country $country */ $country = CountryQuery::create()->findOneById(ConfigQuery::create()->read('store_country', null)); $deliveryModuleModelId = ShoppingFluxConfigQuery::getDeliveryModuleId(); $deliveryModuleModel = ModuleQuery::create()->findPk($deliveryModuleModelId); /** @var \Thelia\Module\AbstractDeliveryModule $deliveryModule */ $deliveryModule = $deliveryModuleModel->getModuleInstance($this->container); /** * Build fake Request to inject in the module */ $fakeRequest = new Request(); $fakeRequest->setSession((new FakeSession())->setCart($fakeCart)); $deliveryModule->setRequest($fakeRequest); /** * Currency */ $currency = Currency::getDefaultCurrency(); /** * Load ecotax */ $ecotax = TaxQuery::create()->findPk(ShoppingFluxConfigQuery::getEcotaxRuleId()); /** * If there's a problem in the configuration, load a fake tax */ if ($ecotax === null) { $ecotax = new Tax(); $ecotax->setType('\\Thelia\\TaxEngine\\TaxType\\FixAmountTaxType')->setRequirements(array('amount' => 0)); } /** * Load the tax instance */ $ecotaxInstance = $ecotax->getTypeInstance(); // Compatibility with Thelia <= 2.0.2 $ecotaxInstance->loadRequirements($ecotax->getRequirements()); // We can pass any product as Argument, it is not used $ecotax = $ecotaxInstance->fixAmountRetriever(new Product()); /** @var \Thelia\Model\Product $product */ foreach ($this->getData() as $product) { $product->setLocale($this->locale); $node = $this->xml->addChild("produit"); /** * Parent id */ $node->addChild("id", $product->getId()); $node->addChild("nom", $product->getTitle()); $node->addChild("url", URL::getInstance()->absoluteUrl("/", ["view" => "product", "product_id" => $product->getId()])); $node->addChild("description-courte", $product->getChapo()); $node->addChild("description", $product->getDescription()); /** * Images URL */ $imagesNode = $node->addChild("images"); /** @var \Thelia\Model\ProductImage $productImage */ foreach ($product->getProductImages() as $productImage) { $imagesNode->addChild("image", URL::getInstance()->absoluteUrl("/shoppingflux/image/" . $productImage->getId())); } /** * Product Brand */ if ($product->getBrand()) { $brand = $product->getBrand(); $brand->setLocale($this->locale); if (!array_key_exists($brandId = $brand->getId(), $cache["brand"])) { $cache["brand"][$brandId] = $brand->getTitle(); } $node->addChild("marque", $cache["brand"][$brandId]); } else { $node->addChild("marque", null); } $node->addChild("url-marque"); /** * Compute breadcrumb */ $category = $product->getCategories()[0]; $category->setLocale($this->locale); if (!array_key_exists($categoryId = $category->getId(), $cache["category"])) { $cache["category"][$categoryId] = $category->getTitle(); $breadcrumb = []; do { $category->setLocale($this->locale); $breadcrumb[] = $category->getTitle(); } while (null !== ($category = CategoryQuery::create()->findPk($category->getParent()))); $reversedBreadcrumb = array_reverse($breadcrumb); $reversedBreadcrumb[] = $product->getTitle(); $cache["breadcrumb"][$categoryId] = implode(" > ", $reversedBreadcrumb); } $node->addChild("rayon", $cache["category"][$categoryId]); $node->addChild("fil-ariane", $cache["breadcrumb"][$categoryId]); /** * Features */ $featuresNode = $node->addChild("caracteristiques"); foreach ($product->getFeatureProducts() as $featureProduct) { if ($featureProduct->getFeatureAv() !== null && $featureProduct->getFeature() !== null) { if (!array_key_exists($featureId = $featureProduct->getFeature()->getId(), $cache["feature"]["title"])) { $featureProduct->getFeatureAv()->setLocale($this->locale); $featureProduct->getFeature()->setLocale($this->locale); $cache["feature"]["title"][$featureId] = trim(preg_replace("#[^a-z0-9_\\-]#i", "_", $featureProduct->getFeature()->getTitle()), "_"); $cache["feature"]["value"][$featureId] = $featureProduct->getFeatureAv()->getTitle(); } $featuresNode->addChild($cache["feature"]["title"][$featureId], $cache["feature"]["value"][$featureId]); } } /** * Compute VAT */ $taxRuleCountry = TaxRuleCountryQuery::create()->filterByTaxRule($product->getTaxRule())->findOne(); $tax = $taxRuleCountry->getTax(); /** @var \Thelia\TaxEngine\TaxType\PricePercentTaxType $taxType*/ $taxType = $tax->getTypeInstance(); if (array_key_exists("percent", $taxRequirements = $taxType->getRequirements())) { $node->addChild("tva", $taxRequirements["percent"]); } /** * Compute product sale elements */ $productSaleElements = $product->getProductSaleElementss(); $psesNode = $node->addChild("declinaisons"); /** @var \Thelia\Model\ProductSaleElements $pse */ foreach ($productSaleElements as $pse) { /** * Fake the cart so that module::getPostage() returns the price * for only one object */ $fakeCartItem->setProductSaleElements($pse); /** * If the object is too heavy, don't export it */ try { $shipping_price = $deliveryModule->getPostage($country); } catch (DeliveryException $e) { continue; } $productPrice = $pse->getPricesByCurrency($currency); $pse->setVirtualColumn("price_PRICE", $productPrice->getPrice()); $pse->setVirtualColumn("price_PROMO_PRICE", $productPrice->getPromoPrice()); $deliveryTimeMin = null; $deliveryTimeMax = null; $pseNode = $psesNode->addChild("declinaison"); /** * Child id */ $pseNode->addChild("id", $product->getId() . "_" . $pse->getId()); $pseNode->addChild("prix-ttc", $pse->getPromo() ? $pse->getPromoPrice() : $pse->getPrice()); $pseNode->addChild("prix-ttc-barre", $pse->getPromo() ? $pse->getPrice() : null); $pseNode->addChild("quantite", $pse->getQuantity()); $pseNode->addChild("ean", $pse->getEanCode()); $pseNode->addChild("poids", $pse->getWeight()); $pseNode->addChild("ecotaxe", $ecotax); $pseNode->addChild("frais-de-port", $shipping_price); $pseNode->addChild("delai-livraison-mini", $deliveryTimeMin); $pseNode->addChild("delai-livraison-maxi", $deliveryTimeMax); $pseAttrNode = $pseNode->addChild("attributs"); /** @var \Thelia\Model\AttributeCombination $attr */ foreach ($pse->getAttributeCombinations() as $attr) { if ($attr->getAttribute() !== null && $attr->getAttributeAv() !== null) { if (!array_key_exists($attributeId = $attr->getAttribute()->getId(), $cache["attribute"]["title"])) { $attr->getAttribute()->setLocale($this->locale); $attr->getAttributeAv()->setLocale($this->locale); $cache["attribute"]["title"][$attributeId] = trim(preg_replace("#[^a-z0-9_\\-]#i", "_", $attr->getAttribute()->getTitle()), "_"); $cache["attribute"]["value"][$attributeId] = $attr->getAttributeAv()->getTitle(); } $pseAttrNode->addChild($cache["attribute"]["title"][$attributeId], $cache["attribute"]["value"][$attributeId]); } } $pseNode->addChild("promo-de"); $pseNode->addChild("promo-a"); } } /** * Then return a well formed string */ $dom = new \DOMDocument("1.0"); $dom->preserveWhiteSpace = false; $dom->formatOutput = true; $dom->loadXML($this->xml->asXML()); return $dom->saveXML(); }
public function testCreateForm() { /** * Run the module class generator for the form */ $generator = new ModulePhpGenerator($this->getSmarty()); $generator->doGenerate($this->event); $this->loadClassFromVfs("TheliaStudioTestModule", false); $this->loadClassFromVfs("Form/ExampleTableCreateForm"); $reflection = new \ReflectionClass("TheliaStudioTestModule\\Form\\ExampleTableCreateForm"); $this->assertTrue($reflection->isSubclassOf("TheliaStudioTestModule\\Form\\Base\\ExampleTableCreateForm")); $this->assertTrue($reflection->isSubclassOf("Thelia\\Form\\BaseForm")); $this->assertTrue($reflection->hasConstant("FORM_NAME")); $this->assertEquals("example_table_create", $reflection->getConstant("FORM_NAME")); /** * Mock the request to build the form */ new Translator(new Container()); $request = new Request(); $session = new Session(new MockArraySessionStorage()); $request->setSession($session); $baseForm = $reflection->newInstance($request); /** @var \Symfony\Component\Form\Form $form */ $form = $baseForm->getForm(); /** * Then test it */ $this->assertTrue($form->has("locale")); $this->assertTrue($form->has("title")); $this->assertTrue($form->has("description")); $this->assertTrue($form->has("chapo")); $this->assertTrue($form->has("postscriptum")); $this->assertTrue($form->has("visible")); $this->assertFalse($form->has("position")); $this->assertFalse($form->has("id")); }