/** * Build rate request * * @return void */ protected function buildRequest() { $package = new Child('Package'); $package->setAttributes('ID', '1ST'); $package->addChild(new Child('Service', 'ALL'))->addChild(new Child('ZipOrigination', $this->shipFrom['ZipOrigination']))->addChild(new Child('ZipDestination', $this->shipTo['ZipDestination']))->addChild(new Child('Pounds', $this->weight['Pounds']))->addChild(new Child('Ounces', $this->weight['Ounces']))->addChild(new Child('Container', $this->container))->addChild(new Child('Size', $this->containerSize)); if (null !== $this->dimensions['Length'] && null !== $this->dimensions['Width'] && null !== $this->dimensions['Height']) { $package->addChild(new Child('Width', $this->dimensions['Width']))->addChild(new Child('Length', $this->dimensions['Length']))->addChild(new Child('Height', $this->dimensions['Height'])); if (null == $this->dimensions['Girth']) { $this->dimensions['Girth'] = 2 * $this->dimensions['Width'] + 2 * $this->dimensions['Height']; } $package->addChild(new Child('Girth', $this->dimensions['Girth'])); } $package->addChild(new Child('Machinable', $this->machinable))->addChild(new Child('DropOffTime', '12:00'))->addChild(new Child('ShipDate', date('Y-m-d'))); $this->request->addChild($package); }
/** * Build rate request * * @return void */ protected function buildRateRequest() { $rating = new Child('RatingServiceSelectionRequest'); $request = new Child('Request'); $transaction = new Child('TransactionReference'); $pickup = new Child('PickupType'); $shipment = new Child('Shipment'); $customer = new Child('CustomerContext', 'Rating and Service'); $xpci = new Child('XpciVersion', '1.0'); $requestAction = new Child('RequestAction', 'Rate'); $requestOption = new Child('RequestOption', 'Shop'); $transaction->addChild($customer)->addChild($xpci); $request->addChild($transaction)->addChild($requestAction)->addChild($requestOption); $pickup->addChild(new Child('Code', $this->pickupType))->addChild(new Child('Description', self::$pickupTypes[$this->pickupType])); $shipment->addChild(new Child('Description', 'Rate')); $shipper = new Child('Shipper'); $shipper->addChild(new Child('ShipperNumber', $this->userId)); $shipTo = new Child('ShipTo'); $shipFrom = new Child('ShipFrom'); if (null !== $this->shipTo['CompanyName']) { $shipTo->addChild(new Child('CompanyName', $this->shipTo['CompanyName'])); } if (null !== $this->shipFrom['CompanyName']) { $shipFrom->addChild(new Child('CompanyName', $this->shipFrom['CompanyName'])); } $shipToAddress = new Child('Address'); foreach ($this->shipTo as $key => $value) { if ($key !== 'CompanyName') { $shipToAddress->addChild(new Child($key, $value)); } } $shipFromAddress = new Child('Address'); foreach ($this->shipFrom as $key => $value) { if ($key !== 'CompanyName') { $shipFromAddress->addChild(new Child($key, $value)); } } $shipTo->addChild($shipToAddress); $shipFrom->addChild($shipFromAddress); $shipper->addChild($shipFromAddress); $service = new Child('Service'); $service->addChild(new Child('Code', $this->service))->addChild(new Child('Description', self::$services[$this->service])); $package = new Child('Package'); $packageType = new Child('PackagingType'); $packageType->addChild(new Child('Code', $this->packageType))->addChild(new Child('Description', self::$packagingTypes[$this->packageType])); $package->addChild($packageType)->addChild(new Child('Description', 'Rate')); if (null !== $this->dimensions['Length'] && null !== $this->dimensions['Width'] && null !== $this->dimensions['Height']) { $dimensions = new Child('Dimensions'); $unit = new Child('UnitOfMeasurement'); $unit->addChild(new Child('Code', $this->dimensions['UnitOfMeasurement'])); $dimensions->addChild($unit)->addChild(new Child('Length', $this->dimensions['Length']))->addChild(new Child('Width', $this->dimensions['Width']))->addChild(new Child('Height', $this->dimensions['Height'])); $package->addChild($dimensions); } $weight = new Child('PackageWeight'); $unit = new Child('UnitOfMeasurement'); $unit->addChild(new Child('Code', $this->weight['UnitOfMeasurement'])); $weight->addChild($unit)->addChild(new Child('Weight', $this->weight['Weight'])); $package->addChild($weight); $shipment->addChild($shipper)->addChild($shipTo)->addChild($shipFrom)->addChild($service)->addChild($package); $rating->addChild($request)->addChild($pickup)->addChild($shipment); $this->rateRequest->addChild($rating); }
public function testRender() { $d = new Dom(Dom::XHTML11, 'utf-8', new Child('p', 'This is another paragraph')); $d->addChild(new Child('p', 'This is a paragraph')); $code = $d->render(true); ob_start(); $d->render(); $output = ob_get_clean(); $this->assertContains('<p>', $code); $this->assertContains('<p>', $output); }