function test_decode_ping_responce_invalid_state()
    {
        $this->setExpectedException('invalid_state_exception');

        $xml = "<?xml version=\"1.0\"?>
            <response>
                <protocol_version>0.1</protocol_version>
                <state>invalid</state>
                <error_msg></error_msg>
            </response>";

        $rmt = new mdl_remotes();
        $rmt->decode_ping_response($xml);
    }
    function test_ping_public()
    {
        $rmt_mck = new mck_mdl_remotes('sue', 'Big fat human');

        $xml = new SimpleXMLElement("<data></data>");
        $xml->addChild('remote_name',    'fred');
        $xml->addChild('remote_profile',  make_profile_url('fred'));
        $xml->addChild('remote_avatar',   APP_ROOT . 'media/default_avatar.jpg');
        $xml->addChild('remote_message', '@sue a message from fred');

        $rmt = new mdl_remotes();
        $_POST['data'] = 
            $rmt->send_ping('http://localhost/',
                'public', 'sue', $rmt_mck->get_pub_key(), $rmt_mck->get_priv_key(),
                $xml->asXML(), true);

        $msg = new ctrl_messages();

    // call ping
        ob_start();
        $msg->ping();
        $result = ob_get_contents();
        ob_end_clean();

        $xml = $rmt->decode_ping_response($result);

        $this->assertTrue($xml->state == 'success');

        $query = "SELECT * FROM `direct-message` WHERE
            `Remote_message` = '@sue a message from fred'";

        $result = mysql_query($query);

        $this->assertEquals(mysql_num_rows($result), 1);
    }
    function test_ping_remove()
    {
        $rmt_mck = new mck_mdl_remotes('sue', 'Big fat human');

        $rmt = new mdl_remotes();
        $_POST['data'] = $rmt->send_ping(
            'http://localhost',
            'remove',
            'fred',
            $rmt_mck->get_pub_key(),
            $rmt_mck->get_priv_key(),
            'http://localhost/messages/follow/sue',
            true);

        $rel = new ctrl_relations();

        ob_start();
        $rel->ping($rmt_mck);
        $result = ob_get_contents();
        ob_end_clean();

        $ping_response = $rmt->decode_ping_response($result);

        $this->assertEquals((string) $ping_response->state, 'fail');
    }