simpletestのBASIC認証とテキスト取得メモ

class CounterTest extends WebTestCase
{
    function CounterTest(){
        $this->WebTestCase('カウンターテスト');
    }

    function testCountUp(){
        $this->addHeader('Authorization: Basic ' . base64_encode(BASIC_USER.':'.BASIC_PASS));
        $this->get(COUNTER_MANAGE_URL);

        $browser = $this->getBrowser();
        $content = $browser->getContent();

        preg_match('|<td class="counter">(\d*)</td>|', $content, $matches);
        $count = $matches[1];
        $this->assertTrue(is_numeric($count), 'カウンタの数値を取得できません');

        // カウンタの更新テスト
        $this->get(TARGET_URL);

        $this->get(COUNTER_MANAGE_URL);
        $browser = $this->getBrowser();
        $content = $browser->getContent();

        preg_match('|<td class="counter">(\d*)</td>|', $content, $matches);
        $this->assertTrue(($count + 1) == $matches[1], "カウントアップ失敗:$count => $matches[1]");
    }
}

# 認証は authenticate($name, $password) でした