aboutsummaryrefslogtreecommitdiff
path: root/models/openid-php-openid-782224d/Tests/Auth/OpenID/TestUtil.php
blob: 28e3ca9af12b46e57af0f69d9335b764fc55db71 (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
<?php

/**
 * Utilites for test functions
 */


function Tests_Auth_OpenID_datafile($name, $reader)
{
    $path = dirname(realpath(__FILE__));
    $sep = DIRECTORY_SEPARATOR;
    $filename = $path . $sep . 'data' . $sep . $name;
    $data = $reader($filename);
    if ($data === false) {
        $msg = "Failed to open data file: $name";
        trigger_error($msg, E_USER_ERROR);
    }
    return $data;
}

function Tests_Auth_OpenID_readdata($name)
{
    return Tests_Auth_OpenID_datafile($name, 'file_get_contents');
}

function Tests_Auth_OpenID_readlines($name)
{
    return Tests_Auth_OpenID_datafile($name, 'file');
}

class OpenIDTestMixin extends PHPUnit_Framework_TestCase {
    function failUnlessOpenIDValueEquals($msg, $key, $expected, $ns=null)
    {
        if ($ns === null) {
            $ns = Auth_OpenID_OPENID_NS;
        }

        $actual = $msg->getArg($ns, $key);
        $error_format = 'Wrong value for openid.%s: expected=%s, actual=%s';
        $error_message = sprintf($error_format,
                                 $key, $expected, $actual);

        $this->assertEquals($expected, $actual, $error_message);
    }

    function failIfOpenIDKeyExists($msg, $key, $ns=null)
    {
        if ($ns === null) {
            $ns = Auth_OpenID_OPENID_NS;
        }

        $actual = $msg->getArg($ns, $key);
        $error_message = sprintf('openid.%s unexpectedly present: %s',
                                 $key, $actual);

        $this->assertFalse($msg->hasKey($ns, $key),
                           $error_message);
    }
}