GOV/Webservice/PHP/GovToolsTest.php
< GOV • Webservice • PHP
Zur Navigation springen
Zur Suche springen
<?php
require_once 'PHPUnit/Framework.php';
require_once 'GovTools.php';
class GovToolsTest extends PHPUnit_Framework_TestCase {
function testNormalizeNames_BeginYear() {
$place->name->value = 'foobar';
$place->name->lang = 'deu';
$place->name->{'begin-year'} = 1900;
GovTools::normalizeNames($place);
$this->assertEquals( 0, $place->name[0]->begin->precision );
$this->assertEquals( 2415021, $place->name[0]->begin->jd);
}
function testNormalizeNames_EndYear() {
$place->name->value = 'foobar';
$place->name->lang = 'deu';
$place->name->{'end-year'} = 1900;
GovTools::normalizeNames($place);
$this->assertEquals( 0, $place->name[0]->end->precision );
$this->assertEquals( 2415021, $place->name[0]->end->jd);
}
function testNormalizeNames_ArrayOfNames() {
$place->name[0]->value = 'foo';
$place->name[0]->lang = 'deu';
$place->name[0]->{'begin-year'} = 1900;
$place->name[1]->value = 'bar';
$place->name[1]->lang = 'deu';
$place->name[1]->{'end-year'} = 1900;
GovTools::normalizeNames($place);
$this->assertEquals( 0, $place->name[0]->begin->precision );
$this->assertEquals( 2415021, $place->name[0]->begin->jd);
$this->assertEquals( 0, $place->name[1]->end->precision );
$this->assertEquals( 2415021, $place->name[1]->end->jd);
}
/**
* The most simple case, only one name.
*/
function testGetName_OnlyOne() {
$place->name->value = 'foobar';
$place->name->lang = 'deu';
$result = GovTools::getName($place, 2455106, 'deu' );
$this->assertEquals('foobar', $result);
}
/**
* Several names (without time) but with different languages.
*/
function testGetName_MultipleLanguages() {
$place->name[0]->value = 'foobar';
$place->name[0]->lang = 'fre';
$place->name[1]->value = 'name eng';
$place->name[1]->lang = 'eng';
$place->name[2]->value = 'name pol';
$place->name[2]->lang = 'pol';
$result = GovTools::getName($place, 2455106, 'deu' );
$this->assertEquals('foobar', $result);
}
/**
* The place has only a name in a different language.
*/
function testGetName_DifferentLanguage() {
$place->name->value = 'foobar';
$place->name->lang = 'fre';
$result = GovTools::getName($place, 2455106, 'deu' );
$this->assertEquals('foobar', $result);
}
/**
* The place has an old and a new name
*/
function testGetName_OldAndNew() {
$place->name[0]->value = 'old';
$place->name[0]->lang = 'deu';
$place->name[0]->{'end-year'} = 1900;
$place->name[1]->value = 'new';
$place->name[1]->lang = 'deu';
$place->name[1]->{'begin-year'} = 1900;
$result = GovTools::getName($place, 2455106, 'deu' );
$this->assertEquals('new', $result);
}
/**
* The place has an old and a new name
*/
function testGetName_OldAndNew_WithDay() {
$place->name[0]->value = 'old';
$place->name[0]->lang = 'deu';
$place->name[0]->end->jd = 2415021;
$place->name[0]->end->precision = 2;
$place->name[1]->value = 'new';
$place->name[1]->lang = 'deu';
$place->name[1]->begin->jd = 2415021;
$place->name[1]->begin->precision = 2;
$result = GovTools::getName($place, 2455106, 'deu' );
$this->assertEquals('new', $result);
}
/**
* There are three names recorded for the object, one without a time (the common name)
* and two old names with a year specified.
*
* heißt (auf deu) Garding,
* heißt 1438 (auf deu) Gerdingen,
* heißt 1509 (auf deu) Gardingk,
*
*/
function testGetName_TwoSingleYears() {
$place->name[0]->value = 'Garding';
$place->name[0]->lang = 'deu';
$place->name[1]->value = 'Gerdingen';
$place->name[1]->lang = 'deu';
$place->name[1]->year = 1438;
$place->name[2]->value = 'Gardingk';
$place->name[2]->lang = 'deu';
$place->name[2]->year = 1590;
$result = GovTools::getName($place, 2454287, 'deu');
$this->assertEquals('Garding', $result);
}
}
?>