aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/lib/classes/AvatarClassTest.php
blob: cc7bbbcfcc2db12cdab4c0b8277806555ac20efe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
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);
  }
}