/** * Class constructor. */ public function __construct() { $this->manager = Shopware()->Models(); $this->repository = $this->manager->getRepository('Shopware\\Models\\Category\\Category'); $this->blogRepository = $this->manager->getRepository('Shopware\\Models\\Blog\\Blog'); $this->baseCategory = Shopware()->Shop()->getCategory(); }
/** * test the feed list */ public function testGetFeeds() { //delete old data $feeds = $this->repository->findBy(array('hash' => '0805bbb935327228edb5374083b81416')); foreach ($feeds as $testFeed) { $this->manager->remove($testFeed); } $this->manager->flush(); $feed = $this->createDummy(); /** @var Enlight_Controller_Response_ResponseTestCase */ $this->dispatch('backend/ProductFeed/getFeeds?page=1&start=0&limit=30'); $this->assertTrue($this->View()->success); $returnData = $this->View()->data; $this->assertNotEmpty($returnData); $this->assertGreaterThan(0, $this->View()->totalCount); $foundDummyFeed = array(); foreach ($returnData as $feedData) { if ($feedData["name"] == $feed->getName()) { $foundDummyFeed = $feedData; } } $this->assertEquals($feed->getId(), $foundDummyFeed["id"]); $this->manager->remove($feed); $this->manager->flush(); }
/** * Class constructor. */ public function __construct() { $this->manager = Shopware()->Models(); $this->repository = $this->manager->getRepository('Shopware\\Models\\Category\\Category'); $this->baseUrl = Shopware()->Config()->get('baseFile') . '?sViewport=cat&sCategory='; $this->blogBaseUrl = Shopware()->Config()->get('baseFile') . '?sViewport=blog&sCategory='; $this->baseId = (int) Shopware()->Shop()->get('parentID'); $this->customerGroupId = (int) Shopware()->Modules()->System()->sSYSTEM->sUSERGROUPDATA['id']; }
public function createOrder() { $paymentStatusOpen = $this->em->getReference('\\Shopware\\Models\\Order\\Status', 17); $orderStatusOpen = $this->em->getReference('\\Shopware\\Models\\Order\\Status', 0); $paymentDebit = $this->em->getReference('\\Shopware\\Models\\Payment\\Payment', 2); $dispatchDefault = $this->em->getReference('\\Shopware\\Models\\Dispatch\\Dispatch', 9); $defaultShop = $this->em->getReference('\\Shopware\\Models\\Shop\\Shop', 1); $partner = new \Shopware\Models\Partner\Partner(); $partner->setCompany("Dummy"); $partner->setIdCode("Dummy"); $partner->setDate(new \DateTime()); $partner->setContact('Dummy'); $partner->setStreet('Dummy'); $partner->setStreetNumber('Dummy'); $partner->setZipCode('Dummy'); $partner->setCity('Dummy'); $partner->setPhone('Dummy'); $partner->setFax('Dummy'); $partner->setCountryName('Dummy'); $partner->setEmail('Dummy'); $partner->setWeb('Dummy'); $partner->setProfile('Dummy'); $this->em->persist($partner); $order = new \Shopware\Models\Order\Order(); $order->setNumber('abc'); $order->setPaymentStatus($paymentStatusOpen); $order->setOrderStatus($orderStatusOpen); $order->setPayment($paymentDebit); $order->setDispatch($dispatchDefault); $order->setPartner($partner); $order->setShop($defaultShop); $order->setInvoiceAmount(5); $order->setInvoiceAmountNet(5); $order->setInvoiceShipping(5); $order->setInvoiceShippingNet(5); $order->setTransactionId(5); $order->setComment('Dummy'); $order->setCustomerComment('Dummy'); $order->setInternalComment('Dummy'); $order->setNet(true); $order->setTaxFree(false); $order->setTemporaryId(5); $order->setReferer('Dummy'); $order->setTrackingCode("Dummy"); $order->setLanguageIso("Dummy"); $order->setCurrency("EUR"); $order->setCurrencyFactor(5); $order->setRemoteAddress("127.0.0.1"); return $order; }
/** * test getList controller action */ public function testGetList() { //delete old data $repositoryData = $this->repository->findBy(array('name' => $this->dummyData["name"])); foreach ($repositoryData as $testDummy) { $this->manager->remove($testDummy); } $this->manager->flush(); $dummy = $this->createDummy(); /** @var Enlight_Controller_Response_ResponseTestCase */ $params["node"] = 1; $this->Request()->setParams($params); $this->dispatch('backend/Category/getList'); $this->assertTrue($this->View()->success); $returnData = $this->View()->data; $this->assertNotEmpty($returnData); $this->assertGreaterThan(0, $this->View()->total); $foundDummy = array(); foreach ($returnData as $dummyData) { if ($dummyData["name"] == $dummy->getName()) { $foundDummy = $dummyData; } } $this->assertTrue(!empty($foundDummy)); $this->manager->remove($dummy); $this->manager->flush(); }
/** * @param array $category * @return string */ private function getCategoryCanonicalParams($category) { $request = $this->frontController->Request(); $page = $request->getQuery('sPage'); $emotion = $this->manager->getRepository('Shopware\\Models\\Emotion\\Emotion')->getCategoryBaseEmotionsQuery($category['id'])->getArrayResult(); $canonicalParams = array('sViewport' => $category['blog'] ? 'blog' : 'cat', 'sCategory' => $category['id']); if ($this->config->get('seoIndexPaginationLinks') && (!$emotion || $page)) { $canonicalParams['sPage'] = $page ?: 1; } return $canonicalParams; }
/** * Test case */ public function testFormShouldBePersisted() { $form = new Form(); $form->fromArray($this->testData); $this->em->persist($form); $this->em->flush(); $formId = $form->getId(); // remove form from entity manager $this->em->detach($form); unset($form); $form = $this->repo->find($formId); foreach ($this->testData as $fieldname => $value) { $getMethod = 'get' . ucfirst($fieldname); $this->assertEquals($form->{$getMethod}(), $value); } }
/** * Test case */ public function testShouldBePersisted() { $snippet = new Snippet(); $snippet->fromArray($this->testData); $this->em->persist($snippet); $this->em->flush(); $snippetId = $snippet->getId(); // remove from entity manager $this->em->detach($snippet); unset($snippet); $snippet = $this->repo->find($snippetId); foreach ($this->testData as $fieldname => $value) { $getMethod = 'get' . ucfirst($fieldname); $this->assertEquals($snippet->{$getMethod}(), $value); } $this->assertInstanceOf('\\DateTime', $snippet->getCreated()); $this->assertInstanceOf('\\DateTime', $snippet->getUpdated()); }
public function testEsdShouldBePersisted() { $esd = new Esd(); $articleDetail = Shopware()->Models()->getRepository('Shopware\\Models\\Article\\Detail')->findOneBy(array('active' => true)); $esd->setArticleDetail($articleDetail); $esd->fromArray($this->testData); $this->em->persist($esd); $this->em->flush(); $esdId = $esd->getId(); // remove esd from entity manager $this->em->detach($esd); unset($esd); $esd = $this->repo->find($esdId); foreach ($this->testData as $fieldname => $value) { $getMethod = 'get' . ucfirst($fieldname); $this->assertEquals($esd->{$getMethod}(), $value); } $this->assertInstanceOf('\\DateTime', $esd->getDate()); }
/** * Test saveAction controller action - Update an existing customer * * @depends testAddCustomerPaymentDataWithDebit */ public function testUpdateCustomerPaymentDataWithSepa($dummyDataId) { $dummyData = $this->repository->find($dummyDataId); $sepa = $this->manager->getRepository('Shopware\\Models\\Payment\\Payment')->findOneBy(array('name' => 'sepa')); $debit = $this->manager->getRepository('Shopware\\Models\\Payment\\Payment')->findOneBy(array('name' => 'debit')); $this->assertEquals($debit->getId(), $dummyData->getPaymentId()); $this->assertCount(1, $dummyData->getPaymentData()->toArray()); $params = array('id' => $dummyData->getId(), 'paymentId' => $sepa->getId(), 'paymentData' => array(array('accountHolder' => '', 'accountNumber' => '', 'bankCode' => '', 'bankName' => 'European bank name', 'bic' => '123bic312', 'iban' => '456iban654', 'useBillingData' => true))); $this->Request()->setMethod('POST')->setPost($params); $this->dispatch('/backend/Customer/save'); $jsonBody = $this->View()->getAssign(); $this->assertTrue($this->View()->success); $this->assertEquals($sepa->getId(), $jsonBody['data']['paymentId']); $this->manager->refresh($dummyData); $this->assertEquals($sepa->getId(), $dummyData->getPaymentId()); $paymentDataArray = $dummyData->getPaymentData()->toArray(); $this->assertCount(2, $paymentDataArray); // Old debit payment data is still there, it's just not used currently /** @var \Shopware\Models\Customer\PaymentData $paymentData */ $paymentData = array_shift($paymentDataArray); $this->assertInstanceOf('\\Shopware\\Models\\Customer\\PaymentData', $paymentData); $this->assertEquals('Account Holder Name', $paymentData->getAccountHolder()); $this->assertEquals('1234567890', $paymentData->getAccountNumber()); $this->assertEquals('2345678901', $paymentData->getBankCode()); $this->assertEquals('Bank name', $paymentData->getBankName()); $this->assertEmpty($paymentData->getBic()); $this->assertEmpty($paymentData->getIban()); $this->assertFalse($paymentData->getUseBillingData()); // New SEPA data /** @var \Shopware\Models\Customer\PaymentData $paymentData */ $paymentData = array_shift($paymentDataArray); $this->assertInstanceOf('\\Shopware\\Models\\Customer\\PaymentData', $paymentData); $this->assertEmpty($paymentData->getAccountHolder()); $this->assertEmpty($paymentData->getAccountNumber()); $this->assertEmpty($paymentData->getBankCode()); $this->assertEquals('European bank name', $paymentData->getBankName()); $this->assertEquals('123bic312', $paymentData->getBic()); $this->assertEquals('456iban654', $paymentData->getIban()); $this->assertTrue($paymentData->getUseBillingData()); $this->manager->remove($dummyData); $this->manager->flush(); }
/** * Testcase */ public function testMailShouldBePersisted() { $mail = new Mail(); $mail->fromArray($this->testData); $this->em->persist($mail); $this->em->flush(); $mailId = $mail->getId(); // remove mail from entity manager $this->em->detach($mail); unset($mail); $mail = $this->repo->find($mailId); foreach ($this->testData as $fieldname => $value) { if (substr($fieldname, 0, 2) == 'is') { $getMethod = $fieldname; } else { $getMethod = 'get' . ucfirst($fieldname); } $this->assertEquals($mail->{$getMethod}(), $value); } }
/** * test the voucherCode validation methods with the created voucher * * @depends testAddVoucher */ public function testValidateVoucherCode() { $params = array(); $voucherModel = $this->createDummy(false); $voucherData = Shopware()->Models()->toArray($voucherModel); $params["value"] = $voucherData["voucherCode"]; $params["param"] = $voucherData["id"]; $this->Request()->setParams($params); $this->dispatch('backend/voucher/validateVoucherCode'); $this->assertEquals(1, $this->Response()->getBody()); $this->Request()->clearParams(); $this->Response()->clearBody(); $params["value"] = $voucherData["voucherCode"]; //test with an unknown voucher id $params["param"] = 416531; $this->Request()->setParams($params); $this->dispatch('backend/voucher/validateVoucherCode'); $this->assertEmpty($this->Response()->getBody()); $this->manager->remove($voucherModel); $this->manager->flush(); }
/** * test validateTrackingCode controller action * * @depends testSavePartner * @param $id * @return $id | dummy id */ public function testValidateTrackingCode($id) { $params["value"] = "31337"; $params["param"] = $id; $this->Request()->setParams($params); $this->Response()->clearBody(); $this->dispatch('backend/Partner/validateTrackingCode'); $body = $this->Response()->getBody(); $this->assertEquals("1", $body); $newDummy = $this->createDummy(); $this->Response()->clearBody(); $params["value"] = "31337"; $params["param"] = $newDummy->getId(); $this->Request()->setParams($params); $this->dispatch('backend/Partner/validateTrackingCode'); $body = $this->Response()->getBody(); $this->assertTrue(empty($body)); //delete the new dummy $this->manager->remove($newDummy); $this->manager->flush(); return $id; }
/** * Init doctrine method * * @return Shopware\Components\Model\ModelManager */ public function initModels() { /** @var $config \Doctrine\ORM\Configuration */ $config = $this->getResource('ModelConfig'); $cacheResource = $this->getResource('Cache'); // Check if native Doctrine ApcCache may be used if ($cacheResource->getBackend() instanceof Zend_Cache_Backend_Apc) { $cache = new Doctrine\Common\Cache\ApcCache(); } else { $cache = new Shopware\Components\Model\Cache($cacheResource); } // register standard doctrine annotations Doctrine\Common\Annotations\AnnotationRegistry::registerFile( 'Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php' ); // register symfony validation annotions Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespace( 'Symfony\Component\Validator\Constraint' ); // register gedmo annotions Doctrine\Common\Annotations\AnnotationRegistry::registerFile( 'Gedmo/Mapping/Annotation/All.php' ); $cachedAnnotationReader = new Doctrine\Common\Annotations\CachedReader( new Doctrine\Common\Annotations\AnnotationReader, $cache ); $annotationDriver = new Doctrine\ORM\Mapping\Driver\AnnotationDriver( $cachedAnnotationReader, array( $this->Application()->Loader()->isReadable('Gedmo/Tree/Entity/MappedSuperclass'), $this->Application()->AppPath('Models') )); // create a driver chain for metadata reading $driverChain = new Doctrine\ORM\Mapping\Driver\DriverChain(); // register annotation driver for our application $driverChain->addDriver($annotationDriver, 'Gedmo'); $driverChain->addDriver($annotationDriver, 'Shopware\\Models\\'); $driverChain->addDriver($annotationDriver, 'Shopware\\CustomModels\\'); $this->registerResource('ModelAnnotations', $annotationDriver); $config->setMetadataDriverImpl($driverChain); // Create event Manager $eventManager = new \Doctrine\Common\EventManager(); $treeListener = new Gedmo\Tree\TreeListener; $treeListener->setAnnotationReader($cachedAnnotationReader); $eventManager->addEventSubscriber($treeListener); // Create new shopware event subscriber to handle the entity lifecycle events. $liveCycleSubscriber = new \Shopware\Components\Model\EventSubscriber( $this->Application()->Events() ); $eventManager->addEventSubscriber($liveCycleSubscriber); // now create the entity manager and use the connection // settings we defined in our application.ini $conn = \Doctrine\DBAL\DriverManager::getConnection( array('pdo' => $this->Application()->Db()->getConnection()), $config, $eventManager ); $entityManager = Shopware\Components\Model\ModelManager::create($conn, $config, $eventManager); //if (!is_readable(rtrim($config->getProxyDir(), '/') . '/__CG__ShopwareModelsShopShop.php')) { // $metadata = $entityManager->getMetadataFactory()->getAllMetadata(); // $proxyFactory = $entityManager->getProxyFactory(); // $proxyFactory->generateProxyClasses($metadata); //} return $entityManager; }