Skip to content

Commit

Permalink
Convert tests to PSR-2 coding standards
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberwolf committed Jan 12, 2016
1 parent c4eb629 commit 9b1411b
Show file tree
Hide file tree
Showing 15 changed files with 1,268 additions and 920 deletions.
14 changes: 10 additions & 4 deletions tests/CultureFeed/Cdb/Data/Address/GeoInformationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

class CultureFeed_Cdb_Data_Address_GeoInformationTest extends PHPUnit_Framework_TestCase
{
public function sampleCoordinates() {
public function sampleCoordinates()
{
return array(
array('4,34890', '50,84740'),
array('4,3488', '50,8391'),
Expand All @@ -15,7 +16,8 @@ public function sampleCoordinates() {
* @param string $x
* @param string $y
*/
public function testXYGettersReturnConstructorInjectedValues($x, $y) {
public function testXYGettersReturnConstructorInjectedValues($x, $y)
{
$geo = new CultureFeed_Cdb_Data_Address_GeoInformation($x, $y);

$this->assertEquals($x, $geo->getXCoordinate());
Expand All @@ -28,8 +30,12 @@ public function testXYGettersReturnConstructorInjectedValues($x, $y) {
* @param string $x
* @param string $y
*/
public function testXYGettersReturnSetterInjectedValues($x, $y) {
$geo = new CultureFeed_Cdb_Data_Address_GeoInformation('4,7139', '50,88162');
public function testXYGettersReturnSetterInjectedValues($x, $y)
{
$geo = new CultureFeed_Cdb_Data_Address_GeoInformation(
'4,7139',
'50,88162'
);

$geo->setXCoordinate($x);
$geo->setYCoordinate($y);
Expand Down
29 changes: 21 additions & 8 deletions tests/CultureFeed/Cdb/Data/Address/PhysicalAddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,30 @@

class CultureFeed_Cdb_Data_Address_PhysicalAddressTest extends PHPUnit_Framework_TestCase
{
public function loadSample($fileName) {
public function loadSample($fileName)
{
$sampleDir = __DIR__ . '/samples/PhysicalAddressTest/';
$filePath = $sampleDir . $fileName;

return simplexml_load_file($filePath);
}

public function missingElementSamples() {
public function missingElementSamples()
{
return array(
array('missing_city.xml'),
array('missing_country.xml'),
array('missing_zipcode.xml'),
);
}

public function testParseFull() {
public function testParseFull()
{
$sample = $this->loadSample('full.xml');

$address = CultureFeed_Cdb_Data_Address_PhysicalAddress::parseFromCdbXml($sample);
$address = CultureFeed_Cdb_Data_Address_PhysicalAddress::parseFromCdbXml(
$sample
);

$this->assertEquals('Brussel', $address->getCity());
$this->assertEquals('BE', $address->getCountry());
Expand All @@ -30,15 +35,21 @@ public function testParseFull() {
$this->assertEquals('Sint-Gisleinstraat', $address->getStreet());
$geo = $address->getGeoInformation();

$this->assertInstanceOf('CultureFeed_Cdb_Data_Address_GeoInformation', $geo);
$this->assertInstanceOf(
'CultureFeed_Cdb_Data_Address_GeoInformation',
$geo
);
$this->assertEquals('4,3488', $geo->getXCoordinate());
$this->assertEquals('50,8391', $geo->getYCoordinate());
}

public function testParseMinimal() {
public function testParseMinimal()
{
$sample = $this->loadSample('minimal.xml');

$address = CultureFeed_Cdb_Data_Address_PhysicalAddress::parseFromCdbXml($sample);
$address = CultureFeed_Cdb_Data_Address_PhysicalAddress::parseFromCdbXml(
$sample
);

$this->assertEquals('Brussel', $address->getCity());
$this->assertEquals('BE', $address->getCountry());
Expand All @@ -56,6 +67,8 @@ public function testParseMinimal() {
public function testParseXMLWithMissingElementThrowsException($sampleName)
{
$sample = $this->loadSample($sampleName);
$address = CultureFeed_Cdb_Data_Address_PhysicalAddress::parseFromCdbXml($sample);
$address = CultureFeed_Cdb_Data_Address_PhysicalAddress::parseFromCdbXml(
$sample
);
}
}
60 changes: 32 additions & 28 deletions tests/CultureFeed/Cdb/Data/Calendar/PeriodTest.php
Original file line number Diff line number Diff line change
@@ -1,36 +1,40 @@
<?php

/**
* Created by PhpStorm.
* User: Kristof
* Date: 12/12/13
* Time: 20:31
*/

class CultureFeed_Cdb_Data_Calendar_PeriodTest extends PHPUnit_Framework_TestCase {

public function testAppendToDOM() {
$from = '2013-12-06';
$to = '2013-12-25';
$period = new CultureFeed_Cdb_Data_Calendar_Period($from, $to);

$scheme = new CultureFeed_Cdb_Data_Calendar_Weekscheme();

$scheme->monday()->setOpen();
$scheme->tuesday()->setOpen();
$scheme->wednesday()->setOpen();
$scheme->thursday()->setOpenByAppointment();
$scheme->friday()->setOpen();
$scheme->saturday()->setClosed();
$scheme->sunday()->setClosed();

$period->setWeekScheme($scheme);

$dom = new DOMDocument('1.0', 'utf8');
$root = $dom->createElement('calendar');
$dom->appendChild($root);

$period->appendToDOM($root);

$this->assertXmlStringEqualsXmlFile(__DIR__ . '/samples/period.xml', $dom->saveXML());
}
class CultureFeed_Cdb_Data_Calendar_PeriodTest extends PHPUnit_Framework_TestCase
{
public function testAppendToDOM()
{
$from = '2013-12-06';
$to = '2013-12-25';
$period = new CultureFeed_Cdb_Data_Calendar_Period($from, $to);

$scheme = new CultureFeed_Cdb_Data_Calendar_Weekscheme();

$scheme->monday()->setOpen();
$scheme->tuesday()->setOpen();
$scheme->wednesday()->setOpen();
$scheme->thursday()->setOpenByAppointment();
$scheme->friday()->setOpen();
$scheme->saturday()->setClosed();
$scheme->sunday()->setClosed();

$period->setWeekScheme($scheme);

$dom = new DOMDocument('1.0', 'utf8');
$root = $dom->createElement('calendar');
$dom->appendChild($root);

$period->appendToDOM($root);

$this->assertXmlStringEqualsXmlFile(
__DIR__ . '/samples/period.xml',
$dom->saveXML()
);
}
}
86 changes: 55 additions & 31 deletions tests/CultureFeed/Cdb/Data/Calendar/WeekschemeTest.php
Original file line number Diff line number Diff line change
@@ -1,39 +1,63 @@
<?php

/**
* Created by PhpStorm.
* User: Kristof
* Date: 12/12/13
* Time: 19:46
*/

class CultureFeed_Cdb_Data_Calendar_WeekschemeTest extends PHPUnit_Framework_TestCase {

public function testAppendToDOM() {
$open = CultureFeed_Cdb_Data_Calendar_SchemeDay::SCHEMEDAY_OPEN_TYPE_OPEN;
$closed = CultureFeed_Cdb_Data_Calendar_SchemeDay::SCHEMEDAY_OPEN_TYPE_CLOSED;

$ws = new CultureFeed_Cdb_Data_Calendar_Weekscheme();

/** @var CultureFeed_Cdb_Data_Calendar_SchemeDay[] $days */
$days = array();
$days[] = new CultureFeed_Cdb_Data_Calendar_SchemeDay(CultureFeed_Cdb_Data_Calendar_SchemeDay::MONDAY, $closed);
$days[] = new CultureFeed_Cdb_Data_Calendar_SchemeDay(CultureFeed_Cdb_Data_Calendar_SchemeDay::TUESDAY, $open);
$days[] = new CultureFeed_Cdb_Data_Calendar_SchemeDay(CultureFeed_Cdb_Data_Calendar_SchemeDay::WEDNESDAY, $open);
$days[] = new CultureFeed_Cdb_Data_Calendar_SchemeDay(CultureFeed_Cdb_Data_Calendar_SchemeDay::THURSDAY, $closed);
$days[] = new CultureFeed_Cdb_Data_Calendar_SchemeDay(CultureFeed_Cdb_Data_Calendar_SchemeDay::FRIDAY, $open);
$days[] = new CultureFeed_Cdb_Data_Calendar_SchemeDay(CultureFeed_Cdb_Data_Calendar_SchemeDay::SATURDAY, $open);
$days[] = new CultureFeed_Cdb_Data_Calendar_SchemeDay(CultureFeed_Cdb_Data_Calendar_SchemeDay::SUNDAY, $closed);

foreach ($days as $day) {
$ws->setDay($day->getDayName(), $day);
*/
class CultureFeed_Cdb_Data_Calendar_WeekschemeTest extends PHPUnit_Framework_TestCase
{
public function testAppendToDOM()
{
$open = CultureFeed_Cdb_Data_Calendar_SchemeDay::SCHEMEDAY_OPEN_TYPE_OPEN;
$closed = CultureFeed_Cdb_Data_Calendar_SchemeDay::SCHEMEDAY_OPEN_TYPE_CLOSED;

$ws = new CultureFeed_Cdb_Data_Calendar_Weekscheme();

/** @var CultureFeed_Cdb_Data_Calendar_SchemeDay[] $days */
$days = array();
$days[] = new CultureFeed_Cdb_Data_Calendar_SchemeDay(
CultureFeed_Cdb_Data_Calendar_SchemeDay::MONDAY,
$closed
);
$days[] = new CultureFeed_Cdb_Data_Calendar_SchemeDay(
CultureFeed_Cdb_Data_Calendar_SchemeDay::TUESDAY,
$open
);
$days[] = new CultureFeed_Cdb_Data_Calendar_SchemeDay(
CultureFeed_Cdb_Data_Calendar_SchemeDay::WEDNESDAY,
$open
);
$days[] = new CultureFeed_Cdb_Data_Calendar_SchemeDay(
CultureFeed_Cdb_Data_Calendar_SchemeDay::THURSDAY,
$closed
);
$days[] = new CultureFeed_Cdb_Data_Calendar_SchemeDay(
CultureFeed_Cdb_Data_Calendar_SchemeDay::FRIDAY,
$open
);
$days[] = new CultureFeed_Cdb_Data_Calendar_SchemeDay(
CultureFeed_Cdb_Data_Calendar_SchemeDay::SATURDAY,
$open
);
$days[] = new CultureFeed_Cdb_Data_Calendar_SchemeDay(
CultureFeed_Cdb_Data_Calendar_SchemeDay::SUNDAY,
$closed
);

foreach ($days as $day) {
$ws->setDay($day->getDayName(), $day);
}

$dom = new DOMDocument('1.0', 'utf8');
$root = $dom->createElement('period');
$dom->appendChild($root);
$ws->appendToDOM($root);

$this->assertXmlStringEqualsXmlFile(
__DIR__ . '/samples/weekscheme.xml',
$dom->saveXML()
);
}

$dom = new DOMDocument('1.0', 'utf8');
$root = $dom->createElement('period');
$dom->appendChild($root);
$ws->appendToDOM($root);

$this->assertXmlStringEqualsXmlFile(__DIR__ . '/samples/weekscheme.xml', $dom->saveXML());
}

}
77 changes: 38 additions & 39 deletions tests/CultureFeed/Cdb/Data/EventDetailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,57 @@

class CultureFeed_Cdb_Data_EventDetailTest extends PHPUnit_Framework_TestCase
{
public function testGeneratesMediaElementIfFilesWereAdded()
{
$detail = new CultureFeed_Cdb_Data_EventDetail();

public function testGeneratesMediaElementIfFilesWereAdded()
{
$detail = new CultureFeed_Cdb_Data_EventDetail();
$media = $detail->getMedia();

$media = $detail->getMedia();
$this->assertInstanceOf('\CultureFeed_Cdb_Data_Media', $media);
$this->assertCount(0, $media);

$this->assertInstanceOf('\CultureFeed_Cdb_Data_Media', $media);
$this->assertCount(0, $media);
$file = new CultureFeed_Cdb_Data_File();
$file->setMediaType($file::MEDIA_TYPE_WEBRESOURCE);
$file->setHLink('http://www.cultuurnet.be');

$file = new CultureFeed_Cdb_Data_File();
$file->setMediaType($file::MEDIA_TYPE_WEBRESOURCE);
$file->setHLink('http://www.cultuurnet.be');
$media->add($file);

$media->add($file);
$dom = new DOMDocument();
$eventElement = $dom->createElement('event');
$dom->appendChild($eventElement);
$detail->appendToDOM($eventElement);

$dom = new DOMDocument();
$eventElement = $dom->createElement('event');
$dom->appendChild($eventElement);
$detail->appendToDOM($eventElement);
$xpath = new DOMXPath($dom);

$xpath = new DOMXPath($dom);
$items = $xpath->query('/event/eventdetail');
$this->assertEquals(1, $items->length);

$items = $xpath->query('/event/eventdetail');
$this->assertEquals(1, $items->length);
$items = $xpath->query('/event/eventdetail/media');
$this->assertEquals(1, $items->length);

$items = $xpath->query('/event/eventdetail/media');
$this->assertEquals(1, $items->length);
$items = $xpath->query('/event/eventdetail/media/file');
$this->assertEquals(1, $items->length);
}

$items = $xpath->query('/event/eventdetail/media/file');
$this->assertEquals(1, $items->length);
}
public function testDoesNotGenerateEmptyMediaElement()
{
$detail = new CultureFeed_Cdb_Data_EventDetail();

public function testDoesNotGenerateEmptyMediaElement()
{
$detail = new CultureFeed_Cdb_Data_EventDetail();
$media = $detail->getMedia();

$media = $detail->getMedia();
$this->assertInstanceOf('\CultureFeed_Cdb_Data_Media', $media);
$this->assertCount(0, $media);

$this->assertInstanceOf('\CultureFeed_Cdb_Data_Media', $media);
$this->assertCount(0, $media);
$dom = new DOMDocument();
$eventElement = $dom->createElement('event');
$dom->appendChild($eventElement);
$detail->appendToDOM($eventElement);

$dom = new DOMDocument();
$eventElement = $dom->createElement('event');
$dom->appendChild($eventElement);
$detail->appendToDOM($eventElement);
$xpath = new DOMXPath($dom);
$items = $xpath->query('/event/eventdetail');
$this->assertEquals(1, $items->length);

$xpath = new DOMXPath($dom);
$items = $xpath->query('/event/eventdetail');
$this->assertEquals(1, $items->length);

$items = $xpath->query('/event/eventdetail/media');
$this->assertEquals(0, $items->length);
}
$items = $xpath->query('/event/eventdetail/media');
$this->assertEquals(0, $items->length);
}
}
5 changes: 2 additions & 3 deletions tests/CultureFeed/Cdb/Data/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public function testAppendsSubBrand()
}

/**
* @return DOMXPath
*/
* @return DOMXPath
*/
private function xpathOnMediaWithFileAppended(CultureFeed_Cdb_Data_File $file)
{
$dom = new DOMDocument();
Expand All @@ -98,5 +98,4 @@ public function testGetDescription()

$this->assertEquals($description, $this->file->getDescription());
}

}
Loading

0 comments on commit 9b1411b

Please sign in to comment.