예제 #1
0
 /**
  * Testing the same URL with different data types for the placeholders
  */
 public function testRouteWrongDataType()
 {
     // create a request
     $request = Request::create('/blog/test/42');
     // Create a route
     $r = new Route('blogtest', '/blog/test/{page}', array('controller' => 'example:DemoController:hello'), array('page' => 'int'), array());
     // Test that the route matches the request
     $this->assertTrue($r->isMatch('/blog/test/42', $request));
     $r = new Route('another', '/blog/test/{page}', array('controller' => 'example:DemoController:hello'), array('page' => 'alpha'), array());
     $this->assertFalse($r->isMatch('/blog/test/42', $request));
 }
예제 #2
0
 /**
  * Same again, only for POST arguments
  */
 public function testPostArguments()
 {
     $request = Request::create('http://www.example.com/blog/42/testing-routes');
     $post = $request->post;
     $this->assertEquals($post->count(), 0);
     $request = Request::create('blog/42', 'POST', array('x' => 42, 'long_name' => 'Lots of data here'));
     $post = $request->post;
     $this->assertEquals($post->count(), 2);
     $this->assertTrue($post->has('x'));
     $this->assertTrue($post->has('long_name'));
     $this->assertFalse($post->has('y'));
     $request = Request::create('blog/42', 'POST', array('x' => 42, 'y' => '42 text message! £3.40 #trouble'));
     $post = $request->post;
     $x = $post->get('x');
     $this->assertEquals($x, 42);
     // get an int
     $x = $post->getInt('x');
     $this->assertSame($x, 42);
     $this->assertTrue(is_int($x));
     // get as text
     $text = $post->getText('x');
     $this->assertSame($text, '42');
     $this->assertTrue(is_string($text));
     // get only alpha chars
     $text = $post->getAlpha('y');
     $this->assertSame($text, 'textmessagetrouble');
     $this->assertTrue(is_string($text));
     // get only alpha num chars
     $text = $post->getAlphaNum('y');
     $this->assertSame($text, '42textmessage340trouble');
     // get only digit chars
     $text = $post->getDigits('y');
     $this->assertSame($text, '42340');
     // get something that isn't there
     $text = $post->getText('not_there');
     $this->assertSame($text, '');
     $text = $post->getText('not_there', 'default value');
     $this->assertSame($text, 'default value');
     $text = $post->getText('x', 'default value');
     $this->assertSame($text, '42');
 }