示例#1
0
function testProgressProperlyCalculated()
{
    $w = getWidget();
    $addr = getBitcoinAddr($btcBalance = 2);
    # Case where widget uses BTC as base currency.
    $w->bitcoinAddress = $addr;
    $w->setGoal(4, Currencies\BTC());
    $w->save();
    $reloaded = Widget::getByID($w->id);
    assertTrue($reloaded->progressPercent > 49 && $reloaded->progressPercent < 51);
    # Case where widget uses fiat as base currency.
    setPriceForBTC(Currencies\USD(), 100);
    $w->bitcoinAddress = $addr;
    $w->setGoal(600, Currencies\USD());
    $w->save();
    $reloaded = Widget::getByID($w->id);
    $expected = 200 / 600 * 100;
    assertTrue($reloaded->progressPercent > floor($expected) && $reloaded->progressPercent < ceil($expected));
}
示例#2
0
function getWidget(User $u = null)
{
    require_once 'chipin/widgets.php';
    if ($u == null) {
        $u = getUser();
    }
    $w = new Widget();
    $w->ownerID = $u->id;
    $w->title = "Test Widget";
    $w->ending = new DateTime('2020-06-30');
    $w->setGoal(100, 'USD');
    $w->setDimensions(350, 310);
    $colors = Widgets\allowedColors();
    $w->color = $colors[0];
    $w->bitcoinAddress = getBitcoinAddr();
    $w->countryCode = 'CA';
    $w->about = "This is a test widget!";
    $w->save();
    return $w;
}