diff options
| author | Jan-Hendrik Willms <tleilax+studip@gmail.com> | 2022-07-14 08:21:04 +0000 |
|---|---|---|
| committer | David Siegfried <david.siegfried@uni-vechta.de> | 2022-07-14 08:21:04 +0000 |
| commit | 24377df5463c10696077822a81a8fa20790a4749 (patch) | |
| tree | 98db3b55da25cf32d5ea3af46314077cc071e920 /tests/unit | |
| parent | b7dcb67da285cd25122a59dd342ca78400450ff2 (diff) | |
fix errors in tests, fixes #1309
Closes #1309
Merge request studip/studip!805
Diffstat (limited to 'tests/unit')
| -rw-r--r-- | tests/unit/lib/FunctionsTest.php | 11 | ||||
| -rw-r--r-- | tests/unit/lib/VisualTest.php | 21 | ||||
| -rw-r--r-- | tests/unit/lib/classes/AvatarClassTest.php | 183 | ||||
| -rw-r--r-- | tests/unit/lib/classes/CronjobScheduleTest.php | 8 | ||||
| -rw-r--r-- | tests/unit/lib/classes/CsrfProtectionTest.php | 4 | ||||
| -rw-r--r-- | tests/unit/lib/classes/IconClassTest.php | 2 | ||||
| -rw-r--r-- | tests/unit/lib/classes/MarkupClassTest.php | 2 | ||||
| -rw-r--r-- | tests/unit/lib/classes/NotificationCenterTest.php | 5 | ||||
| -rw-r--r-- | tests/unit/lib/classes/ObjectBuilderTest.php | 3 | ||||
| -rw-r--r-- | tests/unit/lib/classes/PluginRepositoryTest.php | 4 | ||||
| -rw-r--r-- | tests/unit/lib/classes/StudipFormatTest.php | 9 | ||||
| -rw-r--r-- | tests/unit/lib/classes/StudipVersionTest.php | 14 | ||||
| -rw-r--r-- | tests/unit/lib/classes/TextFormatTest.php | 40 | ||||
| -rw-r--r-- | tests/unit/varstream.php | 3 |
14 files changed, 164 insertions, 145 deletions
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', - 'äöü' => 'äöü', - '<' => '<', - '"' => '"', - "'" => ''', - '&' => '&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 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'); - |
