index.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. require_once(__DIR__ . '/vendor/autoload.php');
  3. define(URL, 'http://ponape.com.ar/libre.fm/trunk/tests');
  4. define(USERNAME, 'testuser');
  5. define(PASSWORD, 'goodpassword');
  6. include('web/database.php');
  7. include('web/data/TagCloud.php');
  8. class testLibreFM extends PHPUnit_Framework_TestCase {
  9. function __construct () {
  10. $this->UnitTestCase();
  11. }
  12. function testDB () {
  13. global $mdb2, $connect_string;
  14. # Test if the connection string is more or less connectionstringesque :p
  15. $this->assertRegexp('/(mysql|sqlite|pgsql):\/\/[a-zA-Z0-9]*:.*@[a-zA-Z0-9]*:[0-9]*\/[a-zA-Z0-9_]*/', $connect_string);
  16. $this->assertFalse(PEAR::isError($mdb2));
  17. }
  18. function testTagCloud () {
  19. # Testing if we have an array as result
  20. $this->assertInstanceOf('array', TagCloud::generateTagCloud('Scrobbles', 'artist', 20, null));
  21. }
  22. function login ($username, $password) {
  23. $timestamp = time();
  24. $token = md5(md5($password) . $timestamp);
  25. $browser =& new SimpleBrowser();
  26. $browser->get('http://turtle.libre.fm/', array('hs' => 'true', 'u' => $username, 't' => $timestamp, 'a' => $token, 'c' => 'utt'));
  27. return $browser;
  28. }
  29. function testScrobbleBadAuth() {
  30. $this->assertTrue(true);
  31. }
  32. function WebLogin($username, $password) {
  33. $browser =& new SimpleBrowser();
  34. $browser->get(URL . '/web/login.php');
  35. $browser->setField('username', $username);
  36. $browser->setField('password', $password);
  37. $browser->clickSubmitByName('login');
  38. return $browser;
  39. }
  40. function testWebLoginBad() {
  41. $badlogin = $this->WebLogin(USERNAME, 'badpassword');
  42. $this->assertEquals($badlogin->getUrl(), URL . '/web/login.php');
  43. }
  44. function testWebLoginGood() {
  45. $goodlogin = $this->WebLogin(USERNAME, PASSWORD);
  46. $this->assertEquals($goodlogin->getUrl(), URL . '/web/index.php');
  47. }
  48. function testWebLogout() {
  49. $logout = $this->WebLogin(USERNAME, PASSWORD);
  50. $this->assertTrue(preg_match('/login\.php\?action=logout/', $logout->getContent()));
  51. $logout->click('logout');
  52. $this->assertFalse(preg_match('/login\.php\?action=logout/', $logout->getContentAsText()));
  53. }
  54. }
  55. $test = new testLibreFM();
  56. $test->run(new HtmlReporter());
  57. ?>