summaryrefslogtreecommitdiffstats
path: root/tests/lib/SimpleSAML/ModuleTest.php
blob: a3abf0e11460e1de5e5692f6fde13cf1fb0e2cd4 (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
<?php
namespace SimpleSAML\Test;

use SimpleSAML\Module;

class ModuleTest extends \PHPUnit_Framework_TestCase
{


    /**
     * Test for SimpleSAML\Module::isModuleEnabled().
     */
    public function testIsModuleEnabled()
    {
        // test for the most basic functionality
        $this->assertTrue(Module::isModuleEnabled('core'));
    }


    /**
     * Test for SimpleSAML\Module::getModuleDir().
     */
    public function testGetModuleDir()
    {
        // test for the most basic functionality
        $this->assertEquals(
            dirname(dirname(dirname(dirname(__FILE__)))).'/modules/module',
            Module::getModuleDir('module')
        );
    }


    /**
     * Test for SimpleSAML\Module::getModuleURL().
     */
    public function testGetModuleURL()
    {
        \SimpleSAML_Configuration::loadFromArray(array(
            'baseurlpath' => 'https://example.com/simplesaml/'
        ), '', 'simplesaml');
        $this->assertEquals(
            'https://example.com/simplesaml/module.php/module/script.php',
            Module::getModuleURL('module/script.php')
        );
        $this->assertEquals(
            'https://example.com/simplesaml/module.php/module/script.php?param1=value1&param2=value2',
            Module::getModuleURL('module/script.php', array(
                'param1' => 'value1',
                'param2' => 'value2',
            ))
        );
    }


    /**
     * Test for SimpleSAML\Module::getModules().
     */
    public function testGetModules()
    {
        $this->assertGreaterThan(0, count(Module::getModules()));
    }


    /**
     * Test for SimpleSAML\Module::resolveClass(). It will make sure that an exception is thrown if we are not asking
     * for a class inside a module (that is, there is no colon separating the name of the module and the name of the
     * class).
     *
     * @expectedException \Exception
     */
    public function testResolveClassNoModule()
    {
        Module::resolveClass('nomodule', '');
    }


    /**
     * Test for SimpleSAML\Module::resolveClass(). It will make sure that an exception is thrown if the class we are
     * asking for cannot be found.
     *
     * @expectedException \Exception
     */
    public function testResolveClassNotFound()
    {
        Module::resolveClass('core:Missing', '');
    }


    /**
     * Test for SimpleSAML\Module::resolveClass(). It will make sure that an exception is thrown if the class we are
     * asking for can be resolved, but does not extend a given class.
     *
     * @expectedException \Exception
     */
    public function testResolveClassNotSubclass()
    {
        Module::resolveClass('core:PHP', 'Auth_Process', '\Exception');
    }


    /**
     * Test for SimpleSAML\Module::resolveClass(). It covers all the valid use cases.
     */
    public function tesstResolveClass()
    {
        // most basic test
        $this->assertEquals('sspmod_core_ACL', Module::resolveClass('core:ACL', ''));

        // test for the $type parameter correctly translated into a path
        $this->assertEquals('sspmod_core_Auth_Process_PHP', Module::resolveClass('core:PHP', 'Auth_Process'));

        // test for valid subclasses
        $this->assertEquals('sspmod_core_Auth_Process_PHP', Module::resolveClass(
            'core:PHP',
            'Auth_Process',
            'SimpleSAML_Auth_ProcessingFilter'
        ));
    }
}