Skip to content

Commit

Permalink
Backport JHttp tests from Platform repo, add Apache config to repo to…
Browse files Browse the repository at this point in the history
… enable future testing
  • Loading branch information
mbabker committed Sep 17, 2014
1 parent 2c6ca10 commit 9524e7b
Show file tree
Hide file tree
Showing 9 changed files with 659 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ before_script:
- pyrus install -f pear/PHP_CodeSniffer-1.5.4
- pyrus install -f pear/Cache_Lite
- phpenv rehash
# Set up databases for testing
- mysql -e 'create database joomla_ut;'
- mysql joomla_ut < tests/unit/suites/database/stubs/mysql.sql
- psql -c 'create database joomla_ut;' -U postgres
- psql -d joomla_ut -a -f tests/unit/suites/database/stubs/postgresql.sql
# Set up Apache
# - ./build/travis/php-apache.sh
# Enable additional PHP extensions
- phpenv config-add build/travis/phpenv/memcached.ini
- phpenv config-add build/travis/phpenv/apc-$TRAVIS_PHP_VERSION.ini
- phpenv config-add build/travis/phpenv/redis.ini
Expand Down
18 changes: 18 additions & 0 deletions build/travis/apache2/php-apache
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<VirtualHost *:80>
DocumentRoot %TRAVIS_BUILD_DIR%

<Directory "%TRAVIS_BUILD_DIR%">
Options FollowSymLinks MultiViews ExecCGI
AllowOverride All
Order deny,allow
Allow from all
</Directory>

# Wire up Apache to use Travis CI's php-fpm.
<IfModule mod_fastcgi.c>
AddHandler php5-fcgi .php
Action php5-fcgi /php5-fcgi
Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi
FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -host 127.0.0.1:9000 -pass-header Authorization
</IfModule>
</VirtualHost>
12 changes: 12 additions & 0 deletions build/travis/php-apache.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

sudo apt-get install apache2 libapache2-mod-fastcgi
# enable php-fpm
sudo cp ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.conf.default ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.conf
sudo a2enmod rewrite actions fastcgi alias
echo "cgi.fix_pathinfo = 1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
~/.phpenv/versions/$(phpenv version-name)/sbin/php-fpm
# configure apache virtual hosts
sudo cp -f build/travis/apache2/php-apache /etc/apache2/sites-available/default
sudo sed -e "s?%TRAVIS_BUILD_DIR%?$(pwd)?g" --in-place /etc/apache2/sites-available/default
sudo service apache2 restart
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<const name="JTEST_DATABASE_PDO_MYSQL_DSN" value="host=localhost;dbname=joomla_ut;user=utuser;pass=ut1234" />
<const name="JTEST_DATABASE_POSTGRESQL_DSN" value="host=localhost;port=5432;dbname=joomla_ut;user=utuser;pass=ut1234" />
<const name="JTEST_DATABASE_SQLSRV_DSN" value="host=localhost;dbname=joomla_ut;user=utuser;pass=ut1234" />
<const name="JTEST_HTTP_STUB" value="http://localhost/joomla-cms/tests/unit/stubs/jhttp_stub.php" />
</php>
-->

Expand Down
53 changes: 53 additions & 0 deletions tests/unit/stubs/jhttp_stub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
/**
* @package Joomla.UnitTest
* @subpackage Http
*
* @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/

/**
* This is a stub file to aid in testing the JHttp transports. The idea is to echo
* back data that is sent from the transports so that assertions can be made and
* it can be ensured that proper data is being sent in the request.
*
* This file must be placed on a webserver in a location that can be accessed
* by the system that the test is running.
*/

$response = new stdClass;

$response->method = getVar($_SERVER, 'REQUEST_METHOD');
$response->http_user_agent = getVar($_SERVER, 'HTTP_USER_AGENT');
$response->request_uri = getVar($_SERVER, 'REQUEST_URI');
$response->query_string = getVar($_SERVER, 'QUERY_STRING');
$response->http_accept = getVar($_SERVER, 'HTTP_ACCEPT');
$response->http_accept_charset = getVar($_SERVER, 'HTTP_ACCEPT_CHARSET');
$response->http_accept_encoding = getVar($_SERVER, 'HTTP_ACCEPT_ENCODING');

$response->http_referer = getVar($_SERVER, 'HTTP_REFERER');

$response->get = $_GET;
$response->post = $_POST;
$response->files = $_FILES;
$response->cookies = $_COOKIE;

echo json_encode($response);


/**
* Retrieves a value from an array, returning a default value if not present
*
* @param array $array The array from which to retrieve a value.
* @param string $key The value to retrieve.
* @param mixed $default The value to return if the key isn't present.
*
* @return mixed
*
* @since 3.4
*/
function getVar($array, $key, $default = '')
{
return isset($array[$key]) ? $array[$key] : $default;
}
88 changes: 88 additions & 0 deletions tests/unit/suites/libraries/joomla/http/JHttpFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php
/**
* @package Joomla.UnitTest
* @subpackage Http
*
* @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/

/**
* Test class for JHttpFactory.
*
* @package Joomla.UnitTest
* @subpackage Http
* @since 3.4
*/
class JHttpFactoryTest extends PHPUnit_Framework_TestCase
{
/**
* Tests the getHttp method.
*
* @return void
*
* @since 3.4
*/
public function testGetHttp()
{
$this->assertInstanceOf(
'JHttp',
JHttpFactory::getHttp()
);
}

/**
* Tests the getHttp method for an exception.
*
* @return void
*
* @since 3.4
* @expectedException RuntimeException
*/
public function testGetHttpException()
{
$this->markTestSkipped('Cannot test correctly because a class_exists check is not performed.');

JHttpFactory::getHttp(new \Joomla\Registry\Registry, array('fopen'));
}

/**
* Tests the getAvailableDriver method.
*
* @return void
*
* @since 3.4
*/
public function testGetAvailableDriver()
{
$this->assertFalse(
JHttpFactory::getAvailableDriver(new \Joomla\Registry\Registry, array()),
'Passing an empty array should return false due to there being no adapters to test'
);

$this->markTestIncomplete('Cannot test next assertion correctly because a class_exists check is not performed.');

$this->assertFalse(
JHttpFactory::getAvailableDriver(new \Joomla\Registry\Registry, array('fopen')),
'A false should be returned if a class is not present or supported'
);
}

/**
* Tests the getHttpTransports method.
*
* @return void
*
* @since 3.4
*/
public function testGetHttpTransports()
{
$transports = JHttpFactory::getHttpTransports();

$this->assertEquals(
'curl',
$transports[0],
'CURL should be the first transport returned.'
);
}
}
Loading

0 comments on commit 9524e7b

Please sign in to comment.