Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Get form action

By: a guest on Jan 19th, 2014  |  syntax: PHP  |  size: 0.84 KB  |  views: 38  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }