Beispiel #1
0
 public function testRenderLoop()
 {
     $customerId = CustomerQuery::create()->findOne()->getId();
     $this->handler->expects($this->any())->method("buildDataSet")->willReturn($this->handler->renderLoop("address", ["customer" => $customerId]));
     $lang = Lang::getDefaultLanguage();
     $loop = $this->handler->buildDataSet($lang);
     $this->assertInstanceOf("Thelia\\Core\\Template\\Loop\\Address", $loop);
     $data = $this->handler->buildData($lang);
     $addresses = AddressQuery::create()->filterByCustomerId($customerId)->find()->toArray("Id");
     foreach ($data->getData() as $row) {
         $this->assertArrayHasKey("id", $row);
         $this->assertArrayHasKey($row["id"], $addresses);
         $this->assertEquals(count($addresses), $row["loop_total"]);
         $address = $addresses[$row["id"]];
         $this->assertEquals($row["address1"], $address["Address1"]);
         $this->assertEquals($row["address2"], $address["Address2"]);
         $this->assertEquals($row["address3"], $address["Address3"]);
         $this->assertEquals($row["cellphone"], $address["Cellphone"]);
         $this->assertEquals($row["city"], $address["City"]);
         $this->assertEquals($row["company"], $address["Company"]);
         $this->assertEquals($row["country"], $address["CountryId"]);
         $this->assertEquals($row["create_date"], $address["CreatedAt"]);
         $this->assertEquals($row["update_date"], $address["UpdatedAt"]);
         $this->assertEquals($row["firstname"], $address["Firstname"]);
         $this->assertEquals($row["lastname"], $address["Lastname"]);
         $this->assertEquals($row["id"], $address["Id"]);
         $this->assertEquals($row["label"], $address["Label"]);
         $this->assertEquals($row["phone"], $address["Phone"]);
         $this->assertEquals($row["title"], $address["TitleId"]);
         $this->assertEquals($row["zipcode"], $address["Zipcode"]);
     }
 }
Beispiel #2
0
 /**
  * @param  AbstractFormatter      $formatter
  * @param  ExportHandler          $handler
  * @param  AbstractArchiveBuilder $archiveBuilder
  * @param  bool                   $includeImages
  * @param  bool                   $includeDocuments
  * @return Response
  *
  * Processes an export by returning a response with the export's content.
  */
 protected function processExport(AbstractFormatter $formatter, ExportHandler $handler, AbstractArchiveBuilder $archiveBuilder = null, Lang $lang, $includeImages = false, $includeDocuments = false)
 {
     /**
      * Build an event containing the formatter and the handler.
      * Used for specific configuration (e.g: XML node names)
      */
     $event = new ImportExportEvent($formatter, $handler);
     $filename = $formatter::FILENAME . "." . $formatter->getExtension();
     if ($archiveBuilder === null) {
         $data = $handler->buildData($lang);
         $event->setData($data);
         $this->dispatch(TheliaEvents::EXPORT_BEFORE_ENCODE, $event);
         $formattedContent = $formatter->setOrder($handler->getOrder())->encode($data);
         $this->dispatch(TheliaEvents::EXPORT_AFTER_ENCODE, $event->setContent($formattedContent));
         return new Response($event->getContent(), 200, ["Content-Type" => $formatter->getMimeType(), "Content-Disposition" => "attachment; filename=\"" . $filename . "\""]);
     } else {
         $event->setArchiveBuilder($archiveBuilder);
         if ($includeImages && $handler instanceof ImagesExportInterface) {
             $this->processExportImages($handler, $archiveBuilder);
             $handler->setImageExport(true);
         }
         if ($includeDocuments && $handler instanceof DocumentsExportInterface) {
             $this->processExportDocuments($handler, $archiveBuilder);
             $handler->setDocumentExport(true);
         }
         $data = $handler->buildData($lang)->setLang($lang);
         $this->dispatch(TheliaEvents::EXPORT_BEFORE_ENCODE, $event);
         $formattedContent = $formatter->setOrder($handler->getOrder())->encode($data);
         $this->dispatch(TheliaEvents::EXPORT_AFTER_ENCODE, $event->setContent($formattedContent));
         $archiveBuilder->addFileFromString($event->getContent(), $filename);
         return $archiveBuilder->buildArchiveResponse($formatter::FILENAME);
     }
 }