diff --git a/lib/models/resources/ResourcePropertyDefinition.class.php b/lib/models/resources/ResourcePropertyDefinition.class.php index c039459dad65ce5dad0309b6feda436abf3d8642..37fa89b95d3bed5133a3a2ec56e93809e4194104 100644 --- a/lib/models/resources/ResourcePropertyDefinition.class.php +++ b/lib/models/resources/ResourcePropertyDefinition.class.php @@ -30,7 +30,7 @@ * @property string $info_label database column * @property bool $searchable database column * 0 = not searchable, 1 = searchable - * @property string $range_search database column: Whether a search field + * @property bool $range_search database column: Whether a search field * for this property shall display a range selector (1) or not (0). * Setting this attribute is only useful for the property types * 'num' and 'position'. diff --git a/phpstan.neon.dist b/phpstan.neon.dist index bc2526cc6f5c6c4ef92e29af121e7e2b5fdaca74..ac4a30c767e9ad87fb0a6f78ce5302e403aff724 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -4,7 +4,9 @@ parameters: paths: - app/routes - lib - # - tests + - tests/functional + - tests/jsonapi + - tests/unit scanFiles: - composer/phpxmlrpc/phpxmlrpc/lib/xmlrpc.inc scanDirectories: diff --git a/tests/functional/lib/models/resources/BuildingTest.php b/tests/functional/lib/models/resources/BuildingTest.php index 109cccb50279c3297a04f51801e030f69d6ca7ed..6576196017415bade6f1156f1f94072a125c60b3 100644 --- a/tests/functional/lib/models/resources/BuildingTest.php +++ b/tests/functional/lib/models/resources/BuildingTest.php @@ -23,10 +23,15 @@ class BuildingTest extends \Codeception\Test\Unit protected $db_handle; protected $oldUser; + private $location_cat; + private $building_cat; + private $location; + private $building; + /** * @SuppressWarnings(PHPMD.Superglobals) */ - protected function _before() + protected function setUp(): void { //First we must initialise the StudipPDO database connection: $this->db_handle = new \StudipPDO( @@ -61,7 +66,7 @@ class BuildingTest extends \Codeception\Test\Unit //Everything is set up for the test cases. } - protected function _after() + protected function tearDown(): void { //We must roll back the changes we made in this test //so that the live database remains unchanged after diff --git a/tests/functional/lib/models/resources/LocationTest.php b/tests/functional/lib/models/resources/LocationTest.php index 97b139c42b4d2c703cd84578324db87d0948738f..a8c4261e66aeeac17c611d70987c2e9160cb12c3 100644 --- a/tests/functional/lib/models/resources/LocationTest.php +++ b/tests/functional/lib/models/resources/LocationTest.php @@ -26,7 +26,10 @@ class LocationTest extends \Codeception\Test\Unit protected $db_handle; protected $oldUser; - protected function _before() + private $location_cat; + private $location; + + protected function setUp(): void { //First we must initialise the StudipPDO database connection: $this->db_handle = new \StudipPDO( @@ -65,7 +68,7 @@ class LocationTest extends \Codeception\Test\Unit //Everything is set up for the test cases. } - protected function _after() + protected function tearDown(): void { //We must roll back the changes we made in this test //so that the live database remains unchanged after diff --git a/tests/functional/lib/models/resources/ResourceAssignmentTest.php b/tests/functional/lib/models/resources/ResourceAssignmentTest.php index f1a6a6ce816f68049d769265b7048524f301b852..f2c2fcd9c8325ee3f38ef6e6d156baa9ea00824a 100644 --- a/tests/functional/lib/models/resources/ResourceAssignmentTest.php +++ b/tests/functional/lib/models/resources/ResourceAssignmentTest.php @@ -20,9 +20,16 @@ class ResourceAssignmentTest extends \Codeception\Test\Unit { protected $db_handle; - protected $oldPerm, $oldUser; + protected $oldPerm; + protected $oldUser; - protected function _before() + private $test_user_username; + private $test_user; + private $resource_category; + private $resource; + private $booking; + + protected function setUp(): void { //First we must initialise the StudipPDO database connection: $this->db_handle = new \StudipPDO( @@ -55,12 +62,12 @@ class ResourceAssignmentTest extends \Codeception\Test\Unit //As a final step we create the SORM objects for our test cases: $this->test_user_username = 'test_user_' . date('YmdHis'); - $this->test_user = new User(); - $this->test_user->username = $this->test_user_username; - $this->test_user->vorname = 'Test'; - $this->test_user->nachname = 'User'; - $this->test_user->perms = 'admin'; - $this->test_user->store(); + $this->test_user = User::create([ + 'username' => $this->test_user_username, + 'vorname' => 'Test', + 'nachname' => 'User', + 'perms' => 'admin', + ]); $perm = new ResourcePermission(); $perm->user_id = $this->test_user->id; @@ -88,21 +95,9 @@ class ResourceAssignmentTest extends \Codeception\Test\Unit 0, new DateTime('2017-12-04 15:00:00+0000') ); - - $this->another_booking = $this->resource->createBooking( - $this->test_user, - $this->test_user->id, - [ - [ - 'begin' => new DateTime('2017-12-06 0:00:00+0000'), - 'end' => new DateTime('2017-12-06 12:00:00+0000') - ] - ] - ); - //Everything is set up for the test cases. } - protected function _after() + protected function tearDown(): void { //We must roll back the changes we made in this test //so that the live database remains unchanged after @@ -175,9 +170,6 @@ class ResourceAssignmentTest extends \Codeception\Test\Unit { $time_intervals = $this->booking->getTimeIntervals(); - $this->assertEquals( - 4, - count($time_intervals) - ); + $this->assertCount(4, $time_intervals); } } diff --git a/tests/functional/lib/models/resources/ResourceTest.php b/tests/functional/lib/models/resources/ResourceTest.php index 86c46f97b9116c72cd25184a7cd4015509794471..66eae5583bb7a50be28ed54ef80c8c91294ff391 100644 --- a/tests/functional/lib/models/resources/ResourceTest.php +++ b/tests/functional/lib/models/resources/ResourceTest.php @@ -3,9 +3,29 @@ class ResourceTest extends \Codeception\Test\Unit { protected $db_handle; - protected $oldPerm, $oldUser; - - protected function _before() + protected $oldPerm; + protected $oldUser; + + private $test_user_username; + private $test_user; + private $test_property_name; + private $test_property2_name; + private $resource_cat; + private $test_resource_name; + private $resource; + private $booking_start_time; + private $booking_end_time; + private $booking_repeat_end; + private $booking; + private $lock_start_time; + private $lock_end_time; + private $lock; + private $course; + private $course_date; + private $user2; + + + protected function setUp(): void { //First we must initialise the StudipPDO database connection: $this->db_handle = new \StudipPDO( @@ -36,44 +56,44 @@ class ResourceTest extends \Codeception\Test\Unit //As a final step we create the SORM objects for our test cases: $this->test_user_username = 'test_user_' . date('YmdHis'); - $this->test_user = new User(); - $this->test_user->username = $this->test_user_username; - $this->test_user->vorname = 'Test'; - $this->test_user->nachname = 'User'; - $this->test_user->perms = 'admin'; - $this->test_user->store(); + $this->test_user = User::create([ + 'username' => $this->test_user_username, + 'vorname' => 'Test', + 'nachname' => 'User', + 'perms' => 'admin', + ]); $this->test_property_name = 'test_' . date('YmdHis'); $this->test_property2_name = 'some_test_user_' . date('YmdHis'); - $this->resource_cat = new ResourceCategory(); - $this->resource_cat->name = 'Test Category'; - $this->resource_cat->class_name = 'Resource'; - $this->resource_cat->iconnr = '1'; - $this->resource_cat->store(); - - $def = new ResourcePropertyDefinition(); - $def->name = $this->test_property_name; - $def->type = 'text'; - $def->searchable = '0'; - $def->range_search = '0'; - $def->store(); - - $def2 = new ResourcePropertyDefinition(); - $def2->name = $this->test_property2_name; - $def2->type = 'user'; - $def2->searchable = '0'; - $def2->range_search = '0'; - $def2->store(); - - $this->test_property = $this->resource_cat->addProperty( + $this->resource_cat = ResourceCategory::create([ + 'name' => 'Test Category', + 'class_name' => Resource::class, + 'iconnr' => 1, + ]); + + ResourcePropertyDefinition::create([ + 'name' => $this->test_property_name, + 'type' => 'text', + 'searchable' => false, + 'range_search' => false, + ]); + + ResourcePropertyDefinition::create([ + 'name' => $this->test_property2_name, + 'type' => 'user', + 'searchable' => false, + 'range_search' => false, + ]); + + $this->resource_cat->addProperty( $this->test_property_name, 'text', true, true ); - $this->test_property2 = $this->resource_cat->addProperty( + $this->resource_cat->addProperty( $this->test_property2_name, 'user', false, @@ -86,7 +106,7 @@ class ResourceTest extends \Codeception\Test\Unit $this->test_resource_name, 'Resource Description 20171013' ); - $this->resource->requestable = '1'; + $this->resource->requestable = true; $this->resource->store(); $this->resource->setProperty( @@ -99,11 +119,11 @@ class ResourceTest extends \Codeception\Test\Unit $this->test_user ); - $permission = new ResourcePermission(); - $permission->user_id = $this->test_user->id; - $permission->resource_id = $this->resource->id; - $permission->perms = 'admin'; - $permission->store(); + ResourcePermission::create([ + 'user_id' => $this->test_user->id, + 'resource_id' => $this->resource->id, + 'perms' => 'admin', + ]); $this->booking_start_time = new DateTime('2017-10-02 8:00:00 +0000'); $this->booking_end_time = new DateTime('2017-10-02 10:00:00 +0000'); @@ -132,18 +152,18 @@ class ResourceTest extends \Codeception\Test\Unit $this->lock_end_time ); - $this->course = new Course(); - $this->course->name = 'Test Resource Course ' . date('YmdHis'); - $this->course->store(); + $this->course = Course::create([ + 'name' => 'Test Resource Course ' . date('YmdHis'), + ]); - $this->course_date = new CourseDate(); - $this->course_date->range_id = $this->course->id; - $this->course_date->autor_id = $this->test_user->id; - $this->course_date->date = strtotime('2017-10-02 11:00:00 +0000'); - $this->course_date->end_time = strtotime('2017-10-02 12:00:00 +0000'); - $this->course_date->store(); + CourseDate::create([ + 'range_id' => $this->course->id, + 'autor_id' => $this->test_user->id, + 'date' => strtotime('2017-10-02 11:00:00 +0000'), + 'end_time' => strtotime('2017-10-02 12:00:00 +0000'), + ]); - $this->request = $this->resource->createRequest( + $this->resource->createRequest( $this->test_user, $this->course->id, 'test createRequest', @@ -152,12 +172,12 @@ class ResourceTest extends \Codeception\Test\Unit ] ); - $this->user2 = new User(); - $this->user2->username = 'test_user2_' . date('YmdHis'); - $this->user2->perms = 'tutor'; - $this->user2->vorname = 'Test'; - $this->user2->nachname = 'User 2'; - $this->user2->store(); + $this->user2 = User::create([ + 'username' => 'test_user2_' . date('YmdHis'), + 'perms' => 'tutor', + 'vorname' => 'Test', + 'nachname' => 'User 2', + ]); $this->resource->setUserPermission( $this->user2, @@ -167,7 +187,7 @@ class ResourceTest extends \Codeception\Test\Unit //Everything is set up for the test cases. } - protected function _after() + protected function tearDown(): void { //We must roll back the changes we made in this test //so that the live database remains unchanged after @@ -185,14 +205,14 @@ class ResourceTest extends \Codeception\Test\Unit InvalidResourceException::class ); - $r = new Resource(); - $r->name = 'Invalid Resource'; - $r->store(); + Resource::create([ + 'name' => 'Invalid Resource', + ]); } public function testCreateResource() { - //$this->resource has been created in the _before() method + //$this->resource has been created in the setUp() method $this->assertEquals( $this->test_resource_name, $this->resource->name @@ -206,7 +226,7 @@ class ResourceTest extends \Codeception\Test\Unit public function testCreateBooking() { - //The booking has been created in the _before() method. + //The booking has been created in the setUp() method. $this->assertEquals( $this->resource->id, @@ -246,7 +266,7 @@ class ResourceTest extends \Codeception\Test\Unit public function testCreateLock() { - //The resource lock has been created in the _before() method. + //The resource lock has been created in the setUp() method. $this->assertEquals( $this->resource->id, @@ -266,7 +286,7 @@ class ResourceTest extends \Codeception\Test\Unit public function testPropertyExists() { - //The property has been created in the _before() method. + //The property has been created in the setUp() method. $this->assertTrue( $this->resource->propertyExists( @@ -277,7 +297,7 @@ class ResourceTest extends \Codeception\Test\Unit public function testGetPropertyObject() { - //The property has been created in the _before() method. + //The property has been created in the setUp() method. $property = $this->resource->getPropertyObject( $this->test_property_name @@ -296,7 +316,7 @@ class ResourceTest extends \Codeception\Test\Unit public function testGetProperty() { - //The property has been created in the _before() method. + //The property has been created in the setUp() method. $state = $this->resource->getProperty( $this->test_property_name @@ -310,7 +330,7 @@ class ResourceTest extends \Codeception\Test\Unit public function testNonexistingProperty() { - //The resource has been created in the _before() method. + //The resource has been created in the setUp() method. $this->assertFalse( $this->resource->propertyExists( @@ -321,7 +341,7 @@ class ResourceTest extends \Codeception\Test\Unit public function testGetNonexistingPropertyObject() { - //The resource has been created in the _before() method. + //The resource has been created in the setUp() method. $no_object = $this->resource->getPropertyObject( 'nonexistant_property_' . date('YmdHis') @@ -334,7 +354,7 @@ class ResourceTest extends \Codeception\Test\Unit public function testGetNonexistingProperty() { - //The resource has been created in the _before() method. + //The resource has been created in the setUp() method. $no_object = $this->resource->getProperty( 'nonexistant_property_' . date('YmdHis') @@ -349,7 +369,7 @@ class ResourceTest extends \Codeception\Test\Unit { $this->expectException(TypeError::class); - //The resource has been created in the _before() method. + //The resource has been created in the setUp() method. $no_object = $this->resource->getPropertyObject(); @@ -362,7 +382,7 @@ class ResourceTest extends \Codeception\Test\Unit public function testGetPropertyWithoutName() { $this->expectException(TypeError::class); - //The resource has been created in the _before() method. + //The resource has been created in the setUp() method. $this->assertEquals( null, @@ -376,10 +396,7 @@ class ResourceTest extends \Codeception\Test\Unit $this->test_property2_name ); - $this->assertEquals( - true, - ($user instanceof User) - ); + $this->assertInstanceOf(User::class, $user); $this->assertEquals( $this->test_user_username, @@ -393,13 +410,11 @@ class ResourceTest extends \Codeception\Test\Unit 'nonexistant_property' . date('YmdHis') ); - $this->assertNull( - $no_object - ); + $this->assertNull($no_object); } //Resource::setProperty and Resource::setPropertyRelatedObject - //don't need to be tested since they are called in the _before() method. + //don't need to be tested since they are called in the setUp() method. //If those set methods wouldn't work then the tests where //properties or property objects are retrieved would fail. @@ -407,20 +422,14 @@ class ResourceTest extends \Codeception\Test\Unit { $properties = $this->resource->getPropertyArray(); - $this->assertEquals( - 2, - count($properties) - ); + $this->assertCount(2, $properties); } public function testGetOnlyRequestablePropertyArray() { $properties = $this->resource->getPropertyArray(true); - $this->assertEquals( - 1, - count($properties) - ); + $this->assertCount(1, $properties); $this->assertEquals( $this->test_property_name, @@ -444,35 +453,35 @@ class ResourceTest extends \Codeception\Test\Unit public function testResourceAddChild() { - //$this->resource has been created in the _before() method. + //$this->resource has been created in the setUp() method. - $this->child = $this->resource_cat->createResource( + $child = $this->resource_cat->createResource( 'Test Resource Child 20171013', 'Resource Child Description 20171013' ); - $this->resource->addChild($this->child); + $this->resource->addChild($child); $this->assertEquals( $this->resource->children[0]->id, - $this->child->id + $child->id ); $this->assertEquals( - $this->child->parent_id, + $child->parent_id, $this->resource->id ); $this->assertEquals( - $this->child->level, - ($this->resource->level+1) + $child->level, + $this->resource->level + 1 ); } public function testResourceIsAssigned() { //$this->resource has been created - //in the _before()-Method. + //in the setUp()-Method. $this->assertTrue( $this->resource->isAssigned( @@ -506,17 +515,14 @@ class ResourceTest extends \Codeception\Test\Unit public function testGetResourceBookings() { - //$this->resource has been created in the _before() method. + //$this->resource has been created in the setUp() method. $bookings = $this->resource->getResourceBookings( new DateTime('2017-01-01 0:00:00 +0000'), new DateTime('2017-12-31 23:59:59 +0000') ); - $this->assertEquals( - count($bookings), - 1 - ); + $this->assertCount(1, $bookings); $this->assertEquals( $bookings[0]->id, @@ -592,7 +598,7 @@ class ResourceTest extends \Codeception\Test\Unit ) ); - //user2 is set up in the _before() method and user2's + //user2 is set up in the setUp() method and user2's //permission level on $this->resource is set to admin. $user2_perms = $this->resource->getUserPermission($this->user2); diff --git a/tests/functional/lib/models/resources/RoomTest.php b/tests/functional/lib/models/resources/RoomTest.php index baf65737c9b00906db4609e21346c0e4315a4294..82611f20038bea03b965bc8d9f6c96a8a28b7947 100644 --- a/tests/functional/lib/models/resources/RoomTest.php +++ b/tests/functional/lib/models/resources/RoomTest.php @@ -24,9 +24,23 @@ require_once __DIR__ . '/../../../_bootstrap.php'; class RoomTest extends \Codeception\Test\Unit { protected $db_handle; - protected $oldPerm, $oldUser; - - protected function _before() + protected $oldPerm; + protected $oldUser; + + private $test_user_username; + private $test_user; + private $location_cat; + private $building_cat; + private $room_cat; + private $location; + private $building; + private $room; + private $request_begin_date; + private $request_end_date; + private $course_date; + private $room_request; + + protected function setUp(): void { //First we must initialise the StudipPDO database connection: $this->db_handle = new \StudipPDO( @@ -57,32 +71,24 @@ class RoomTest extends \Codeception\Test\Unit //As a final step we create the SORM objects for our test cases: $this->test_user_username = 'test_user_' . date('YmdHis'); - $this->test_user = new User(); - $this->test_user->username = $this->test_user_username; - $this->test_user->vorname = 'Test'; - $this->test_user->nachname = 'User'; - $this->test_user->perms = 'admin'; - $this->test_user->store(); - - $perms = new ResourcePermission(); - $perms->user_id = $this->test_user->id; - $perms->resource_id = 'global'; - $perms->perms = 'tutor'; - $perms->store(); - - $this->location_cat = ResourceManager::createLocationCategory( - 'TestLocation' - ); - $this->building_cat = ResourceManager::createBuildingCategory( - 'TestBuilding' - ); - $this->room_cat = ResourceManager::createRoomCategory( - 'TestRoom' - ); + $this->test_user = User::create([ + 'username' => $this->test_user_username, + 'vorname' => 'Test', + 'nachname' => 'User', + 'perms' => 'admin', + ]); - $this->location = $this->location_cat->createResource( - 'Test location object' - ); + ResourcePermission::create([ + 'user_id' => $this->test_user->id, + 'resource_id' => 'global', + 'perms' => 'tutor', + ]); + + $this->location_cat = ResourceManager::createLocationCategory('TestLocation'); + $this->building_cat = ResourceManager::createBuildingCategory('TestBuilding'); + $this->room_cat = ResourceManager::createRoomCategory('TestRoom'); + + $this->location = $this->location_cat->createResource('Test location object'); $this->building = $this->building_cat->createResource( 'Test building object', @@ -100,19 +106,18 @@ class RoomTest extends \Codeception\Test\Unit //it when we're testing finding rooms by a room request. //The request we create is for a room with at least 22 seats. $this->room->seats = 25; - - $this->room->requestable = '1'; - + $this->room->requestable = true; $this->room->store(); $this->request_begin_date = new DateTime(); $this->request_begin_date->setTime(12,0,0); $this->request_end_date = clone $this->request_begin_date; $this->request_end_date->setTime(14,0,0); - $this->course_date = new CourseDate(); - $this->course_date->date = $this->request_begin_date->getTimestamp(); - $this->course_date->end_time = $this->request_end_date->getTimestamp(); - $this->course_date->store(); + + $this->course_date = CourseDate::create([ + 'date' => $this->request_begin_date->getTimestamp(), + 'end_time' => $this->request_end_date->getTimestamp(), + ]); $this->room_request = $this->room->createRequest( $this->test_user, @@ -126,7 +131,7 @@ class RoomTest extends \Codeception\Test\Unit //Everything is set up for the test cases. } - protected function _after() + protected function tearDown(): void { //We must roll back the changes we made in this test //so that the live database remains unchanged after diff --git a/tests/functional/lib/resources/ResourceManagerTest.php b/tests/functional/lib/resources/ResourceManagerTest.php index 5b65c3b774c1b205186b29bbe2e8de52f1544f5a..f858e9009725bda13fe4ec64a8ce38aae8ea154e 100644 --- a/tests/functional/lib/resources/ResourceManagerTest.php +++ b/tests/functional/lib/resources/ResourceManagerTest.php @@ -6,7 +6,11 @@ class ResourceManagerTest extends \Codeception\Test\Unit protected $db_handle; protected $oldUser; - protected function _before() + private $test_cat; + private $position_def; + private $perm_resource; + + protected function setUp(): void { //First we must initialise the StudipPDO database connection: $this->db_handle = new \StudipPDO( @@ -34,34 +38,32 @@ class ResourceManagerTest extends \Codeception\Test\Unit //As a final step we create the SORM objects for our test cases: - $this->test_cat = new ResourceCategory(); - $this->test_cat->class_name = 'Resource'; - $this->test_cat->store(); + $this->test_cat = ResourceCategory::create([ + 'class_name' => Resource::class, + ]); - $this->position_def = new ResourcePropertyDefinition(); - $this->position_def->name = 'test_pos'; - $this->position_def->type = 'position'; - $this->position_def->store(); + $this->position_def = ResourcePropertyDefinition::create([ + 'name' => 'test_pos', + 'type' => 'position', + ]); - $this->perm_user = new User(); - $this->perm_user->username = 'test_resource_perm'; - $this->perm_user->perms = 'autor'; - $this->perm_user->store(); + User::create([ + 'username' => 'test_resource_perm', + 'perms' => 'autor', + ]); $this->perm_resource = $this->test_cat->createResource( 'Permission Test Resource' ); $this->perm_resource->store(); - $this->test_def = new ResourcePropertyDefinition(); - $this->test_def->name = 'test_is_test'; - $this->test_def->type = 'bool'; - $this->test_def->store(); - - //Everything is set up for the test cases. + ResourcePropertyDefinition::create([ + 'name' => 'test_is_test', + 'type' => 'bool', + ]); } - protected function _after() + protected function tearDown(): void { //We must roll back the changes we made in this test //so that the live database remains unchanged after @@ -115,8 +117,7 @@ class ResourceManagerTest extends \Codeception\Test\Unit $category->iconnr ); - $this->assertEquals( - true, + $this->assertTrue( $category->hasProperty('test_is_test', 'bool') ); } @@ -137,14 +138,12 @@ class ResourceManagerTest extends \Codeception\Test\Unit ); //Test default properties: - $this->assertEquals( - true, + $this->assertTrue( $location_cat->hasProperty('geo_coordinates', 'position') ); //Test optional properties: - $this->assertEquals( - true, + $this->assertTrue( $location_cat->hasProperty('test_is_test', 'bool') ); } @@ -165,29 +164,24 @@ class ResourceManagerTest extends \Codeception\Test\Unit ); //Test default properties: - $this->assertEquals( - true, + $this->assertTrue( $building_cat->hasProperty('address', 'text') ); - $this->assertEquals( - true, + $this->assertTrue( $building_cat->hasProperty('accessible', 'bool') ); - $this->assertEquals( - true, + $this->assertTrue( $building_cat->hasProperty('geo_coordinates', 'position') ); - $this->assertEquals( - true, + $this->assertTrue( $building_cat->hasProperty('number', 'text') ); //Test optional properties: - $this->assertEquals( - true, + $this->assertTrue( $building_cat->hasProperty('test_is_test', 'bool') ); } @@ -208,24 +202,20 @@ class ResourceManagerTest extends \Codeception\Test\Unit ); //Test default properties: - $this->assertEquals( - true, + $this->assertTrue( $room_cat->hasProperty('room_type', 'select') ); - $this->assertEquals( - true, + $this->assertTrue( $room_cat->hasProperty('seats', 'num') ); - $this->assertEquals( - true, + $this->assertTrue( $room_cat->hasProperty('booking_plan_is_public', 'bool') ); //Test optional properties: - $this->assertEquals( - true, + $this->assertTrue( $room_cat->hasProperty('test_is_test', 'bool') ); } @@ -309,7 +299,6 @@ class ResourceManagerTest extends \Codeception\Test\Unit public static function coordinateProvider(): array { - return [ 'empty' => [''], diff --git a/tests/functional/lib/resources/RoomManagerTest.php b/tests/functional/lib/resources/RoomManagerTest.php deleted file mode 100644 index 910a5760259c4fd33627a7714e917e1b5e07d8f7..0000000000000000000000000000000000000000 --- a/tests/functional/lib/resources/RoomManagerTest.php +++ /dev/null @@ -1,94 +0,0 @@ -<?php - - -require_once __DIR__ . '/../../_bootstrap.php'; -require_once 'lib/resources/RoomManager.class.php'; -require_once 'lib/resources/ResourceManager.class.php'; - - -class RoomManagerTest extends \Codeception\Test\Unit -{ - protected $db_handle; - - - protected function _before() - { - //First we must initialise the StudipPDO database connection: - $this->db_handle = new \StudipPDO( - 'mysql:host=' - . $GLOBALS['DB_STUDIP_HOST'] - . ';dbname=' - . $GLOBALS['DB_STUDIP_DATABASE'], - $GLOBALS['DB_STUDIP_USER'], - $GLOBALS['DB_STUDIP_PASSWORD'] - ); - - //Then we must start a transaction before we access the database, - //otherwise we would spam the live database with test data! - $this->db_handle->beginTransaction(); - - //Now we tell the DBManager about the connection - //we have established to the Stud.IP database: - \DBManager::getInstance()->setConnection('studip', $this->db_handle); - - $this->user = new User(); - $this->user->username = 'test_user_' . date('YmdHis'); - $this->user->vorname = 'Test'; - $this->user->nachname = 'User'; - $this->user->perms = 'admin'; - $this->user->store(); - - ResourceManager::setGlobalResourcePermission($this->user, 'admin'); - - $this->location_cat = ResourceManager::createLocationCategory( - 'TestLocation' - ); - $this->building_cat = ResourceManager::createBuildingCategory( - 'TestBuilding' - ); - $this->room_cat = ResourceManager::createRoomCategory( - 'TestRoom' - ); - - $this->location = $this->location_cat->createResource( - 'Test location object' - ); - $this->building = $this->building_cat->createResource( - 'Test building object', - '', - $this->location->id - ); - $this->room = $this->room_cat->createResource( - 'Test room object', - '', - $this->building->id - ); - - $this->room->seats = 25; - - $this->room->createLock( - $this->user, - new DateTime('2017-10-02 8:00:00 +0000'), - new DateTime('2017-10-02 18:00:00 +0000') - ); - - $this->course = new Course(); - $this->course->name = 'test_course_' . date('YmdHis'); - $this->course->store(); - - $this->course_date = new CourseDate(); - $this->course_date->range_id = $this->course->id; - $this->course_date->autor_id = $this->user->id; - $this->course_date->date = strtotime('2017-10-01 8:00:00 +0000'); - $this->course_date->end_time = strtotime('2017-10-01 10:00:00 +0000'); - $this->course_date->store(); - } - - protected function _after() - { - //We must roll back the changes we made in this test - //so that the live database remains unchanged after - //all the test cases of this test have been finished: - $this->db_handle->rollBack(); - } -} diff --git a/tests/jsonapi/BlubberTestHelper.php b/tests/jsonapi/BlubberTestHelper.php index bcbec71a96c0808208796739e413c37cdb9ada32..cb43d783da9c19b1faf274f3f56820925b25da0a 100644 --- a/tests/jsonapi/BlubberTestHelper.php +++ b/tests/jsonapi/BlubberTestHelper.php @@ -144,7 +144,7 @@ trait BlubberTestHelper array_map(function ($thread) { return \BlubberThread::upgradeThread($thread); }, $threads), - function ($thread) use ($user) { + function ($thread) use ($credentials) { return $thread->isVisibleInStream() && $thread->isReadable($credentials['id']); } ); diff --git a/tests/jsonapi/CommentsDeleteTest.php b/tests/jsonapi/CommentsDeleteTest.php index 9e7151c396c015007618c6a0ebb21cfe6ba48ca0..464cb96ccd9a5c293bd71057c67c6bd07fe1391d 100644 --- a/tests/jsonapi/CommentsDeleteTest.php +++ b/tests/jsonapi/CommentsDeleteTest.php @@ -1,6 +1,8 @@ <?php +use JsonApi\Routes\Blubber\CommentsDelete; + class CommentsDeleteTest extends \Codeception\Test\Unit { /** @@ -21,7 +23,7 @@ class CommentsDeleteTest extends \Codeception\Test\Unit { $commentId = '372d6c3bd41cd503c022961e73698d4c'; $credentials = $this->tester->getCredentialsForRoot(); - $response = $this->deleteComment($credentials, $newsId); + $this->deleteComment($credentials, $commentId); } private function deleteComment(array $credentials, $commentId) diff --git a/tests/jsonapi/CourseNewsCreateTest.php b/tests/jsonapi/CourseNewsCreateTest.php index 83170becf2f3ec03b6302d169b0b6b428edaaf8b..5c832c1549105c316a1535ad367b15baec5e8de6 100644 --- a/tests/jsonapi/CourseNewsCreateTest.php +++ b/tests/jsonapi/CourseNewsCreateTest.php @@ -1,6 +1,8 @@ <?php +use JsonApi\Routes\News\CourseNewsCreate; + class CourseNewsCreateTest extends \Codeception\Test\Unit { /** @@ -26,7 +28,7 @@ class CourseNewsCreateTest extends \Codeception\Test\Unit $date = time(); $expire = $date + 1 * 7 * 24 * 60 * 60; $credentials = $this->tester->getCredentialsForRoot(); - $response = $this->createCourseNews($credentials, $courseId, $title, $content, $date, $expire); + $this->createCourseNews($credentials, $courseId, $title, $content, $date, $expire); } //helpers: diff --git a/tests/jsonapi/ForumEntriesDeleteTest.php b/tests/jsonapi/ForumEntriesDeleteTest.php index 60ae3a6492c36c91fd6a9781bcf781697ebb9bc1..e2f0a7ed05b073b49370e7a9b61467996c2d0779 100644 --- a/tests/jsonapi/ForumEntriesDeleteTest.php +++ b/tests/jsonapi/ForumEntriesDeleteTest.php @@ -36,8 +36,7 @@ class ForumEntriesDeleteTest extends \Codeception\Test\Unit $requestBuilder = $this->tester->createRequestBuilder($credentials); $requestBuilder ->setUri('/forum-entries/'.$entry->id) - ->delete() - ->setJsonApiBody($entry_json); + ->delete(); $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest()); @@ -54,8 +53,7 @@ class ForumEntriesDeleteTest extends \Codeception\Test\Unit $requestBuilder = $this->tester->createRequestBuilder($credentials); $requestBuilder ->setUri('/forum-entries/badId') - ->delete() - ->setJsonApiBody($entry_json); + ->delete(); $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest()); $this->tester->assertSame(404, $response->getStatusCode()); diff --git a/tests/jsonapi/NewsCreateTest.php b/tests/jsonapi/NewsCreateTest.php index eaf9dfd7e1f1c22fed2f8b30e1ecc4fa63437e78..b943c3f92402c510a768e156b122691c48ff4952 100644 --- a/tests/jsonapi/NewsCreateTest.php +++ b/tests/jsonapi/NewsCreateTest.php @@ -47,7 +47,6 @@ class NewsCreateTest extends \Codeception\Test\Unit $resourceObject = $document->primaryResource(); $this->tester->assertNotNull($resourceObject->attribute('title')); $this->tester->assertNotNull($resourceObject->attribute('content')); - $newsId = $news->id; } public function testShouldNotStudipNewsCreate() @@ -116,7 +115,6 @@ class NewsCreateTest extends \Codeception\Test\Unit $resourceObject = $document->primaryResource(); $this->tester->assertNotNull($resourceObject->attribute('title')); $this->tester->assertNotNull($resourceObject->attribute('content')); - $newsId = $news->id; } public function testShouldNotCourseNewsCreate() @@ -160,7 +158,6 @@ class NewsCreateTest extends \Codeception\Test\Unit $resourceObject = $document->primaryResource(); $this->tester->assertNotNull($resourceObject->attribute('title')); $this->tester->assertNotNull($resourceObject->attribute('content')); - $newsId = $news->id; } public function testShouldNotUserNewsCreate() diff --git a/tests/jsonapi/NewsDeleteTest.php b/tests/jsonapi/NewsDeleteTest.php index ac671a675f49a5ab54a17a801b057a87a634241d..fa74ab51ef57698b56a683e4b23035fdc4748439 100644 --- a/tests/jsonapi/NewsDeleteTest.php +++ b/tests/jsonapi/NewsDeleteTest.php @@ -50,7 +50,7 @@ class NewsDeleteTest extends \Codeception\Test\Unit } public function testShouldCommentDelete() { - + $title = 'A course testing title'; $credentials = $this->tester->getCredentialsForTestDozent(); $content = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit'; @@ -62,10 +62,9 @@ class NewsDeleteTest extends \Codeception\Test\Unit $requestBuilder = $this->tester->createRequestBuilder($credentials); $requestBuilder ->setUri('/comments/'.$comment->id) - ->delete() - ->setJsonApiBody($entry_json); - - $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest()); + ->delete(); + + $this->tester->sendMockRequest($app, $requestBuilder->getRequest()); $this->tester->assertIsEmpty(StudipComment::find($comment->id)); } } diff --git a/tests/unit/lib/FunctionsTest.php b/tests/unit/lib/FunctionsTest.php index 61ad409ed50bc44123d6164c372e39130212a6bf..b7d2498825687c9bb4609fbb39fde81a5bf24142 100644 --- a/tests/unit/lib/FunctionsTest.php +++ b/tests/unit/lib/FunctionsTest.php @@ -9,17 +9,6 @@ * the License, or (at your option) any later version. */ -class StringWrapper { - function __construct($string) - { - $this->string = $string; - } - function __toString() - { - return (string) $this->string; - } -} - class FunctionsTest extends \Codeception\Test\Unit { function testWords() diff --git a/tests/unit/lib/VisualTest.php b/tests/unit/lib/VisualTest.php index ae0b94196c6b3f775313d16ba129de5bf63e9f87..d5c0ba9e828daecb8d7af4ccbcfa07249a6e5f2c 100644 --- a/tests/unit/lib/VisualTest.php +++ b/tests/unit/lib/VisualTest.php @@ -45,20 +45,21 @@ class VisualFunctionsTest extends \Codeception\Test\Unit public function testHtmlReady() { $pairs = [ - 'abc' => 'abc', - 'äöü' => 'äöü', - '<' => '<', - '"' => '"', - "'" => ''', - '&' => '&amp;', - ''' => '&#039;', - '' => '', - NULL => NULL + 'abc' => 'abc', + 'äöü' => 'äöü', + '<' => '<', + '"' => '"', + "'" => ''', + '&' => '&amp;', + ''' => '&#039;', + '' => '', ]; foreach ($pairs as $string => $expected) { - $this->assertEquals($expected, htmlReady($string)); + $this->assertEquals($expected, htmlReady($string)); } + + $this->assertEquals(null, htmlReady(null)); } public function testFormatReadyTicket1255() diff --git a/tests/unit/lib/classes/AvatarClassTest.php b/tests/unit/lib/classes/AvatarClassTest.php index f531b263367ee334a2f24b5414f2d99ce3ce9d6f..88b24bd2a8e43598a1d6bfa36eefd4030ed77b82 100644 --- a/tests/unit/lib/classes/AvatarClassTest.php +++ b/tests/unit/lib/classes/AvatarClassTest.php @@ -20,9 +20,12 @@ require_once 'lib/phplib/Seminar_Perm.class.php'; * @author mlunzena * @copyright (c) Authors */ -class AvatarTestCase extends \Codeception\Test\Unit { +class AvatarTestCase extends \Codeception\Test\Unit +{ + private $avatar_id; + private $avatar; - function setUp(): void + public function setUp(): void { $stub = $this->createMock('Seminar_Perm'); // Configure the stub. @@ -37,91 +40,107 @@ class AvatarTestCase extends \Codeception\Test\Unit { $this->avatar = Avatar::getAvatar($this->avatar_id); } - function tearDown(): void { - unset($GLOBALS['DYNAMIC_CONTENT_PATH'], $GLOBALS['DYNAMIC_CONTENT_URL']); - } - - function test_class_should_exist() { - $this->assertTrue(class_exists('Avatar')); - } - - function test_avatar_url() { - $url = $this->avatar->getCustomAvatarUrl(Avatar::NORMAL); - $this->assertEquals("/dynamic/user/" . $this->avatar_id . "_normal.png?d=0", $url); - } - - function test_avatar_path() { - $path = $this->avatar->getCustomAvatarPath(Avatar::NORMAL); - $this->assertEquals("/dynamic/user/" . $this->avatar_id . "_normal.png", $path); - } - - function test_nobody_url() { - $url = Avatar::getNobody()->getUrl(Avatar::NORMAL); - $this->assertEquals("/dynamic/user/nobody_normal.png?d=0", $url); - } - - function test_nobody_path() { - $path = Avatar::getNobody()->getCustomAvatarPath(Avatar::NORMAL); - $this->assertEquals("/dynamic/user/nobody_normal.png", $path); - } + public function tearDown(): void + { + unset($GLOBALS['DYNAMIC_CONTENT_PATH'], $GLOBALS['DYNAMIC_CONTENT_URL']); + } + + public function test_class_should_exist() + { + $this->assertTrue(class_exists('Avatar')); + } + + public function test_avatar_url() + { + $url = $this->avatar->getCustomAvatarUrl(Avatar::NORMAL); + $this->assertEquals("/dynamic/user/" . $this->avatar_id . "_normal.png?d=0", $url); + } + + public function test_avatar_path() + { + $path = $this->avatar->getCustomAvatarPath(Avatar::NORMAL); + $this->assertEquals("/dynamic/user/" . $this->avatar_id . "_normal.png", $path); + } + + public function test_nobody_url() + { + $url = Avatar::getNobody()->getUrl(Avatar::NORMAL); + $this->assertEquals("/dynamic/user/nobody_normal.png?d=0", $url); + } + + public function test_nobody_path() + { + $path = Avatar::getNobody()->getCustomAvatarPath(Avatar::NORMAL); + $this->assertEquals("/dynamic/user/nobody_normal.png", $path); + } } class CourseAvatarTestCase extends \Codeception\Test\Unit { + private $avatar_id; + private $avatar; - function setUp(): void { - $this->avatar_id = "123456789"; - $this->avatar = CourseAvatar::getAvatar($this->avatar_id); - - $this->setUpFS(); - - $GLOBALS['DYNAMIC_CONTENT_URL'] = "/dynamic"; - $GLOBALS['DYNAMIC_CONTENT_PATH'] = "/dynamic"; - } - - function setUpFS() { - ArrayFileStream::set_filesystem([ - 'dynamic' => [ - 'course' => [ - $this->avatar_id . '_normal.png' => '', - $this->avatar_id . '_medium.png' => '', - $this->avatar_id . '_small.png' => '', - ], - ], - ]); - - if (!stream_wrapper_register("var", "ArrayFileStream")) { - new Exception("Failed to register protocol"); + public function setUp(): void + { + $this->avatar_id = "123456789"; + $this->avatar = CourseAvatar::getAvatar($this->avatar_id); + + $this->setUpFS(); + + $GLOBALS['DYNAMIC_CONTENT_URL'] = "/dynamic"; + $GLOBALS['DYNAMIC_CONTENT_PATH'] = "/dynamic"; + } + + private function setUpFS() + { + ArrayFileStream::set_filesystem([ + 'dynamic' => [ + 'course' => [ + $this->avatar_id . '_normal.png' => '', + $this->avatar_id . '_medium.png' => '', + $this->avatar_id . '_small.png' => '', + ], + ], + ]); + + if (!stream_wrapper_register("var", "ArrayFileStream")) { + throw new Exception("Failed to register protocol"); + } + } + + public function tearDown(): void + { + stream_wrapper_unregister("var"); + unset($GLOBALS['DYNAMIC_CONTENT_PATH'], $GLOBALS['DYNAMIC_CONTENT_URL']); + } + + public function test_class_should_exist() + { + $this->assertTrue(class_exists('CourseAvatar')); + } + + public function test_avatar_url() + { + $url = $this->avatar->getCustomAvatarUrl(Avatar::NORMAL); + $this->assertEquals("/dynamic/course/". $this->avatar_id . "_normal.png?d=0", $url); + } + + public function test_avatar_path() + { + $path = $this->avatar->getCustomAvatarPath(Avatar::NORMAL); + $this->assertEquals("/dynamic/course/". $this->avatar_id . "_normal.png", $path); + } + + public function test_nobody_url() + { + $url = CourseAvatar::getNobody()->getUrl(Avatar::NORMAL); + $this->assertEquals("/dynamic/course/nobody_normal.png?d=0", $url); + } + + public function test_nobody_path() + { + $path = CourseAvatar::getNobody()->getCustomAvatarPath(Avatar::NORMAL); + $this->assertEquals("/dynamic/course/nobody_normal.png", $path); } - } - - function tearDown(): void { - stream_wrapper_unregister("var"); - unset($GLOBALS['DYNAMIC_CONTENT_PATH'], $GLOBALS['DYNAMIC_CONTENT_URL']); - } - - function test_class_should_exist() { - $this->assertTrue(class_exists('CourseAvatar')); - } - - function test_avatar_url() { - $url = $this->avatar->getCustomAvatarUrl(Avatar::NORMAL); - $this->assertEquals("/dynamic/course/". $this->avatar_id . "_normal.png?d=0", $url); - } - - function test_avatar_path() { - $path = $this->avatar->getCustomAvatarPath(Avatar::NORMAL); - $this->assertEquals("/dynamic/course/". $this->avatar_id . "_normal.png", $path); - } - - function test_nobody_url() { - $url = CourseAvatar::getNobody()->getUrl(Avatar::NORMAL); - $this->assertEquals("/dynamic/course/nobody_normal.png?d=0", $url); - } - - function test_nobody_path() { - $path = CourseAvatar::getNobody()->getCustomAvatarPath(Avatar::NORMAL); - $this->assertEquals("/dynamic/course/nobody_normal.png", $path); - } } diff --git a/tests/unit/lib/classes/CronjobScheduleTest.php b/tests/unit/lib/classes/CronjobScheduleTest.php index 18ead9b8e218f575eb8258353a47acc1d018268b..a97872ef3c57f5a3f0a89339353148fc22707b4c 100644 --- a/tests/unit/lib/classes/CronjobScheduleTest.php +++ b/tests/unit/lib/classes/CronjobScheduleTest.php @@ -66,15 +66,15 @@ class CronjobScheduleTest extends \Codeception\Test\Unit /** * @depends testOnceSchedule */ - function testNextExecutionOnceFuture($schedule) + function testNextExecutionOnceFuture(CronjobSchedule $schedule) { $now = strtotime('10.11.2013 01:02:00'); $then = strtotime('+2 weeks', $now); - $schedule->next_execution = $next_execution; - $schedule->calculateNextExecution(); + $schedule->next_execution = $then; + $schedule->calculateNextExecution($now); - $this->assertEquals($next_execution, $schedule->next_execution); + $this->assertEquals($then, $schedule->next_execution); } function testPeriodicSchedule() diff --git a/tests/unit/lib/classes/CsrfProtectionTest.php b/tests/unit/lib/classes/CsrfProtectionTest.php index 5bdbb30e182bd576b13cacbcd971f6c2d527a91d..1a74598188b1e231328244316b691643d55edd7a 100644 --- a/tests/unit/lib/classes/CsrfProtectionTest.php +++ b/tests/unit/lib/classes/CsrfProtectionTest.php @@ -12,6 +12,8 @@ class CSRFProtectionTokenTest extends \Codeception\Test\Unit { + private $original_session; + function setUp(): void { if (session_id() === '') { @@ -64,6 +66,8 @@ class CSRFProtectionTokenTest extends \Codeception\Test\Unit class CSRFRequestTest extends \Codeception\Test\Unit { + private $original_state; + private $token; function setUp(): void { diff --git a/tests/unit/lib/classes/IconClassTest.php b/tests/unit/lib/classes/IconClassTest.php index 7659b725001ec63ad1b79f7574230eb1999b61b6..4596d7e9abf5ea1f08aacba7c73315f1b3e74fd2 100644 --- a/tests/unit/lib/classes/IconClassTest.php +++ b/tests/unit/lib/classes/IconClassTest.php @@ -10,6 +10,8 @@ class IconClassTest extends \Codeception\Test\Unit { + private $memo_assets_url; + function setUp(): void { $this->memo_assets_url = Assets::url(); diff --git a/tests/unit/lib/classes/MarkupClassTest.php b/tests/unit/lib/classes/MarkupClassTest.php index ce08f01224ed74af1b2972949b4ed91f3f8e6db5..9ab835f1c53e73b944c432df6d2ea2b44999759b 100644 --- a/tests/unit/lib/classes/MarkupClassTest.php +++ b/tests/unit/lib/classes/MarkupClassTest.php @@ -203,7 +203,7 @@ class MarkupClassTest extends \Codeception\Test\Unit . $test['exception'] . '. Output: ' . $out . '.' ); } - } catch (PHPUnit_Framework_Error_Notice $e) { + } catch (PHPUnit\Framework\Error\Notice $e) { throw $e; } catch (Exception $e) { if ( !isset($test['exception'])) { diff --git a/tests/unit/lib/classes/NotificationCenterTest.php b/tests/unit/lib/classes/NotificationCenterTest.php index 687183e43096a477b431280e39d60b669f08c548..8a6ba9a68db69694900c7ceb80f29e31398aca09 100644 --- a/tests/unit/lib/classes/NotificationCenterTest.php +++ b/tests/unit/lib/classes/NotificationCenterTest.php @@ -20,6 +20,8 @@ interface Observer # @see http://php.net/language.oop5.magic class NotificationCenterTestSoundexPredicate { + private $goldStandard; + public function __construct($goldStandard) { $this->goldStandard = $goldStandard; @@ -33,6 +35,9 @@ class NotificationCenterTestSoundexPredicate class NotificationCenterTest extends \Codeception\Test\Unit { + private $observer; + private $subject; + public function setUp(): void { $this->observer = $this->createMock("Observer"); diff --git a/tests/unit/lib/classes/ObjectBuilderTest.php b/tests/unit/lib/classes/ObjectBuilderTest.php index 1f840ea0fc7c6d1c446622e3486dabb9ed6100d5..6b755e8a1ee406fa5578f6e6da21d3592805b26d 100644 --- a/tests/unit/lib/classes/ObjectBuilderTest.php +++ b/tests/unit/lib/classes/ObjectBuilderTest.php @@ -14,6 +14,9 @@ class ObjectBuilderTest extends \Codeception\Test\Unit protected $another_object; protected $another_changed_object; + private $simple_array_definition; + private $another_simple_array_definition; + public function setUp (): void { require_once 'lib/functions.php'; diff --git a/tests/unit/lib/classes/PluginRepositoryTest.php b/tests/unit/lib/classes/PluginRepositoryTest.php index d1f0f084e30eabcd5a78b9c809d9387425a20d07..6676b7c54ff97b870ba52ac02885c6d50a5cf690 100644 --- a/tests/unit/lib/classes/PluginRepositoryTest.php +++ b/tests/unit/lib/classes/PluginRepositoryTest.php @@ -14,12 +14,14 @@ require_once 'lib/plugins/engine/PluginRepository.class.php'; class PluginRepositoryTest extends \Codeception\Test\Unit { + private $repository; + public function setUp (): void { $GLOBALS['SOFTWARE_VERSION'] = '1.9.0'; $GLOBALS['CACHING_ENABLE'] = false; - $url = 'file://'.dirname(__FILE__).'/plugin_repository_test.xml'; + $url = 'file://' . __DIR__ . '/plugin_repository_test.xml'; $this->repository = new PluginRepository($url); } diff --git a/tests/unit/lib/classes/StudipFormatTest.php b/tests/unit/lib/classes/StudipFormatTest.php index 2a7ca4a03f872b334ae27ec02e6fcf95166fea75..4e1015425fa2813b948f609ccac54aa66517040c 100644 --- a/tests/unit/lib/classes/StudipFormatTest.php +++ b/tests/unit/lib/classes/StudipFormatTest.php @@ -19,17 +19,20 @@ function markupBold($markup, $matches, $contents) class StudipFormatTest extends \Codeception\Test\Unit { - function setUp(): void { + private $old_rules; + + function setUp(): void + { $this->old_rules = StudipCoreFormat::getStudipMarkups(); } function tearDown(): void { - foreach(StudipCoreFormat::getStudipMarkups() as $key => $value) { + foreach (StudipCoreFormat::getStudipMarkups() as $key => $value) { StudipCoreFormat::removeStudipMarkup($key); } - foreach($this->old_rules as $key => $value) { + foreach ($this->old_rules as $key => $value) { StudipCoreFormat::addStudipMarkup($key, @$value['start'], @$value['end'], @$value['callback']); } } diff --git a/tests/unit/lib/classes/StudipVersionTest.php b/tests/unit/lib/classes/StudipVersionTest.php index 4e824bc44c513ab07ee8a4601dd1205a1a716df4..be56ecf0a357f104ab850ada954f93112d92e1fd 100644 --- a/tests/unit/lib/classes/StudipVersionTest.php +++ b/tests/unit/lib/classes/StudipVersionTest.php @@ -1,5 +1,5 @@ <?php -/* +/** * StudipVersionTest.php - unit tests for the StudipVersion class * * This program is free software; you can redistribute it and/or @@ -10,19 +10,11 @@ * @author Till Glöggler * @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2 * @category Stud.IP + * + * @backupGlobals enabled */ - class StudipVersionTest extends \Codeception\Test\Unit { - function setUp(): void { - $this->version = $GLOBALS['SOFTWARE_VERSION']; - } - - function tearDown(): void - { - $GLOBALS['SOFTWARE_VERSION'] = $this->version; - } - public function testStandardVersion() { $GLOBALS['SOFTWARE_VERSION'] = '1.0'; diff --git a/tests/unit/lib/classes/TextFormatTest.php b/tests/unit/lib/classes/TextFormatTest.php index 7a58bed736d1d6610e4db26c8183e999dc6f6702..2174bb9dd56a7212e57d3952cccb3f9bb9f558e8 100644 --- a/tests/unit/lib/classes/TextFormatTest.php +++ b/tests/unit/lib/classes/TextFormatTest.php @@ -191,7 +191,7 @@ function markupSum($markup, $matches) class TextFormatTest extends \Codeception\Test\Unit { - public function setUp(): void + private function getMarkup(): TextFormat { $markup = new TextFormat(); @@ -231,70 +231,70 @@ class TextFormatTest extends \Codeception\Test\Unit $markup->addMarkup('mail', '(\[.*?\])?\b([\w!#%+.-]+@[[:alnum:].-]+)', NULL, 'markupMail'); $markup->addMarkup('sum', '\(:sum\((\d+)\\\\(\d+)\):\)', NULL, 'markupSum'); - $this->markup = $markup; + return $markup; } public function testLine() { $input = "Test\n--\nTest"; $expected = "Test\n<hr>\nTest"; - $this->assertEquals($expected, $this->markup->format($input)); + $this->assertEquals($expected, $this->getMarkup()->format($input)); } public function testHeading() { $input = '!!%%Überschrift%%'; $expected = '<h3 class="content"><i>Überschrift</i></h3>'; - $this->assertEquals($expected, $this->markup->format($input)); + $this->assertEquals($expected, $this->getMarkup()->format($input)); } public function testBoldItalics() { $input = '**some %%code%%**'; $expected = '<b>some <i>code</i></b>'; - $this->assertEquals($expected, $this->markup->format($input)); + $this->assertEquals($expected, $this->getMarkup()->format($input)); } public function testBigSmall() { $input = '++some --code--++'; $expected = '<big>some <small>code</small></big>'; - $this->assertEquals($expected, $this->markup->format($input)); + $this->assertEquals($expected, $this->getMarkup()->format($input)); } public function testSimpleBoldItalics() { $input = '*bold*text* %some%italics%'; $expected = '<b>bold text</b> <i>some italics</i>'; - $this->assertEquals($expected, $this->markup->format($input)); + $this->assertEquals($expected, $this->getMarkup()->format($input)); } public function testMissingClose() { $input = '**missing %%close'; $expected = $input; - $this->assertEquals($expected, $this->markup->format($input)); + $this->assertEquals($expected, $this->getMarkup()->format($input)); } public function testCloseBeforeOpen() { $input = 'there is -}no markup{- here'; $expected = $input; - $this->assertEquals($expected, $this->markup->format($input)); + $this->assertEquals($expected, $this->getMarkup()->format($input)); } public function testIncorrectNesting() { $input = '** test %% test ** test %%'; $expected = '** test <i> test ** test </i>'; - $this->assertEquals($expected, $this->markup->format($input)); + $this->assertEquals($expected, $this->getMarkup()->format($input)); } public function testImage() { $input = '[img=Stud.IP-Logo]http://www.studip.de/logo.png'; $expected = '<img src="http://www.studip.de/logo.png" title="Stud.IP-Logo">'; - $this->assertEquals($expected, $this->markup->format($input)); + $this->assertEquals($expected, $this->getMarkup()->format($input)); } public function testTable() @@ -312,7 +312,7 @@ class TextFormatTest extends \Codeception\Test\Unit .'<td>Mathe Diplom</td>' .'</tr>' .'</table>'; - $this->assertEquals($expected, $this->markup->format($input)); + $this->assertEquals($expected, $this->getMarkup()->format($input)); } public function testList() @@ -326,7 +326,7 @@ class TextFormatTest extends \Codeception\Test\Unit .'</ol></li>' .'<li>Schluss</li>' .'</ul>'; - $this->assertEquals($expected, $this->markup->format($input)); + $this->assertEquals($expected, $this->getMarkup()->format($input)); } public function testIndent() @@ -340,21 +340,21 @@ class TextFormatTest extends \Codeception\Test\Unit .'</p>' ."Ebene 1\n" .'</p>'; - $this->assertEquals($expected, $this->markup->format($input)); + $this->assertEquals($expected, $this->getMarkup()->format($input)); } public function testNop() { $input = '[nop]**A**[quote]B[/quote]{-C-}[/nop]'; $expected = '**A**[quote]B[/quote]{-C-}'; - $this->assertEquals($expected, $this->markup->format($input)); + $this->assertEquals($expected, $this->getMarkup()->format($input)); } public function testPre() { $input = '[pre]**A**{-C-}[/pre]'; $expected = '<pre><b>A</b><strike>C</strike></pre>'; - $this->assertEquals($expected, $this->markup->format($input)); + $this->assertEquals($expected, $this->getMarkup()->format($input)); } public function testQuote() @@ -363,27 +363,27 @@ class TextFormatTest extends \Codeception\Test\Unit $expected = '<blockquote class="quote">' .'<b><u>Anonymous</u> hat geschrieben:</b><hr>some text' .'</blockquote>'; - $this->assertEquals($expected, $this->markup->format($input)); + $this->assertEquals($expected, $this->getMarkup()->format($input)); } public function testLink() { $input = '[Testlink]https://www.studip.de/'; $expected = '<a href="https://www.studip.de/">Testlink</a>'; - $this->assertEquals($expected, $this->markup->format($input)); + $this->assertEquals($expected, $this->getMarkup()->format($input)); } public function testMail() { $input = '[Mail]some.user@example.com'; $expected = '<a href="mailto:some.user@example.com">Mail</a>'; - $this->assertEquals($expected, $this->markup->format($input)); + $this->assertEquals($expected, $this->getMarkup()->format($input)); } public function testSum() { $input = '(:sum(3\\4):)'; $expected = '7'; - $this->assertEquals($expected, $this->markup->format($input)); + $this->assertEquals($expected, $this->getMarkup()->format($input)); } } diff --git a/tests/unit/varstream.php b/tests/unit/varstream.php index daa4f636d4a5d6eb25f4881bd54016857031fb62..9a3acb55c776e5f7e4589fd8ad5d949fa8b59419 100644 --- a/tests/unit/varstream.php +++ b/tests/unit/varstream.php @@ -161,7 +161,7 @@ class ArrayFileStream 'gid' => function_exists('posix_getgid') ? posix_getgid() : 0, 'rdev' => 0, 'size' => $flags & STREAM_URL_STAT_QUIET - ? @mb_strlen($this->_pointer) : mb_strlen($this->_pointer), + ? @mb_strlen($this->open_file) : mb_strlen($this->open_file), 'atime' => $time, 'mtime' => $time, 'ctime' => $time, @@ -213,4 +213,3 @@ class ArrayFileStream #unlink('var://tmp/a'); #var_dump(include 'var://tmp/b'); -