git.gnu.io has moved to IP address 209.51.188.249 -- please double check where you are logging in.

index.php 2.35 KB
Newer Older
1 2 3 4 5
<?php
require_once('simpletest/unit_tester.php');
require_once('simpletest/browser.php');
require_once('simpletest/reporter.php');

fauno's avatar
fauno committed
6 7 8
define(URL, 'http://ponape.com.ar/libre.fm/trunk/tests');
define(USERNAME, 'testuser');
define(PASSWORD, 'goodpassword');
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

include('web/database.php');
include('web/data/TagCloud.php');

class testLibreFM extends UnitTestCase {
    function __construct () {
        $this->UnitTestCase();
    }

    function testDB () {
        global $mdb2, $connect_string;
        # Test if the connection string is more or less connectionstringesque :p
        $this->assertWantedPattern('/(mysql|sqlite|pgsql):\/\/[a-zA-Z0-9]*:.*@[a-zA-Z0-9]*:[0-9]*\/[a-zA-Z0-9_]*/', $connect_string);
        $this->assertFalse(PEAR::isError($mdb2));
    }

    function testTagCloud () {
        # Testing if we have an array as result
        $this->assertIsA(TagCloud::generateTagCloud('Scrobbles', 'artist', 20, null), 'array');
    }
clint's avatar
clint committed
29

30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
    function login ($username, $password) {
        $timestamp = time();
        $token = md5(md5($password) . $timestamp);
        $browser =& new SimpleBrowser();
        $browser->get('http://turtle.libre.fm/', array('hs' => 'true', 'u' => $username, 't' => $timestamp, 'a' => $token, 'c' => 'utt'));
        return $browser;
    }

    function testScrobbleBadAuth() {
        $this->assertTrue(true);
    }

    function WebLogin($username, $password) {
        $browser =& new SimpleBrowser();
        $browser->get(URL . '/web/login.php');
        $browser->setField('username', $username);
        $browser->setField('password', $password);
        $browser->clickSubmitByName('login');

        return $browser;
    }

    function testWebLoginBad() {
fauno's avatar
fauno committed
53
        $badlogin = $this->WebLogin(USERNAME, 'badpassword');
54 55 56 57

        $this->assertEqual($badlogin->getUrl(), URL . '/web/login.php');
    }
    function testWebLoginGood() {
fauno's avatar
fauno committed
58
        $goodlogin = $this->WebLogin(USERNAME, PASSWORD);
59 60 61 62

        $this->assertEqual($goodlogin->getUrl(), URL . '/web/index.php');
    }
    function testWebLogout() {
fauno's avatar
fauno committed
63
        $logout = $this->WebLogin(USERNAME, PASSWORD);
64 65 66 67 68 69 70 71 72
        $this->assertTrue(preg_match('/login\.php\?action=logout/', $logout->getContent()));
        $logout->click('logout');
        $this->assertFalse(preg_match('/login\.php\?action=logout/', $logout->getContentAsText()));
    }
}

$test = new testLibreFM();
$test->run(new HtmlReporter());
?>