diff options
| author | Jan-Hendrik Willms <tleilax+github@gmail.com> | 2021-07-22 16:07:19 +0200 |
|---|---|---|
| committer | Jan-Hendrik Willms <tleilax+github@gmail.com> | 2021-07-22 16:19:12 +0200 |
| commit | a3da1483a9e689846179159355badfec8073dbec (patch) | |
| tree | 770dcca6bdf5f6f2a11b0e7fcbbeda6919a3fc52 /tests/unit/lib/classes/AvatarClassTest.php | |
current code from svn, revision 62608
Diffstat (limited to 'tests/unit/lib/classes/AvatarClassTest.php')
| -rw-r--r-- | tests/unit/lib/classes/AvatarClassTest.php | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/tests/unit/lib/classes/AvatarClassTest.php b/tests/unit/lib/classes/AvatarClassTest.php new file mode 100644 index 0000000..cc7bbbc --- /dev/null +++ b/tests/unit/lib/classes/AvatarClassTest.php @@ -0,0 +1,127 @@ +<?php + +/* + * Copyright (C) 2009 - Marcus Lunzenauer <mlunzena@uos.de> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + */ + +require_once 'lib/phplib/Seminar_Perm.class.php'; + +/** + * Testcase for Avatar class. + * + * @package studip + * @subpackage test + * + * @author mlunzena + * @copyright (c) Authors + */ +class AvatarTestCase extends \Codeception\Test\Unit { + + function setUp() + { + $stub = $this->createMock('Seminar_Perm'); + // Configure the stub. + $stub->expects($this->any()) + ->method('have_perm') + ->will($this->returnValue(true)); + + $GLOBALS['perm'] = $stub; + $GLOBALS['DYNAMIC_CONTENT_URL'] = "/dynamic"; + $GLOBALS['DYNAMIC_CONTENT_PATH'] = "/dynamic"; + $this->avatar_id = "123456789"; + $this->avatar = Avatar::getAvatar($this->avatar_id); + } + + function tearDown() { + 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); + } +} + + +class CourseAvatarTestCase extends \Codeception\Test\Unit +{ + + function setUp() { + $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"); + } + } + + function tearDown() { + 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); + } +} |
