11<?php
2-
32namespace CodeIgniter \Test ;
43
54use CodeIgniter \HTTP \Response ;
1514class TestCaseEmissionsTest extends \CIUnitTestCase
1615{
1716
18- // public function setUp()
19- // {
20- // while( count( ob_list_handlers() ) > 1 )
21- // {
22- // ob_end_clean();
23- // }
24- // ob_start(null, 0, PHP_OUTPUT_HANDLER_CLEANABLE);
25- // }
26- //
27- // public function tearDown()
28- // {
29- // ob_end_clean();
30- // }
31-
3217 //--------------------------------------------------------------------
3318 /**
3419 * This needs to be run as a separate process, since phpunit
@@ -44,37 +29,32 @@ class TestCaseEmissionsTest extends \CIUnitTestCase
4429 * the body we thought would be sent actually was.
4530 *
4631 * @runInSeparateProcess
32+ * @preserveGlobalState disabled
4733 */
48- public function testHeaderEmitted ()
34+ public function testHeadersEmitted ()
4935 {
36+
5037 $ response = new Response (new App ());
5138 $ response ->pretend (FALSE );
5239
5340 $ body = 'Hello ' ;
54- $ expected = $ body ;
41+ $ response -> setBody ( $ body) ;
5542
56- // what do we think we're about to send?
5743 $ response ->setCookie ('foo ' , 'bar ' );
5844 $ this ->assertTrue ($ response ->hasCookie ('foo ' ));
5945 $ this ->assertTrue ($ response ->hasCookie ('foo ' , 'bar ' ));
60-
61- $ response ->setBody ($ body );
62-
63- //echo 'ob level at '.ob_get_level();
64- ob_end_clean ();
65- ob_start (null , 0 , PHP_OUTPUT_HANDLER_CLEANABLE );
66- //$buffer = ob_get_clean(); // flush previous
46+
6747 // send it
68- // $buffer = ob_get_clean ();
48+ ob_start ();
6949 $ response ->send ();
70- $ buffer = ob_end_clean ();
71- // and what actually got sent?; test both ways
72- $ actual = $ response ->getBody (); // what we thought was sent
7350
74- $ this ->assertEquals ($ expected , $ actual );
51+ $ buffer = ob_clean ();
52+ if (ob_get_level () > 0 )
53+ ob_end_clean ();
54+
55+ // and what actually got sent?; test both ways
7556 $ this ->assertHeaderEmitted ("Set-Cookie: foo=bar; " );
7657 $ this ->assertHeaderEmitted ("set-cookie: FOO=bar " , true );
77-
7858 }
7959
8060 /**
@@ -91,32 +71,29 @@ public function testHeaderEmitted()
9171 * the body we thought would be sent actually was.
9272 *
9373 * @runInSeparateProcess
74+ * @preserveGlobalState disabled
9475 */
95- // public function testHeaderNotEmitted()
96- // {
97- // $response = new Response(new App());
98- // $response->pretend(FALSE);
99- //
100- // $body = 'Hello';
101- // $expected = $body;
102- //
103- // // what do we think we're about to send?
104- // $response->setCookie('foo', 'bar');
105- // $this->assertTrue($response->hasCookie('foo'));
106- // $this->assertTrue($response->hasCookie('foo', 'bar'));
107- //
108- // // send it
109- // $response->setBody($body);
110- //
111- // ob_start();
112- // $response->send();
113- // $output = ob_get_clean(); // what really was sent
114- // // and what actually got sent?; test both ways
115- // $actual = $response->getBody(); // what we thought was sent
116- //
117- // $this->assertEquals($expected, $actual);
118- // $this->assertEquals($expected, $output);
119- //
120- // $this->assertHeaderNotEmitted("Set-Cookie: pop=corn", true);
121- // }
76+ public function testHeadersNotEmitted ()
77+ {
78+ $ response = new Response (new App ());
79+ $ response ->pretend (FALSE );
80+
81+ $ body = 'Hello ' ;
82+ $ response ->setBody ($ body );
83+
84+ // what do we think we're about to send?
85+ $ response ->setCookie ('foo ' , 'bar ' );
86+ $ this ->assertTrue ($ response ->hasCookie ('foo ' ));
87+ $ this ->assertTrue ($ response ->hasCookie ('foo ' , 'bar ' ));
88+
89+ // send it
90+ ob_start ();
91+ $ response ->send ();
92+ $ output = ob_clean (); // what really was sent
93+ if (ob_get_level () > 0 )
94+ ob_end_clean ();
95+
96+ $ this ->assertHeaderNotEmitted ("Set-Cookie: pop=corn " , true );
97+ }
98+
12299}
0 commit comments