Benjamin Eckstein
Benjamin Eckstein

Reputation: 894

Set different Input for Codeigniter My_ciunit Controller testing

i know how to set and execute a controller in order to test it.

See the framework link https://bitbucket.org/kenjis/my-ciunit

But how can i define the given test data Input? Ofcourse i can set $_GET and $_POST myself but does the input library reparse this?

I can't find answers at google. I'm also wondering why Codeigniter Testing has such poor google results.

<?php

/**
  * @group Controller
  */

class SomeControllerTest extends CIUnit_TestCase
{
public function setUp()
{
    // Set the tested controller
    $this->CI = set_controller('welcome');
}

public function testWelcomeController()
{

    // Call the controllers method
    $this->CI->index();

    // Fetch the buffered output
    $out = output();
            $viewData = viewvars();

    // Check if the content is OK
    $this->assertSame(0, preg_match('/(error|notice)/i', $out));
}

    public function testInput(){

        //reset $_GET and $_POST?

        $this->CI->login();

        //assert valid login etc ...
    }

}

Upvotes: 1

Views: 554

Answers (1)

davidethell
davidethell

Reputation: 12018

Yes, you will need to manually set the $_GET and $_POST values yourself in your test setup or wherever makes the most sense, e.g.:

public function setUp()
{
    // Set the tested controller
    $this->CI = set_controller('welcome');
    // Set up the input values
    $_GET['parameter_1'] = 'Some String';
    $_GET['parameter_2'] = 123;
}

Upvotes: 1

Related Questions