Example #1
0
 /**
  * Tests Mollom::httpParseQuery().
  */
 function testHttpParseQuery()
 {
     $input = 'foo=1&bar=2';
     $expected = array('foo' => 1, 'bar' => 2);
     $this->assertEquals($expected, Mollom::httpParseQuery($input));
     $input = 'checks=spam&checks=profanity';
     $expected = array('checks' => array('spam', 'profanity'));
     $this->assertEquals($expected, Mollom::httpParseQuery($input));
     // Mollom::httpParseQuery() does not attempt to work transparently. Thus,
     // multiple parameter names containing brackets itself (regular PHP syntax)
     // will lead to an "unexpected" result. Although it wouldn't be hard to add
     // support for this, there's currently no need for it.
     $input = 'checks[]=spam&checks[]=profanity';
     $expected = array('checks' => array(array('spam'), array('profanity')));
     $this->assertEquals($expected, Mollom::httpParseQuery($input));
     $input = 'checks=spam&checks=';
     $expected = array('checks' => array('spam', ''));
     $this->assertEquals($expected, Mollom::httpParseQuery($input));
     $input = 'checks=spam&checks';
     $expected = array('checks' => array('spam', ''));
     $this->assertEquals($expected, Mollom::httpParseQuery($input));
     $input = 'checks=spam&';
     $expected = array('checks' => 'spam');
     $this->assertEquals($expected, Mollom::httpParseQuery($input));
     $input = 'checks=spam';
     $expected = array('checks' => 'spam');
     $this->assertEquals($expected, Mollom::httpParseQuery($input));
 }