Flipkart

Thursday, July 1, 2010

Simpletest: submitFormByName

The SimpleTest PHP unit tester and web test framework.It has support for SSL, forms, frames, proxies and basic authentication. The idea is that common but fiddly PHP tasks, such as logging into a site, can be tested easily.

Unfortunately Simpletest doesnot provide a function for submit a form with its Name.But we can implement this function by 3 small changes in 3 different files.

1)browser.php 
        In this add below code

    function submitFormByName($name) {
        if (! ($form = &$this->_page->getFormByName($name))) {
            return false;
        }
        $success = $this->_load(
                $form->getAction(),
                $form->submit());
        return ($success ? $this->getContent() : $success);
    }


2)Page.php
        Add below function

    function &getFormByName($name) {
        for ($i = 0; $i < count($this->_complete_forms); $i++) {
            if ($this->_complete_forms[$i]->getName() == $name) {
                return $this->_complete_forms[$i];
            }
        }
        $null = null;
        return $null;
    }


3)Form.php

         Here u have to declare variable caleed
                     $this->_name = $tag->getAttribute('name'); 
        in constructor(SimpleForm) then add the function

    function getName() {
        return $this->_name;
    }


 Thats all. Now you can submit a form with its name also.


      

No comments:

Post a Comment