-
-
Save norv/2927930 to your computer and use it in GitHub Desktop.
Initial attempt at testing the user class. Still need to test user settings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace JawHare; | |
class UserTest extends \PHPUnit_Framework_TestCase | |
{ | |
static protected $user; | |
protected $user_data = array( | |
'username' => 'PHPUnitTest', | |
'fullname' => 'PHP Unit Testing', | |
'email' => 'phpunit@jawhare.org', | |
'salt' => 'NaCl', | |
'admin' => true, | |
'password' => 'BillyJoeBob', | |
); | |
static public function setUpBeforeClass() | |
{ | |
global $ini; | |
// User object needs the database | |
$db = Database($ini['database']); | |
self::$user = new User(); | |
// Clear out the user table | |
$db->query('DELETE FROM users'); | |
} | |
public function testSetterGetter() | |
{ | |
$user = self::$user; | |
$user->username($this->user_data['username']) | |
->fullname($this->user_data['fullname']) | |
->email($this->user_data['email']) | |
->salt($this->user_data['salt']) | |
->admin($this->user_data['username']) | |
->passwd($this->user_data['password']); | |
$settings = array( | |
'Foo' => 'bar', | |
'test' => 'nope', | |
'why?' => 'because' | |
); | |
foreach ($settings AS $var => $val) | |
$user->settings($var, $val); | |
$this->assertEquals($user->username(), $this->user_data['username']); | |
$this->assertEquals($user->fullname(), $this->user_data['fullname']); | |
$this->assertEquals($user->email(), $this->user_data['email']); | |
$this->assertEquals($user->salt(), $this->user_data['salt']); | |
$this->assertEquals($user->admin(), $this->user_data['admin']); | |
$this->assertTrue($user->validatepw($this->user_data['password'])); | |
} | |
/** | |
* @depends testSetterGetter | |
*/ | |
public function testSave() | |
{ | |
$user = self::$user; | |
$user->save(); | |
$this->assertNotEquals($user->id(), 0); | |
$this->assertNotNull($user->id()); | |
} | |
/** | |
* @depends testSave | |
*/ | |
public function testLoad() | |
{ | |
$user = self::$user; | |
$user2 = new User($user->id()); | |
foreach(array('id', 'username', 'fullname', 'email', 'salt', 'admin', 'password') AS $variable) | |
$this->assertEquals($user->$variable(), $user2->$variable(), $variable); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment