Closed volodymyroliinyk closed 4 years ago
Would you please show me sample test code?
Hi For example, it id real page in our system it closed for guest and opened for registered user http://some-domain.com/support/youtubefeeds
it is testing of controller YoutubeFeeds_test.php :
class YoutubeFeeds_test extends TestCase{
public function test_Pageurl() {
$this->request('GET', '/support/youtubefeeds');
$this->assertResponseCode(200);
}
}
->assertResponseCode(200) return 307 page code
ci-phpunit-test last version ubuntu PHPUnit 5.1.3 Codeigniter CI_VERSION 3.1.1
Always redirect to login page,when I run tests from terminal
1) Modules_test::test_save_module_data
CIPHPUnitTestRedirectException: Redirect to http://some-domain/login
/var/www/html/vhw/core/application/tests/_ci_phpunit_test/replacing/helpers/url_helper.php:79
/var/www/html/vhw/core/application/controllers/functions/Modules.php:29
/var/www/html/vhw/core/application/tests/_ci_phpunit_test/CIPHPUnitTestCase.php:93
/var/www/html/vhw/core/application/tests/controllers/Modules_test.php:5
How I can synchronize codeigniter and ci-phpunit-test sessions as codeigniter sessions, and doing all tests as registered user? Is it possible?
@volodymyroliinyk
it closed for guest and opened for registered user
You have to set session in your test code.
$_SESSION['logged_in'] = true;
Or the below example should work:
class Sessions extends CI_Controller
{
public function logged_in()
{
echo $this->session->logged_in;
}
}
class Sessions_test extends TestCase
{
public function test_logged_in()
{
$this->request->setCallable(
function ($CI) {
$CI->session->logged_in = 'true';
}
);
$output = $this->request('GET', 'sessions/logged_in');
$expected = 'true';
$this->assertEquals($expected, $output);
}
}
Thank you I will try at monday, but now I know that we dont use Codeigniter Session Library :(, we use simple php sessions which started from session_start()
If you still have the problem, feel free to reopen or create an issue.
ci-phpunit-test sessions and codeigniter sessions are different
$this->assertResponseCode(200); always return 307 code
How I can synchronize codeigniter and ci-phpunit-test sessions as codeigniter sessions, and doing all tests as registered user? Is it possible?