Advertisement
Guest User

Get form action

a guest
Jan 19th, 2014
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.84 KB | None | 0 0
  1. <?php
  2.  
  3. class MyTest extends PHPUnit_Extensions_Selenium2TestCase{
  4.  
  5.     function setUp(){
  6.         $this->setBrowser("phantomjs");
  7.         $this->setBrowserUrl('http://localhost');
  8.         $this->setHost("127.0.0.1");
  9.         $this->setPort(4444);
  10.     }
  11.    
  12.     function testForm(){
  13.         $this->url('/test.html');
  14.        
  15.         $form = $this->byId('login-form');
  16.         $this->assertEquals('/post/login', $this->getRelativeFormAction($form));
  17.     }
  18.    
  19.     function getRelativeFormAction($form){
  20.         $action = $form->attribute('action');
  21.         $action = str_replace($this->getBaseUrl(), '', $action);
  22.         return $action;
  23.     }
  24.    
  25.     function getBaseUrl(){
  26.         $urlComponents = parse_url($this->url());
  27.         $url = "{$urlComponents['scheme']}://{$urlComponents['host']}";
  28.         return $url;
  29.     }
  30.    
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement