123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- <?php
- class InputTest extends PHPUnit_Framework_TestCase {
- /**
- * Setup the testing environment.
- */
- public function setUp()
- {
- Config::set('application.key', 'foo');
- }
- /**
- * Tear down the testing environemnt.
- */
- public function tearDown()
- {
- Input::$input = array();
- Config::set('application.key', '');
- Session::$instance = null;
- }
- /**
- * Test the Input::all method.
- *
- * @group laravel
- */
- public function testAllMethodReturnsInputAndFiles()
- {
- Input::$input = array('name' => 'Taylor');
- $_FILES = array('age' => 25);
- $this->assertEquals(Input::all(), array('name' => 'Taylor', 'age' => 25));
- }
- /**
- * Test the Input::has method.
- *
- * @group laravel
- */
- public function testHasMethodIndicatesTheExistenceOfInput()
- {
- $this->assertFalse(Input::has('foo'));
- Input::$input = array('name' => 'Taylor');
- $this->assertTrue(Input::has('name'));
- }
- /**
- * Test the Input::get method.
- *
- * @group laravel
- */
- public function testGetMethodReturnsInputValue()
- {
- Input::$input = array('name' => 'Taylor');
- $this->assertEquals('Taylor', Input::get('name'));
- $this->assertEquals('Default', Input::get('foo', 'Default'));
- }
- /**
- * Test the Input::only method.
- *
- * @group laravel
- */
- public function testOnlyMethodReturnsSubsetOfInput()
- {
- Input::$input = array('name' => 'Taylor', 'age' => 25);
- $this->assertEquals(array('name' => 'Taylor'), Input::only(array('name')));
- }
- /**
- * Test the Input::except method.
- *
- * @group laravel
- */
- public function testExceptMethodReturnsSubsetOfInput()
- {
- Input::$input = array('name' => 'Taylor', 'age' => 25);
- $this->assertEquals(array('age' => 25), Input::except(array('name')));
- }
- /**
- * Test the Input::old method.
- *
- * @group laravel
- */
- public function testOldInputCanBeRetrievedFromSession()
- {
- $this->setSession();
- Session::$instance->session['data']['laravel_old_input'] = array('name' => 'Taylor');
- $this->assertNull(Input::old('foo'));
- $this->assertTrue(Input::had('name'));
- $this->assertFalse(Input::had('foo'));
- $this->assertEquals('Taylor', Input::old('name'));
- }
- /**
- * Test the Input::file method.
- *
- * @group laravel
- */
- public function testFileMethodReturnsFromFileArray()
- {
- $_FILES['foo'] = array('name' => 'Taylor', 'size' => 100);
- $this->assertEquals('Taylor', Input::file('foo.name'));
- $this->assertEquals(array('name' => 'Taylor', 'size' => 100), Input::file('foo'));
- }
- /**
- * Test the Input::flash method.
- *
- * @group laravel
- */
- public function testFlashMethodFlashesInputToSession()
- {
- $this->setSession();
- Input::$input = $input = array('name' => 'Taylor', 'age' => 25);
- Input::flash();
- $this->assertEquals($input, Session::$instance->session['data'][':new:']['laravel_old_input']);
- Input::flash('only', array('name'));
- $this->assertEquals(array('name' => 'Taylor'), Session::$instance->session['data'][':new:']['laravel_old_input']);
- Input::flash('except', array('name'));
- $this->assertEquals(array('age' => 25), Session::$instance->session['data'][':new:']['laravel_old_input']);
- }
- /**
- * Test the Input::flush method.
- *
- * @group laravel
- */
- public function testFlushMethodClearsFlashedInput()
- {
- $this->setSession();
- Input::$input = $input = array('name' => 'Taylor');
- Input::flash();
- $this->assertEquals($input, Session::$instance->session['data'][':new:']['laravel_old_input']);
- Input::flush();
- $this->assertEquals(array(), Session::$instance->session['data'][':new:']['laravel_old_input']);
- }
- /**
- * Set the session payload instance.
- */
- protected function setSession()
- {
- $driver = $this->getMock('Laravel\\Session\\Drivers\\Driver');
- Session::$instance = new Laravel\Session\Payload($driver);
- }
- }
|