Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $f3 = require('lib/base.php');
- $f3->set('DEBUG',5);
- $test=new Test();
- $dbpath = __DIR__ . '/_test.sqlite';
- echo "Using test db: $dbpath\n";
- $db=new DB\SQL('sqlite:'.$dbpath);
- $db->exec('CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT,username,pw)');
- $user_mapper = new DB\SQL\Mapper($db, 'users');
- $user_mapper->username = 'theuser';
- $user_mapper->pw = password_hash('thepassword', PASSWORD_DEFAULT);
- $test->expect($user_mapper->save() > 0, 'Test user created successfully');
- $user_mapper2 = new DB\SQL\Mapper($db, 'users');
- $auth = new \Auth($user_mapper2, [ 'id' => 'username', 'pw' => 'pw', 'pwhash' => TRUE ]);
- $test->expect($auth->login('theuser', 'thepassword'), 'Correct login was accepted');
- $test->expect(!$auth->login('wronguser', 'thepassword'), 'Wrong username was rejected');
- $test->expect(!$auth->login('theuser', 'thewrongpassword'), 'Wrong password was rejected');
- // Display the results; not MVC but let's keep it simple
- foreach ($test->results() as $result) {
- echo str_pad($result['text'],55)." ";
- if ($result['status'])
- echo 'Pass';
- else
- echo 'Fail ('.$result['source'].')';
- echo "\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement