$t->diag('Absolute and relative URls'); $b = new sfWebBrowser(array(), $adapter); $t->like($b->get($askeet_params['url'])->getResponseText(), '/<h1>featured questions<\\/h1>/', 'get() understands absolute urls'); $t->like($b->get($askeet_params['url'] . '/index/1')->getResponseText(), '/<h1>popular questions<\\/h1>/', 'get() understands absolute urls'); $t->like($b->get('/recent/1')->getResponseText(), '/<h1>recent questions<\\/h1>/', 'get() understands relative urls with a trailing slash'); $t->like($b->get('/')->get('recent/1')->getResponseText(), '/<h1>recent questions<\\/h1>/', 'get() understands relative urls without a trailing slash'); /***********************/ /* Interaction methods */ /***********************/ $t->diag('Interaction methods'); $b = new sfWebBrowser(array(), $adapter); $t->like($b->get($askeet_params['url'])->click('activities')->getResponseText(), '/tag "activities"/', 'click() clicks on a link and executes the related request'); $t->like($b->get($askeet_params['url'])->click('/tag/activities')->getResponseText(), '/tag "activities"/', 'click() clicks on a link and executes the related request'); $t->like($b->click('askeet')->getResponseText(), '/<h1>featured questions<\\/h1>/', 'click() clicks on an image if it finds the argument in the alt'); $t->like($b->click('search it', array('search' => 'foo'))->getResponseText(), '/<h1>questions matching "foo"<\\/h1>/', 'click() clicks on a form input'); $t->like($b->setField('search', 'bar')->click('search it')->getResponseText(), '/<h1>questions matching "bar"<\\/h1>/', 'setField() fills a form input'); } catch (Exception $e) { $t->fail(sprintf('%s : skipping askeet related tests', $e->getMessage())); } /*******************************/ /* GET request with parameters */ /*******************************/ $t->diag('GET request with parameters'); $b = new sfWebBrowser(array(), $adapter); $test_params = array('foo' => 'bar', 'baz' => '1'); $t->like($b->get($dump_headers_url, $test_params)->getResponseText(), '/\\?foo=bar&baz=1/', 'get() can pass parameters with the second argument'); $t->like($b->get($dump_headers_url . '?' . http_build_query($test_params))->getResponseText(), '/\\?foo=bar&baz=1/', 'get() can pass parameters concatenated to the URI as a query string'); $t->unlike($b->get($dump_headers_url . '?' . http_build_query($test_params))->getResponseText(), '/\\?foo=bar&baz=1\\&/', 'get() with an URL already containing request parameters doesn\'t add an extra &'); $t->like($b->get($dump_headers_url . '?' . http_build_query($test_params), array('biz' => 'bil'))->getResponseText(), '/\\?foo=bar&baz=1&biz=bil/', 'get() can pass parameters concatenated to the URI as a query string and other parameters as a second argument'); $b = new sfWebBrowser(array(), $adapter); $b->get($dump_headers_url);
$web_browser = new sfWebBrowser(array(), "sfCurlAdapter", array('cookies' => true)); // delete the cookies if exist if (is_file($file = sfConfig::get('sf_data_dir') . '/sfWebBrowserPlugin/sfCurlAdapter/cookies.txt')) { unlink($file); } /** * Login to sandbox */ $t->comment('sfPaymentPayPal/sample'); $web_browser->get($sf_payment_paypal_test['application_url'] . '/sfPaymentPayPal/sample'); $t->comment('Pay with PayPal'); $web_browser->click('Pay with PayPal'); $t->comment('PayPal Sandbox'); $web_browser->click('PayPal Sandbox'); $t->comment('Login to sandbox'); $web_browser->setField('login_email', $sf_payment_paypal_test['developer_email'])->setField('login_password', $sf_payment_paypal_test['developer_password'])->click('Log In'); if (eregi("field_label_error", $web_browser->getResponseText()) || eregi('<span class="error">The email address or password you have entered does not match our records. Please try again.</span>', $web_browser->getResponseText())) { $t->fail('Could not login to paypal sandbox'); return; } else { $t->pass('Login successful'); } /* * Go back to site */ $t->comment('sfPaymentPayPal/sample'); $web_browser->get($sf_payment_paypal_test['application_url'] . '/sfPaymentPayPal/sample'); $t->comment('Pay with PayPal'); $web_browser->click('Pay with PayPal'); $t->comment('Go back to site'); // guessing the link and seller name