function testRenderingVariousAmounts()
 {
     $cases = array(array(Currencies\BTC(), 0.01908, array('0.019 BTC', '0.02 BTC', '19 mBTC')), array(Currencies\BTC(), 0.0, array('0 BTC', '0.0 BTC')));
     foreach ($cases as $case) {
         list($currency, $btcAmount, $acceptableRenderings) = $case;
         $w = getWidget();
         $w->currency = $currency;
         $w->save();
         $this->setBalance($w->bitcoinAddress, $btcAmount);
         $this->browseToWidget($w);
         $raisedDiv = current($this->xpathQuery("//div[@class='raised']"));
         $matches = array_filter($acceptableRenderings, function ($t) use($raisedDiv) {
             return contains($raisedDiv->textContent, $t);
         });
         $matchFound = 1 == count($matches);
         assertTrue($matchFound, "Should render as one of following: " . implode(", ", $acceptableRenderings));
     }
 }
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));
}