Пример #1
0
require_once INCLUDE_DIR . "web/ShortSession.php";
class TestShortSession extends PHPUnit2_Framework_TestCase
{
    public $userid = 999;
    function __construct()
    {
        $_REQUEST[LoginSession::SESSION_USERID] = $this->userid;
    }
    function testMakeCheck()
    {
        $date = new DateTime(sprintf("-%d min", ShortSession::ALIVE_TIME_MIN - 1));
        $key = ShortSession::get()->make($date);
        $_REQUEST[ShortSession::SESSION_SHORT] = $key;
        $result = ShortSession::get()->check();
        $this->assertSame($this->userid, $result);
    }
    function testMakeCheck_fail()
    {
        $date = new DateTime(sprintf("-%d min", ShortSession::ALIVE_TIME_MIN + 1));
        $key = ShortSession::get()->make($date);
        $_REQUEST[ShortSession::SESSION_SHORT] = $key;
        try {
            $result = ShortSession::get()->check();
        } catch (VoiceException $ex) {
            return;
        }
        $this->fail();
    }
}
runUnitTest('TestShortSession', INCLUDE_DIR . "web/ShortSession.php");
Пример #2
0
    {
        $info = new UserInfo($this->data);
        $this->assertEquals("", $info->checkPassword());
        $info = new UserInfo(array('password' => 'ab'));
        $this->assertEquals(UserInfo::CODE_PASSWORD_LENGTH, $info->checkPassword());
    }
    function testUpdateUser()
    {
        $info = new UserInfo($this->data);
        $store = new UserDB();
        $store->updateUser($info);
        $result = $store->getUser($info);
        $this->assertEquals($info->userid, $result->userid);
        $this->assertEquals($info->username, $result->username);
        $this->assertEquals($info->userStatus, $result->userStatus);
    }
    function testAuthorizeUser()
    {
        $info = new UserInfo($this->data);
        $store = new UserDB();
        $store->updateUser($info);
        $result = $store->authorizeUser($info);
        $this->assertEquals($info->userid, $result->userid);
        $this->assertEquals($info->username, $result->username);
        $fake = new UserInfo(array('username' => 'test', 'password' => 1111));
        $result = $store->authorizeUser($fake);
        $this->assertEquals(null, $result);
    }
}
runUnitTest('TestUserInfo', INCLUDE_DIR . "DB/UserInfo.php");
Пример #3
0
        $date = new DateTime();
        $this->data = array('user_id' => 999, 'update_date' => $date->format('Y-m-d'));
    }
    function testCopyRecord()
    {
        $key = new TempKey($this->data);
        $this->assertSame($this->data['user_id'], $key->userid);
        $this->assertSame($this->data['update_date'], $key->updateDate);
    }
    function testIsAlive()
    {
        $date = new DateTime("-3 day");
        $key = new TempKey(array('update_date' => $date->format("y-m-d")));
        $this->assertSame(false, $key->isAlive(2));
        $this->assertSame(true, $key->isAlive(4));
    }
    function testAuthorizeTempKey()
    {
        $key = new TempKey($this->data);
        $store = new TempKeyDB();
        $store->updateTempKey($key);
        $result = $store->authorizeTempKey($key);
        $this->assertSame($key->userid, $result->userid);
        $this->assertSame($key->tempKey, $result->tempKey);
        $dateOrigin = new DateTime($key->updateDate);
        $dateResult = new DateTime($result->updateDate);
        $this->assertSame($dateOrigin->format('Y-m-d'), $dateResult->format('Y-m-d'));
    }
}
runUnitTest('TestTempKey', INCLUDE_DIR . "DB/TempKey.php");
Пример #4
0
        $this->assertSame('artist', $result->artist);
        $this->assertSame('description', $result->description);
        $this->assertSame(array('hoge', 'huga'), $result->tags);
    }
    function testUpdatePlaying()
    {
        $info = new VoiceInfo($this->data);
        $infoSub = new VoiceInfo($this->dataSub);
        $store = new VoiceInfoDB();
        $store->updatePlaying($infoSub);
        $result = $store->getPlaying($infoSub);
        $this->assertSame(-998, $result->playedCount);
        $store->updatePlaying($info);
        $result = $store->getPlaying($info);
        $this->assertSame(-999, $result->playedCount);
    }
    function testGetInfosByUser()
    {
        $store = new VoiceInfoDB();
        $infos = $store->getInfosByUser(999);
        $this->assertSame(true, is_array($infos));
    }
    function testGetListByRecent()
    {
        $store = new VoiceInfoDB();
        $list = $store->getListByRecent(10);
        $this->assertSame(true, is_array($list));
    }
}
runUnitTest('TestVoiceInfo', INCLUDE_DIR . "DB/VoiceInfo.php");
Пример #5
0
<?php

require_once "../../../configure.php";
require_once INCLUDE_DIR . "util/UnitTestRun.php";
require_once INCLUDE_DIR . "File/FileCache.php";
class TestFileCache extends PHPUnit2_Framework_TestCase
{
    public $data;
    public $name = 'test';
    function __construct()
    {
        $this->data = array('hoge' => 'huga');
    }
    function testSet()
    {
        $cache = new FileCache();
        $cache->set($this->name, $this->data, new DateTime('+1 day'));
        $result = $cache->get($this->name);
        $this->assertSame($this->data, $result);
    }
    function testSet_expire()
    {
        $cache = new FileCache();
        $cache->set($this->name, $this->data, new DateTime('-1 day'));
        $result = $cache->get($this->name);
        $this->assertSame(null, $result);
    }
}
runUnitTest('TestFileCache', INCLUDE_DIR . "File/FileCache.php");
Пример #6
0
    function testGetMedia()
    {
        $info = new PlaylistInfo($this->data);
        $info->addMediaId('v4');
        $this->assertSame('v2', $info->getMediaId(1));
        $this->assertSame('v4', $info->getMediaId(3));
    }
    function testGetUpdateInfo()
    {
        $store = new PlaylistInfoDB();
        $info = new PlaylistInfo($this->data);
        $store->updateInfo($info);
        $result = $store->getInfo(999);
        $this->assertSame($info->title, $result->title);
        $this->assertSame($info->mediaids, $result->mediaids);
        $info->addMediaId('v4');
        $info->title = 'hoge';
        $store->updateInfo($info);
        $result = $store->getInfo(999);
        $this->assertSame($info->title, $result->title);
        $this->assertSame($info->mediaids, $result->mediaids);
    }
    function testGetUserInfos()
    {
        $store = new PlaylistInfoDB();
        $infos = $store->getUserInfos(999);
        $this->assertSame(true, count($infos) > 0);
    }
}
runUnitTest('TestPlaylistInfo', INCLUDE_DIR . "DB/PlaylistInfo.php");