php - PHPunit set referer -



php - PHPunit set referer -

i have code below want test

class controller_test{ public function action_index(){ if(!$this->referred_from_site()){ echo "un-authorized request"; return; } echo "request ok"; } public function referred_from_site(){ if(strpos($this->request->referrer(),$_server['http_host']) !== false ){ homecoming true; } homecoming false; } }

now, in phpunit script can set value of $_server['http_host'] setup() function. but, how set value $this->request->referrer()? or how if want set value of function referred_from_site() true?

it function not parameter. suggest if want set it, utilize private variable. this.

class controller_test{ private referred = false; public function action_index(){ if(!$this->referred){ echo "un-authorized request"; return; } echo "request ok"; } public function referred_from_site(){ if(strpos($this->request->referrer(),$_server['http_host']) !== false ){ $this->referred = true; } $this->referred = false; } }

and way, don't think thought alter value of $_server['http_host'], utilize parameter such $server = $_server , mess $server['http_host'] = 'domain'

php testing phpunit

Comments

Popular posts from this blog

javascript - THREE.js reposition vertices for RingGeometry -

javascript - I need to update the text of a paragraph by inline edit -

assembly - What is the addressing mode for ld, add, and rjmp instructions? -