Skip to content

Commit

Permalink
Add some new types (#5)
Browse files Browse the repository at this point in the history
* Add some new types

* Code style

* Stop being strict about covers annotation

* Add tests for the new classes
  • Loading branch information
eiriksm committed Nov 3, 2020
1 parent 37e8c98 commit cb5d835
Show file tree
Hide file tree
Showing 7 changed files with 202 additions and 6 deletions.
1 change: 0 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
forceCoversAnnotation="true"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
Expand Down
13 changes: 9 additions & 4 deletions src/AdType.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ abstract class AdType extends XmlBase implements AdTypeInterface

protected $adBody;

/**
* @var \DOMElement[]
*/
protected $customTags;

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -157,16 +162,16 @@ public function __construct($partner_id, $provider)
*/
public function __set($name, $value)
{
if ($name == 'DESCRIPTION') {
// This is CDATA for sure.
if ($name === 'DESCRIPTION') {
// This is CDATA for sure.
$value = $this->dom->createCDATASection($value);
}
if (!isset($this->customTags[$name])) {
$this->customTags[$name] = $this->dom->createElement($name);
$this->adBody->appendChild($this->customTags[$name]);
}
if ($name == 'DESCRIPTION') {
// This is CDATA for sure.
if ($name === 'DESCRIPTION') {
// This is CDATA for sure.
$this->customTags[$name]->appendChild($value);
} else {
$this->customTags[$name]->nodeValue = $value;
Expand Down
17 changes: 16 additions & 1 deletion src/AdTypes/CarXml.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CarXml extends AdType
createMotorPriceElements as protected createMotorPriceElementsTrait;
}

protected $dtd = 'http://www.iad.no/dtd/IADIF-car20.dtd';
protected $dtd = 'http://www.finn.no/dtd/IADIF-car33.dtd';

protected $documentType = 'IAD.IF.CAR';

Expand Down Expand Up @@ -47,6 +47,7 @@ public function __construct($partner_id, $provider)
$this->NO_OF_OWNERS = '';
$this->REGNO = '';
$this->initializeContact();
$this->contactBody->removeAttribute('PHONESALESRESERVATION');
$this->CAR_LOCATION = '';
$this->CAR_SALESFORM = '';
}
Expand All @@ -71,4 +72,18 @@ public function createMotorPriceElements($vat_attribute = false)
}
$this->priceBody->setAttribute('REGISTRATIONTAX_INCLUDED', 'yes');
}

public function setAdType($type)
{
$this->CAR_SALESFORM = $type;
}

public function setRegistrationNumber($number)
{
$this->REGNO = $number;
}

public function setPhoneSalesReservation($reservation = true)
{
}
}
85 changes: 85 additions & 0 deletions src/AdTypes/McXml.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

namespace eiriksm\FinnTransfer\AdTypes;

use eiriksm\FinnTransfer\AdType;
use eiriksm\FinnTransfer\Traits\ModelPropertyTrait;
use eiriksm\FinnTransfer\Traits\MotorPriceTrait;

