aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/models/resources/ResourcePropertyDefinition.class.php2
-rw-r--r--phpstan.neon.dist4
-rw-r--r--tests/functional/lib/models/resources/BuildingTest.php9
-rw-r--r--tests/functional/lib/models/resources/LocationTest.php7
-rw-r--r--tests/functional/lib/models/resources/ResourceAssignmentTest.php42
-rw-r--r--tests/functional/lib/models/resources/ResourceTest.php202
-rw-r--r--tests/functional/lib/models/resources/RoomTest.php77
-rw-r--r--tests/functional/lib/resources/ResourceManagerTest.php77
-rw-r--r--tests/functional/lib/resources/RoomManagerTest.php94
-rw-r--r--tests/jsonapi/BlubberTestHelper.php2
-rw-r--r--tests/jsonapi/CommentsDeleteTest.php4
-rw-r--r--tests/jsonapi/CourseNewsCreateTest.php4
-rw-r--r--tests/jsonapi/ForumEntriesDeleteTest.php6
-rw-r--r--tests/jsonapi/NewsCreateTest.php3
-rw-r--r--tests/jsonapi/NewsDeleteTest.php9
-rw-r--r--tests/unit/lib/FunctionsTest.php11
-rw-r--r--tests/unit/lib/VisualTest.php21
-rw-r--r--tests/unit/lib/classes/AvatarClassTest.php183
-rw-r--r--tests/unit/lib/classes/CronjobScheduleTest.php8
-rw-r--r--tests/unit/lib/classes/CsrfProtectionTest.php4
-rw-r--r--tests/unit/lib/classes/IconClassTest.php2
-rw-r--r--tests/unit/lib/classes/MarkupClassTest.php2
-rw-r--r--tests/unit/lib/classes/NotificationCenterTest.php5
-rw-r--r--tests/unit/lib/classes/ObjectBuilderTest.php3
-rw-r--r--tests/unit/lib/classes/PluginRepositoryTest.php4
-rw-r--r--tests/unit/lib/classes/StudipFormatTest.php9
-rw-r--r--tests/unit/lib/classes/StudipVersionTest.php14
-rw-r--r--tests/unit/lib/classes/TextFormatTest.php40
-rw-r--r--tests/unit/varstream.php3
29 files changed, 388 insertions, 463 deletions
diff --git a/lib/models/resources/ResourcePropertyDefinition.class.php b/lib/models/resources/ResourcePropertyDefinition.class.php
index c039459..37fa89b 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 bc2526c..ac4a30c 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 109cccb..6576196 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 97b139c..a8c4261 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 f1a6a6c..f2c2fcd 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 86c46f9..66eae55 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 baf6573..82611f2 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 5b65c3b..f858e90 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 910a576..0000000
--- 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 bcbec71..cb43d78 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 9e7151c..464cb96 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 83170be..5c832c1 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 60ae3a6..e2f0a7e 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 eaf9dfd..b943c3f 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 ac671a6..fa74ab5 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 61ad409..b7d2498 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 ae0b941..d5c0ba9 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',
- 'äöü' => 'äöü',
- '<' => '&lt;',
- '"' => '&quot;',
- "'" => '&#039;',
- '&amp;' => '&amp;amp;',
- '&#039;' => '&amp;#039;',
- '' => '',
- NULL => NULL
+ 'abc' => 'abc',
+ 'äöü' => 'äöü',
+ '<' => '&lt;',
+ '"' => '&quot;',
+ "'" => '&#039;',
+ '&amp;' => '&amp;amp;',
+ '&#039;' => '&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 f531b26..88b24bd 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 18ead9b..a97872e 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 5bdbb30..1a74598 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 7659b72..4596d7e 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 ce08f01..9ab835f 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 687183e..8a6ba9a 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 1f840ea..6b755e8 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 d1f0f08..6676b7c 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 2a7ca4a..4e10154 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 4e824bc..be56ecf 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 7a58bed..2174bb9 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 daa4f63..9a3acb5 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');
-