Skip to content
Snippets Groups Projects
Commit 41dc18c9 authored by David Siegfried's avatar David Siegfried Committed by Jan-Hendrik Willms
Browse files

fix functional resource management tests, fixes #1193

Closes #1193

Merge request !709
parent 4510e1d1
No related branches found
No related tags found
No related merge requests found
...@@ -534,6 +534,24 @@ class ResourceManager ...@@ -534,6 +534,24 @@ class ResourceManager
} }
} }
/**
* Check if the coordinate are in appropriate CRSWGS_84 format.
*
* - latitude: up to 2 digits, decimal point, 1 to 10 digits for fraction
* - longitude: up to 3 digits, decimal point, 1 to 10 digits for fraction
* - altitude: up to 5 digits, decimal point, 1 to 10 digits for fraction
*
* @param string $coordinate_string
* @return bool
*/
public static function validateCoordinates(string $coordinate_string): bool
{
return preg_match(
ResourcePropertyDefinition::CRSWGS84_REGEX,
$coordinate_string
);
}
// Static methods for position properties: // Static methods for position properties:
...@@ -557,17 +575,8 @@ class ResourceManager ...@@ -557,17 +575,8 @@ class ResourceManager
$coordinate_string = $property->state; $coordinate_string = $property->state;
//Check, if the coordinate string ends with "CRSWGS_84/" // Show error message when coordinates are invalid
//and if all the numbers are in the appropriate format: if (!self::validateCoordinates($coordinate_string)) {
//- latitude: up to 2 digits, decimal point, 1 to 10 digits for fraction
//- longitude: up to 3 digits, decimal point, 1 to 10 digits for fraction
//- altitude: up to 5 digits, decimal point, 1 to 10 digits for fraction
//before the decimal point. After the decimal point,
//In that case it is a coordinate format we can parse:
if(!preg_match(
ResourcePropertyDefinition::CRSWGS84_REGEX,
$coordinate_string
)) {
PageLayout::postError(_('Die Positionsangabe kann nicht umgewandelt werden, da sie ungültige Daten enthält!')); PageLayout::postError(_('Die Positionsangabe kann nicht umgewandelt werden, da sie ungültige Daten enthält!'));
} }
......
...@@ -46,7 +46,7 @@ class BuildingTest extends \Codeception\Test\Unit ...@@ -46,7 +46,7 @@ class BuildingTest extends \Codeception\Test\Unit
// Workaround old-style Stud.IP-API using $GLOBALS['user'] // Workaround old-style Stud.IP-API using $GLOBALS['user']
$this->oldUser = $GLOBALS['user']; $this->oldUser = $GLOBALS['user'];
$GLOBALS['user'] = new \Seminar_User( $GLOBALS['user'] = new \Seminar_User(
\User::build(['user_id' => 'cli', 'username' => 'cli', 'perms' => 'autor'], false) \User::findByUsername('root@studip')
); );
//As a final step we create the SORM objects for our test cases: //As a final step we create the SORM objects for our test cases:
......
...@@ -49,7 +49,7 @@ class LocationTest extends \Codeception\Test\Unit ...@@ -49,7 +49,7 @@ class LocationTest extends \Codeception\Test\Unit
// Workaround old-style Stud.IP-API using $GLOBALS['user'] // Workaround old-style Stud.IP-API using $GLOBALS['user']
$this->oldUser = $GLOBALS['user']; $this->oldUser = $GLOBALS['user'];
$GLOBALS['user'] = new \Seminar_User( $GLOBALS['user'] = new \Seminar_User(
\User::build(['user_id' => 'cli', 'username' => 'cli', 'perms' => 'autor'], false) \User::findByUsername('root@studip')
); );
//As a final step we create the SORM objects for our test cases: //As a final step we create the SORM objects for our test cases:
......
...@@ -47,7 +47,7 @@ class ResourceAssignmentTest extends \Codeception\Test\Unit ...@@ -47,7 +47,7 @@ class ResourceAssignmentTest extends \Codeception\Test\Unit
// Workaround old-style Stud.IP-API using $GLOBALS['user'] // Workaround old-style Stud.IP-API using $GLOBALS['user']
$this->oldUser = $GLOBALS['user']; $this->oldUser = $GLOBALS['user'];
$GLOBALS['user'] = new \Seminar_User( $GLOBALS['user'] = new \Seminar_User(
\User::build(['user_id' => 'cli', 'username' => 'cli', 'perms' => 'root'], false) \User::findByUsername('root@studip')
); );
$this->oldPerm = $GLOBALS['perm']; $this->oldPerm = $GLOBALS['perm'];
$GLOBALS['perm'] = new \Seminar_Perm(); $GLOBALS['perm'] = new \Seminar_Perm();
......
...@@ -159,7 +159,7 @@ class ResourceCategoryTest extends \Codeception\Test\Unit ...@@ -159,7 +159,7 @@ class ResourceCategoryTest extends \Codeception\Test\Unit
$def = new ResourcePropertyDefinition(); $def = new ResourcePropertyDefinition();
$def->name = 'test'; $def->name = 'test';
$def->type = 'unknown'; $def->type = 'bool';
$def->store(); $def->store();
$prop = $resource_cat->addProperty( $prop = $resource_cat->addProperty(
......
...@@ -28,7 +28,7 @@ class ResourceTest extends \Codeception\Test\Unit ...@@ -28,7 +28,7 @@ class ResourceTest extends \Codeception\Test\Unit
// Workaround old-style Stud.IP-API using $GLOBALS['user'] // Workaround old-style Stud.IP-API using $GLOBALS['user']
$this->oldUser = $GLOBALS['user']; $this->oldUser = $GLOBALS['user'];
$GLOBALS['user'] = new \Seminar_User( $GLOBALS['user'] = new \Seminar_User(
\User::build(['user_id' => 'cli', 'username' => 'cli', 'perms' => 'root'], false) \User::findByUsername('root@studip')
); );
$this->oldPerm = $GLOBALS['perm']; $this->oldPerm = $GLOBALS['perm'];
$GLOBALS['perm'] = new \Seminar_Perm(); $GLOBALS['perm'] = new \Seminar_Perm();
......
...@@ -49,7 +49,7 @@ class RoomTest extends \Codeception\Test\Unit ...@@ -49,7 +49,7 @@ class RoomTest extends \Codeception\Test\Unit
// Workaround old-style Stud.IP-API using $GLOBALS['user'] // Workaround old-style Stud.IP-API using $GLOBALS['user']
$this->oldUser = $GLOBALS['user']; $this->oldUser = $GLOBALS['user'];
$GLOBALS['user'] = new \Seminar_User( $GLOBALS['user'] = new \Seminar_User(
\User::build(['user_id' => 'cli', 'username' => 'cli', 'perms' => 'root'], false) \User::findByUsername('root@studip')
); );
$this->oldPerm = $GLOBALS['perm']; $this->oldPerm = $GLOBALS['perm'];
$GLOBALS['perm'] = new \Seminar_Perm(); $GLOBALS['perm'] = new \Seminar_Perm();
......
...@@ -29,7 +29,7 @@ class ResourceManagerTest extends \Codeception\Test\Unit ...@@ -29,7 +29,7 @@ class ResourceManagerTest extends \Codeception\Test\Unit
// Workaround old-style Stud.IP-API using $GLOBALS['user'] // Workaround old-style Stud.IP-API using $GLOBALS['user']
$this->oldUser = $GLOBALS['user']; $this->oldUser = $GLOBALS['user'];
$GLOBALS['user'] = new \Seminar_User( $GLOBALS['user'] = new \Seminar_User(
\User::build(['user_id' => 'cli', 'username' => 'cli', 'perms' => 'autor'], false) \User::findByUsername('root@studip')
); );
//As a final step we create the SORM objects for our test cases: //As a final step we create the SORM objects for our test cases:
...@@ -299,139 +299,31 @@ class ResourceManagerTest extends \Codeception\Test\Unit ...@@ -299,139 +299,31 @@ class ResourceManagerTest extends \Codeception\Test\Unit
); );
} }
public function testEmptyPositionState() /**
* @dataProvider coordinateProvider
*/
public function testCoordinatesValidation($coordinates)
{ {
$this->expectException(ResourcePropertyStateException::class); $this->assertFalse(ResourceManager::validateCoordinates($coordinates));
$position = new ResourceProperty();
$position->getId();
$position->property_id = $this->position_def->id;
$position->state = '';
ResourceManager::getPositionArray($position);
}
public function testBadLatitudePositionState1()
{
$this->expectException(ResourcePropertyStateException::class);
$position = new ResourceProperty();
$position->getId();
$position->property_id = $this->position_def->id;
$position->state = '14.29302-31.28323-5.292CRSWGS_84/';
ResourceManager::getPositionArray($position);
} }
public function testBadLatitudePositionState2() public static function coordinateProvider(): array
{ {
$this->expectException(ResourcePropertyStateException::class);
$position = new ResourceProperty(); return [
$position->getId(); 'empty' => [''],
$position->property_id = $this->position_def->id;
$position->state = '+14-31.28323-5.292CRSWGS_84/';
ResourceManager::getPositionArray($position); 'bad-latitude-1' => ['14.29302-31.28323-5.292CRSWGS_84/'],
} 'bad-latitude-2' => ['+14-31.28323-5.292CRSWGS_84/'],
'missing-latitude' => ['-31.28323-5.292CRSWGS_84/'],
public function testMissingLatitudePositionState() 'bad-longitude-1' => ['-14.29302-31-5.292CRSWGS_84/'],
{ 'bad-longitude-2' => ['-14.29302-+31.28323-5.292CRSWGS_84/'],
$this->expectException(ResourcePropertyStateException::class);
$position = new ResourceProperty(); 'missing-altitude' => ['-14.29302-31.28323CRSWGS_84/'],
$position->property_id = $this->position_def->id;
$position->state = '-31.28323-5.292CRSWGS_84/';
ResourceManager::getPositionArray($position); 'bad-suffix' => ['-14.29302-31.28323-5.292CRSWGS_84'],
'missing-suffix' => ['-14.29302-31.28323-5.292'],
];
} }
public function testBadLongitudePositionState1()
{
$this->expectException(ResourcePropertyStateException::class);
$position = new ResourceProperty();
$position->property_id = $this->position_def->id;
$position->state = '-14.29302-31-5.292CRSWGS_84/';
ResourceManager::getPositionArray($position);
}
public function testBadLongitudePositionState2()
{
$this->expectException(ResourcePropertyStateException::class);
$position = new ResourceProperty();
$position->property_id = $this->position_def->id;
$position->state = '-14.29302-+31.28323-5.292CRSWGS_84/';
ResourceManager::getPositionArray($position);
}
public function testMissingLongitudePositionState()
{
$this->expectException(ResourcePropertyStateException::class);
$position = new ResourceProperty();
$position->property_id = $this->position_def->id;
$position->state = '-14.29302--5.292CRSWGS_84/';
ResourceManager::getPositionArray($position);
}
public function testBadAltitudePositionState1()
{
$this->expectException(ResourcePropertyStateException::class);
$position = new ResourceProperty();
$position->property_id = $this->position_def->id;
$position->state = '-14.29302-31.28323-+5.292CRSWGS_84/';
ResourceManager::getPositionArray($position);
}
public function testBadAltitudePositionState2()
{
$this->expectException(ResourcePropertyStateException::class);
$position = new ResourceProperty();
$position->property_id = $this->position_def->id;
$position->state = '-14.29302-31.28323+5292CRSWGS_84/';
ResourceManager::getPositionArray($position);
}
public function testMissingAltitudePositionState()
{
$this->expectException(ResourcePropertyStateException::class);
$position = new ResourceProperty();
$position->property_id = $this->position_def->id;
$position->state = '-14.29302-31.28323CRSWGS_84/';
ResourceManager::getPositionArray($position);
}
public function testBadSuffixPositionState()
{
$this->expectException(ResourcePropertyStateException::class);
$position = new ResourceProperty();
$position->property_id = $this->position_def->id;
$position->state = '-14.29302-31.28323-5.292CRSWGS_84';
ResourceManager::getPositionArray($position);
}
public function testMissingSuffixPositionState()
{
$this->expectException(ResourcePropertyStateException::class);
$position = new ResourceProperty();
$position->property_id = $this->position_def->id;
$position->state = '-14.29302-31.28323-5.292';
ResourceManager::getPositionArray($position);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment