| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- <?php
- /*
- * This file is part of the php-phantomjs.
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- namespace JonnyW\PhantomJs\Test\Message;
- use JonnyW\PhantomJs\Message\Request;
- /**
- * PHP PhantomJs
- *
- * @author Jon Wenmoth <contact@jonnyw.me>
- */
- class RequestTest extends \PHPUnit_Framework_TestCase
- {
- /**
- * Test invalid URL's throw exception
- *
- * @dataProvider provideInvalidHosts
- *
- * @param string $url
- * @return void
- */
- public function testInvalidUrl($url)
- {
- $this->setExpectedException('JonnyW\\PhantomJs\\Exception\\InvalidUrlException');
- $request = new Request();
- $request->setUrl($url);
- }
- /**
- * Invalid host data providers
- *
- * @return array
- */
- public function provideInvalidHosts()
- {
- return array(
- array('invalid_url'),
- array('invalid_url.test')
- );
- }
- /**
- * Test invalid methods throw exception
- *
- * @dataProvider provideInvalidMethods
- *
- * @param string $method
- * @return void
- */
- public function testInvalidMethod($method)
- {
- $this->setExpectedException('JonnyW\\PhantomJs\\Exception\\InvalidMethodException');
- $request = new Request();
- $request->setMethod($method);
- }
- /**
- * Invalid method data providers
- *
- * @return array
- */
- public function provideInvalidMethods()
- {
- return array(
- array('GOT'),
- array('FIND')
- );
- }
- /**
- * Test invalid methods throw exception
- *
- * @return void
- */
- public function testGetRequestBody()
- {
- $data = array('name' => 'jonnyw', 'email' => 'contact@jonnyw.me');
- $request = new Request('GET', 'http://jonnyw.me');
- $request->setRequestData($data);
- $this->assertEmpty($request->getBody());
- }
- /**
- * Test GET URL parameters when URL
- * does not have existing parameters
- *
- * @return void
- */
- public function testGetUrlQuery()
- {
- $data = array('name' => 'jonnyw', 'email' => 'contact@jonnyw.me');
- $request = new Request('GET', 'http://jonnyw.me?query=true');
- $request->setRequestData($data);
- $this->assertEquals($request->getUrl(), 'http://jonnyw.me?query=true&' . urldecode(http_build_query($data)));
- }
- /**
- * Test GET URL parameters when URL
- * does not have existing parameters
- *
- * @return void
- */
- public function testGetUrlQueryClean()
- {
- $data = array('name' => 'jonnyw', 'email' => 'contact@jonnyw.me');
- $request = new Request('GET', 'http://jonnyw.me');
- $request->setRequestData($data);
- $this->assertEquals($request->getUrl(), 'http://jonnyw.me?' . urldecode(http_build_query($data)));
- }
- /**
- * Test invalid methods throw exception
- *
- * @return void
- */
- public function testPostRequestBody()
- {
- $data = array('name' => 'jonnyw', 'email' => 'contact@jonnyw.me');
- $request = new Request('POST', 'http://jonnyw.me');
- $request->setRequestData($data);
- $this->assertEquals($request->getBody(), urldecode(http_build_query($data)));
- }
- }
|