class McXml extends AdType
{
use ModelPropertyTrait;
use MotorPriceTrait {
setMotorPrice as protected setMotorPriceTrait;
createMotorPriceElements as protected createMotorPriceElementsTrait;
}

protected $dtd = 'http://www.finn.no/dtd/IADIF-mc76.dtd';

protected $documentType = 'IAD.IF.MC';

protected $adBodyTag = 'MC';

public function __construct($partner_id, $provider)
{
parent::__construct($partner_id, $provider);
$this->MC_CONDITION = '';
$this->createModelProperty('MC_MODEL');
$this->adBody->appendChild($this->modelOuterBody);
$this->MC_MAIN_CATEGORY = '';
$this->MC_CATEGORY = '';
$this->YEAR_MODEL = '';
$this->MILEAGE = '';
$this->createMotorPriceElements();
$this->EXTERIOR_COLOUR = '';
$this->MC_EQUIPMENT = '';
$this->createEngineElements();
$this->WEIGHT = '';
$this->DESCRIPTION = '';
$this->createMoreInfoElements();
$this->NO_OF_OWNERS = '';
$this->REGNO = '';
$this->MC_WARRANTY = '';
$this->WARRANTY_DURATION = '';
$this->WARRANTY_DISTANCE = '';
$this->MC_CONDITION_REPORT = '';
$this->VIDEO_URL = '';
$this->initializeContact();
$this->contactBody->removeAttribute('PHONESALESRESERVATION');
$this->contactBody->removeChild($this->contactFaxBody);
$this->contactBody->removeChild($this->contactURLBody);
}

public function setContactFax($fax)
{
}

public function setContactUrl($url)
{
}

public function setSegment($value)
{
$this->MC_MAIN_CATEGORY = $value;
}

public function createMotorPriceElements($vat_attribute = false)
{
$this->createMotorPriceElementsTrait($vat_attribute);
$this->priceBody->removeChild($this->priceCurrencyBody);
}

public function setAdType($type)
{
$this->CAR_SALESFORM = $type;
}

public function setRegistrationNumber($number)
{
$this->REGNO = $number;
}

public function setPhoneSalesReservation($reservation = true)
{
}
}
70 changes: 70 additions & 0 deletions src/AdTypes/TorgetXml.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

namespace eiriksm\FinnTransfer\AdTypes;

use eiriksm\FinnTransfer\AdType;
use eiriksm\FinnTransfer\Traits\ModelPropertyTrait;
use eiriksm\FinnTransfer\Traits\MotorPriceTrait;

class TorgetXml extends AdType
{

protected $dtd = 'https://www.finn.no/dtd/IADIF-BitsandPieces62.dtd';

protected $documentType = 'IAD.IF.BITSPIECES';

protected $adBodyTag = 'SALESOBJECT';

/**
* @var \DOMElement
*/
protected $categoryBody;

/**
* @var \DOMElement
*/
protected $productCategory;

/**
* @var \DOMElement
*/
protected $anonContactBody;
protected $anonReference;
protected $anonInfo;

public function __construct($partner_id, $provider)
{
parent::__construct($partner_id, $provider);
$this->categoryBody = $this->dom->createElement('CATEGORY');
$this->productCategory = $this->dom->createElement('PRODUCTCATEGORY');
$this->categoryBody->appendChild($this->productCategory);
$this->adBody->appendChild($this->categoryBody);
$this->GENERIC_ATTRIBUTE = '';
$this->customTags['GENERIC_ATTRIBUTE']->setAttribute('XMLNAME', '');
$this->DESCRIPTION = '';
$this->ITEM_CONDITION = '';
$this->createMoreInfoElements();
$this->PRICE = '';
$this->initializeContact();
$this->TRANSPORT_TERMS = '';
$this->PAYMENT_TERMS = '';
$this->anonContactBody = $this->dom->createElement('ANONYMOUS_CONTACT');
$this->anonReference = $this->dom->createElement('REFERENCE');
$this->anonContactBody->appendChild($this->anonReference);
$this->anonInfo = $this->dom->createElement('INFO');
$this->anonContactBody->appendChild($this->anonInfo);
}

public function setProductCategory($category)
{
$this->productCategory->nodeValue = $category;
}

public function setMotorPrice($number, $currency = 'NOK')
{
}

public function setIncludingMva($includes)
{
}
}
11 changes: 11 additions & 0 deletions tests/AdTypes/McXmlTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace eiriksm\FinnTransfer\Tests\AdTypes;

use eiriksm\FinnTransfer\AdTypes\McXml;

class McXmlTest extends AdTypeTestBase
{

protected $className = McXml::class;
}
11 changes: 11 additions & 0 deletions tests/AdTypes/TorgetXmlTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace eiriksm\FinnTransfer\Tests\AdTypes;

use eiriksm\FinnTransfer\AdTypes\TorgetXml;

class TorgetXmlTest extends AdTypeTestBase
{

protected $className = TorgetXml::class;
}

0 comments on commit cb5d835

Please sign in to comment.