File: MongoAuthTest.php

package info (click to toggle)
php-mongo 1.4.5-1~bpo70%2B1
  • links: PTS
  • area: main
  • in suites: wheezy-backports
  • size: 9,828 kB
  • sloc: ansic: 13,275; xml: 1,702; php: 1,625; pascal: 255; makefile: 106; sh: 27
file content (58 lines) | stat: -rw-r--r-- 1,667 bytes parent folder | download | duplicates (2)
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
<?php
include 'Mongo/Auth.php';
include 'Mongo/Admin.php';

/**
 * Test class for MongoCollection.
 * Generated by PHPUnit on 2009-04-10 at 13:30:28.
 */
class MongoAuthTest extends PHPUnit_Framework_TestCase
{
    /**
     * @var    MongoAdmin
     * @access protected
     */
    protected $object;

    protected function setUp()
    {
        $this->object = new MongoAdmin();
        $this->object->login("testUser", "testPass");
    }

    public function testAdminBasic() {
        // make sure it behaves like a normal connection
        $this->object->selectCollection("phpunit", "c")->drop();
        $this->object->selectCollection("phpunit", "c")->insert(array("foo"=>"bar"));
        $x = $this->object->selectCollection("phpunit", "c")->findOne();
        $this->assertEquals("bar", $x["foo"]);
    }

    public function testAddUser() {
        /* check auth methods */
        $this->object->addUser("fred", "ted");
        MongoAuth::getHash("fred", "ted");
        $a2 = new MongoAdmin();
        $this->assertTrue($a2->connected);
        $a2->login("fred", "ted");
        $this->assertTrue($a2->loggedIn, json_encode($a2));

        $x = $this->object->changePassword("fred", "ted", "foobar");
        $this->assertEquals(1, $x['ok'], json_encode($x));

        $a2 = new MongoAdmin();
        $a2->login("fred", "ted");
        $this->assertFalse($a2->loggedIn);

        $a2 = new MongoAdmin();
        $a2->login("fred", "foobar");
        $this->assertTrue($a2->loggedIn);

        $this->object->deleteUser("fred");
        $a2 = new MongoAdmin();
        $a2->login("fred", "foobar");
        $this->assertFalse($a2->loggedIn);
    }
}

?>