omit the PHP closing tag at EOF in all PHP files
[racktables] / tests / UserAccountTest.php
CommitLineData
e8d6d941
DO
1<?php
2
3class UserAccountTest extends PHPUnit_Framework_TestCase
4{
5 const PSWDHASH = 'f7563fd105b011264532ef2d405082015bed948e';
6 const REALNAME = 'Test User Account';
7 private $user_name;
8 private $user_id;
9
10 public function setUp ()
11 {
12 $this->user_name = sprintf ('testuser-%s-%u', get_class(), getmypid());
13 $this->user_id = commitCreateUserAccount ($this->user_name, self::REALNAME, self::PSWDHASH);
14 }
15
16 public function tearDown ()
17 {
18 usePreparedDeleteBlade ('UserAccount', array ('user_id' => $this->user_id));
19 }
20
21 /**
22 * @group small
23 */
24 public function testNormal ()
25 {
26 $this->assertArrayHasKey ($this->user_id, getAccountSearchResult ($this->user_name));
27 $this->assertEquals ($this->user_id, getUserIDByUsername ($this->user_name));
28 $this->assertNull (getUserIDByUsername ('x' . $this->user_name));
29 $user = spotEntity ('user', $this->user_id);
30 $this->assertEquals ($this->user_name, $user['user_name']);
31 $this->assertEquals (self::PSWDHASH, $user['user_password_hash']);
32 $this->assertEquals (self::REALNAME, $user['user_realname']);
33
34 $this->user_name = 'x' . $this->user_name;
35 commitUpdateUserAccount ($this->user_id, $this->user_name, 'x' . self::REALNAME, sha1 (self::PSWDHASH));
36
37 $this->assertArrayHasKey ($this->user_id, getAccountSearchResult ($this->user_name));
38 $this->assertEquals ($this->user_id, getUserIDByUsername ($this->user_name));
39 $this->assertNull (getUserIDByUsername ('x' . $this->user_name));
40 $user = spotEntity ('user', $this->user_id, TRUE);
41 $this->assertEquals ($this->user_name, $user['user_name']);
42 $this->assertEquals (sha1 (self::PSWDHASH), $user['user_password_hash']);
43 $this->assertEquals ('x' . self::REALNAME, $user['user_realname']);
44 }
45
46 /**
47 * @group small
48 * @expectedException RTDatabaseError
49 */
50 public function testDuplicate ()
51 {
52 commitCreateUserAccount ($this->user_name, 'x' . self::REALNAME, sha1 (self::PSWDHASH));
53 }
54}