Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. <?php
  2.  
  3. $f3 = require('lib/base.php');
  4. $f3->set('DEBUG',5);
  5. $test=new Test();
  6.  
  7. $dbpath = __DIR__ . '/_test.sqlite';
  8. echo "Using test db: $dbpath\n";
  9.  
  10. $db=new DB\SQL('sqlite:'.$dbpath);
  11. $db->exec('CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT,username,pw)');
  12.  
  13. $user_mapper = new DB\SQL\Mapper($db, 'users');
  14. $user_mapper->username = 'theuser';
  15. $user_mapper->pw = password_hash('thepassword', PASSWORD_DEFAULT);
  16. $test->expect($user_mapper->save() > 0, 'Test user created successfully');
  17.  
  18. $user_mapper2 = new DB\SQL\Mapper($db, 'users');
  19. $auth = new \Auth($user_mapper2, [ 'id' => 'username', 'pw' => 'pw', 'pwhash' => TRUE ]);
  20.  
  21.  
  22. $test->expect($auth->login('theuser', 'thepassword'), 'Correct login was accepted');
  23. $test->expect(!$auth->login('wronguser', 'thepassword'), 'Wrong username was rejected');
  24. $test->expect(!$auth->login('theuser', 'thewrongpassword'), 'Wrong password was rejected');
  25.  
  26.  
  27. // Display the results; not MVC but let's keep it simple
  28. foreach ($test->results() as $result) {
  29. echo str_pad($result['text'],55)." ";
  30. if ($result['status'])
  31. echo 'Pass';
  32. else
  33. echo 'Fail ('.$result['source'].')';
  34. echo "\n";
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement