Author: chabotc
Date: Sun Aug 3 12:08:44 2008
New Revision: 682199
URL: http://svn.apache.org/viewvc?rev=682199&view=rev
Log:
Added several new tests for the common/ classes, got quite good code coverage
there now
Added:
incubator/shindig/trunk/php/test/TestContext.php
incubator/shindig/trunk/php/test/common/BasicBlobCrypterTest.php
incubator/shindig/trunk/php/test/common/BasicRemoteContentTest.php
incubator/shindig/trunk/php/test/common/BasicSecurityTokenTest.php
incubator/shindig/trunk/php/test/common/CryptoTest.php
incubator/shindig/trunk/php/test/common/JsMinTest.php
incubator/shindig/trunk/php/test/common/LocaleTest.php
Modified:
incubator/shindig/trunk/php/src/common/RemoteContentRequest.php
incubator/shindig/trunk/php/src/gadgets/GadgetContext.php
incubator/shindig/trunk/php/test/ShindigAllTests.php
incubator/shindig/trunk/php/test/index.php
Modified: incubator/shindig/trunk/php/src/common/RemoteContentRequest.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/RemoteContentRequest.php?rev=682199&r1=682198&r2=682199&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/common/RemoteContentRequest.php (original)
+++ incubator/shindig/trunk/php/src/common/RemoteContentRequest.php Sun Aug 3
12:08:44 2008
@@ -1,4 +1,5 @@
<?php
+
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -197,18 +198,20 @@
$options->ignoreCache = $ignoreCache;
return $this->createRemoteContentRequestWithUriOptions($uri,
$options);
}
-
+
/**
* Simple constructor for setting a basic response from a string.
Mostly used
* for testing.
*
* @param body
*/
- public function getHttpFalseResponseBody($body) {
+ public function getHttpFalseResponseBody($body)
+ {
return $this->createFalseResponse(RemoteContentRequest::$SC_OK,
$body, null);
}
-
- private function createFalseResponse($httpCode, $body, $headers) {
+
+ private function createFalseResponse($httpCode, $body, $headers)
+ {
$this->httpCode = $httpCode;
$this->responseContent = $body;
$this->headers = $headers;
@@ -346,7 +349,7 @@
}
return null;
}
-
+
public function getCreated()
{
return $this->created;
Modified: incubator/shindig/trunk/php/src/gadgets/GadgetContext.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/GadgetContext.php?rev=682199&r1=682198&r2=682199&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/GadgetContext.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/GadgetContext.php Sun Aug 3
12:08:44 2008
@@ -385,5 +385,4 @@
}
return $signer->createToken($token);
}
-
}
Modified: incubator/shindig/trunk/php/test/ShindigAllTests.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/ShindigAllTests.php?rev=682199&r1=682198&r2=682199&view=diff
==============================================================================
--- incubator/shindig/trunk/php/test/ShindigAllTests.php (original)
+++ incubator/shindig/trunk/php/test/ShindigAllTests.php Sun Aug 3 12:08:44
2008
@@ -25,11 +25,6 @@
* # phpunit ShindigAllTests php/test/ShindigAllTests.php
*/
-set_include_path(get_include_path(). PATH_SEPARATOR . realpath('./php') .
PATH_SEPARATOR . realpath('./php/external'));
-ini_set('error_reporting', E_COMPILE_ERROR | E_ERROR | E_CORE_ERROR);
-
-require_once 'config.php';
-
function __autoload($className)
{
$basePath = realpath('./php');
@@ -60,7 +55,12 @@
}
}
}
-;
+
+set_include_path(get_include_path(). PATH_SEPARATOR . realpath('./php') .
PATH_SEPARATOR . realpath('./php/external'));
+ini_set('error_reporting', E_COMPILE_ERROR | E_ERROR | E_CORE_ERROR);
+require_once 'config.php';
+require_once 'test/TestContext.php';
+
if (defined('PHPUnit_MAIN_METHOD') === false) {
define('PHPUnit_MAIN_METHOD', 'ShindigAllTests::main');
Added: incubator/shindig/trunk/php/test/TestContext.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/TestContext.php?rev=682199&view=auto
==============================================================================
--- incubator/shindig/trunk/php/test/TestContext.php (added)
+++ incubator/shindig/trunk/php/test/TestContext.php Sun Aug 3 12:08:44 2008
@@ -0,0 +1,35 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ *
+ */
+
+class TestContext extends GadgetContext {
+
+ public function __construct()
+ {
+ // construct a 'fake' context we can use for unit testing
+ $this->setRenderingContext('GADGET');
+ $this->setIgnoreCache(true);
+ $this->setForcedJsLibs('');
+ $this->setUrl('http://www.example.org/foo.xml');
+ $this->setModuleId(1);
+ $this->setView('profile');
+ $this->setContainer('test');
+ $this->setRefreshInterval(1);
+ }
+}
Added: incubator/shindig/trunk/php/test/common/BasicBlobCrypterTest.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/common/BasicBlobCrypterTest.php?rev=682199&view=auto
==============================================================================
--- incubator/shindig/trunk/php/test/common/BasicBlobCrypterTest.php (added)
+++ incubator/shindig/trunk/php/test/common/BasicBlobCrypterTest.php Sun Aug 3
12:08:44 2008
@@ -0,0 +1,79 @@
+<?php
+
+/**
+ * BasicBlobCrypter test case.
+ */
+class BasicBlobCrypterTest extends PHPUnit_Framework_TestCase {
+
+ /**
+ * @var BasicBlobCrypter
+ */
+ private $BasicBlobCrypter;
+
+ /**
+ * Prepares the environment before running a test.
+ */
+ protected function setUp()
+ {
+ parent::setUp();
+ $this->BasicBlobCrypter = new BasicBlobCrypter();
+ }
+
+ /**
+ * Cleans up the environment after running a test.
+ */
+ protected function tearDown()
+ {
+ $this->BasicBlobCrypter = null;
+ parent::tearDown();
+ }
+
+ /**
+ * Tests BasicBlobCrypter->__construct()
+ */
+ public function test__construct()
+ {
+ $this->BasicBlobCrypter->__construct();
+ }
+
+ /**
+ * Tests BasicBlobCrypter->wrap()
+ */
+ public function testWrap()
+ {
+ $test = array();
+ $test['o'] = 'o';
+ $test['v'] = 'v';
+ $test['a'] = 'a';
+ $test['d'] = 'd';
+ $test['u'] = 'u';
+ $test['m'] = 'm';
+ $wrapped = $this->BasicBlobCrypter->wrap($test);
+ $unwrapped = $this->BasicBlobCrypter->unwrap($wrapped, 3600);
+ $this->assertEquals($unwrapped['o'], 'o');
+ $this->assertEquals($unwrapped['v'], 'v');
+ $this->assertEquals($unwrapped['a'], 'a');
+ $this->assertEquals($unwrapped['d'], 'd');
+ $this->assertEquals($unwrapped['u'], 'u');
+ $this->assertEquals($unwrapped['m'], 'm');
+ }
+ /**
+ * Tests BasicBlobCrypter->wrap() exception
+ */
+ public function testWrapException()
+ {
+ $this->setExpectedException('BlobExpiredException');
+ $test = array();
+ $test['o'] = 'o';
+ $test['v'] = 'v';
+ $test['a'] = 'a';
+ $test['d'] = 'd';
+ $test['u'] = 'u';
+ $test['m'] = 'm';
+ $wrapped = $this->BasicBlobCrypter->wrap($test);
+ /* there is a 180 seconds clock skew allowed, so this way we
make sure it's expired */
+ $this->BasicBlobCrypter->unwrap($wrapped, -4000);
+ }
+
+}
+
Added: incubator/shindig/trunk/php/test/common/BasicRemoteContentTest.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/common/BasicRemoteContentTest.php?rev=682199&view=auto
==============================================================================
--- incubator/shindig/trunk/php/test/common/BasicRemoteContentTest.php (added)
+++ incubator/shindig/trunk/php/test/common/BasicRemoteContentTest.php Sun Aug
3 12:08:44 2008
@@ -0,0 +1,57 @@
+<?php
+
+require_once 'src/common/samplecontainer/BasicRemoteContent.php';
+
+require_once 'external/PHPUnit/Framework/TestCase.php';
+
+/**
+ * BasicRemoteContent test case.
+ */
+class BasicRemoteContentTest extends PHPUnit_Framework_TestCase {
+
+ /**
+ * @var BasicRemoteContent
+ */
+ private $BasicRemoteContent;
+
+ /**
+ * Prepares the environment before running a test.
+ */
+ protected function setUp()
+ {
+ parent::setUp();
+ $this->BasicRemoteContent = new BasicRemoteContent();
+ }
+
+ /**
+ * Cleans up the environment after running a test.
+ */
+ protected function tearDown()
+ {
+ $this->BasicRemoteContent = null;
+ parent::tearDown();
+ }
+
+ /**
+ * Tests BasicRemoteContent->fetch()
+ */
+ public function testFetch()
+ {
+ $request = new
RemoteContentRequest('http://test.chabotc.com/ok.html');
+ $context = new TestContext();
+ $ret = $this->BasicRemoteContent->fetch($request, $context);
+ $content = $ret->getResponseContent();
+ $this->assertEquals("OK\n", $content);
+ }
+
+ /**
+ * Tests BasicRemoteContent->fetch() 404 response
+ */
+ public function testFetch404()
+ {
+ $request = new
RemoteContentRequest('http://test.chabotc.com/fail.html');
+ $context = new TestContext();
+ $ret = $this->BasicRemoteContent->fetch($request, $context);
+ $this->assertEquals('404', $ret->getHttpCode());
+ }
+}
Added: incubator/shindig/trunk/php/test/common/BasicSecurityTokenTest.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/common/BasicSecurityTokenTest.php?rev=682199&view=auto
==============================================================================
--- incubator/shindig/trunk/php/test/common/BasicSecurityTokenTest.php (added)
+++ incubator/shindig/trunk/php/test/common/BasicSecurityTokenTest.php Sun Aug
3 12:08:44 2008
@@ -0,0 +1,104 @@
+<?php
+
+require_once 'src/common/samplecontainer/BasicSecurityToken.php';
+
+require_once 'external/PHPUnit/Framework/TestCase.php';
+
+/**
+ * BasicSecurityToken test case.
+ */
+class BasicSecurityTokenTest extends PHPUnit_Framework_TestCase {
+
+ /**
+ * @var BasicSecurityToken
+ */
+ private $BasicSecurityToken;
+
+ /**
+ * Prepares the environment before running a test.
+ */
+ protected function setUp()
+ {
+ parent::setUp();
+ $this->BasicSecurityToken =
BasicSecurityToken::createFromValues('owner', 'viewer', 'app', 'domain',
'appUrl', '1');
+ }
+
+ /**
+ * Cleans up the environment after running a test.
+ */
+ protected function tearDown()
+ {
+ $this->BasicSecurityToken = null;
+ parent::tearDown();
+ }
+
+ /**
+ * Tests BasicSecurityToken::createFromValues()
+ */
+ public function testCreateFromValues()
+ {
+ $token = BasicSecurityToken::createFromValues('owner',
'viewer', 'app', 'domain', 'appUrl', '1');
+ $this->assertEquals('owner', $token->getOwnerId());
+ $this->assertEquals('viewer', $token->getViewerId());
+ $this->assertEquals('app', $token->getAppId());
+ $this->assertEquals('domain', $token->getDomain());
+ $this->assertEquals('appUrl', $token->getAppUrl());
+ $this->assertEquals('1', $token->getModuleId());
+ }
+
+ /**
+ * Tests BasicSecurityToken->getAppId()
+ */
+ public function testGetAppId()
+ {
+ $this->assertEquals('app',
$this->BasicSecurityToken->getAppId());
+ }
+
+ /**
+ * Tests BasicSecurityToken->getAppUrl()
+ */
+ public function testGetAppUrl()
+ {
+ $this->assertEquals('appUrl',
$this->BasicSecurityToken->getAppUrl());
+ }
+
+ /**
+ * Tests BasicSecurityToken->getDomain()
+ */
+ public function testGetDomain()
+ {
+ $this->assertEquals('domain',
$this->BasicSecurityToken->getDomain());
+ }
+
+ /**
+ * Tests BasicSecurityToken->getModuleId()
+ */
+ public function testGetModuleId()
+ {
+ $this->assertEquals(1,
$this->BasicSecurityToken->getModuleId());
+ }
+
+ /**
+ * Tests BasicSecurityToken->getOwnerId()
+ */
+ public function testGetOwnerId()
+ {
+ $this->assertEquals('owner',
$this->BasicSecurityToken->getOwnerId());
+ }
+
+ /**
+ * Tests BasicSecurityToken->getViewerId()
+ */
+ public function testGetViewerId()
+ {
+ $this->assertEquals('viewer',
$this->BasicSecurityToken->getViewerId());
+ }
+
+ /**
+ * Tests BasicSecurityToken->isAnonymous()
+ */
+ public function testIsAnonymous()
+ {
+ $this->assertFalse($this->BasicSecurityToken->isAnonymous());
+ }
+}
Added: incubator/shindig/trunk/php/test/common/CryptoTest.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/common/CryptoTest.php?rev=682199&view=auto
==============================================================================
--- incubator/shindig/trunk/php/test/common/CryptoTest.php (added)
+++ incubator/shindig/trunk/php/test/common/CryptoTest.php Sun Aug 3 12:08:44
2008
@@ -0,0 +1,80 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ *
+ */
+
+/**
+ * Crypto test case.
+ */
+class CryptoTest extends PHPUnit_Framework_TestCase {
+
+ /**
+ * Tests Crypto::aes128cbcEncrypt()
+ */
+ public function testAes128()
+ {
+ $string = 'Lorem ipsum dolor sit amet, consectetuer adipiscing
elit';
+ $key = 'Aliquam erat volutpat';
+ $encrypted = Crypto::aes128cbcEncrypt($key, $string);
+ $decrypted = Crypto::aes128cbcDecrypt($key, $encrypted);
+ $this->assertEquals($decrypted, $string);
+ }
+
+ /**
+ * Tests Crypto::hmacSha1()
+ */
+ public function testHmacSha1()
+ {
+ $string = 'Lorem ipsum dolor sit amet, consectetuer adipiscing
elit';
+ $key = 'Aliquam erat volutpat';
+ $expected =
'%16%E7%E0E%22%08%5C%2B48%85d%FE%DE%C7%3A%C3%0D%11c';
+ $hmac = urlencode(Crypto::hmacSha1($key, $string));
+ $this->assertEquals($expected, $hmac);
+ }
+
+ /**
+ * Tests Crypto::hmacSha1Verify()
+ */
+ public function testHmacSha1VerifyException()
+ {
+ $string = 'Lorem ipsum dolor sit amet, consectetuer adipiscing
elit';
+ $key = 'Aliquam erat volutpat';
+ $expected = 'foo';
+ $this->setExpectedException('GeneralSecurityException');
+ Crypto::hmacSha1Verify($key, $string, $expected);
+ }
+
+ /**
+ * Tests Crypto::hmacSha1Verify()
+ */
+ public function testHmacSha1Verify()
+ {
+ $string = 'Lorem ipsum dolor sit amet, consectetuer adipiscing
elit';
+ $key = 'Aliquam erat volutpat';
+ $expected =
'%16%E7%E0E%22%08%5C%2B48%85d%FE%DE%C7%3A%C3%0D%11c';
+ try {
+ Crypto::hmacSha1Verify($key, $string,
urldecode($expected));
+ $success = true;
+ } catch (GeneralSecurityException $e) {
+ $success = false;
+ }
+ $this->assertTrue($success);
+ }
+
+}
+
Added: incubator/shindig/trunk/php/test/common/JsMinTest.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/common/JsMinTest.php?rev=682199&view=auto
==============================================================================
--- incubator/shindig/trunk/php/test/common/JsMinTest.php (added)
+++ incubator/shindig/trunk/php/test/common/JsMinTest.php Sun Aug 3 12:08:44
2008
@@ -0,0 +1,83 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * JsMin test case.
+ */
+class JsMinTest extends PHPUnit_Framework_TestCase {
+
+ /**
+ * @var JsMin
+ */
+ private $JsMin;
+
+ /**
+ * Prepares the environment before running a test.
+ */
+ protected function setUp()
+ {
+ parent::setUp();
+ $this->JsMin = new JsMin();
+ }
+
+ /**
+ * Cleans up the environment after running a test.
+ */
+ protected function tearDown()
+ {
+ $this->JsMin = null;
+ parent::tearDown();
+ }
+
+ /**
+ * Constructs the test case.
+ */
+ public function __construct()
+ {
+ }
+
+ /**
+ * Tests JsMin->__construct()
+ */
+ public function test__construct()
+ {
+ $this->JsMin->__construct();
+ }
+
+ /**
+ * Tests JsMin::minify()
+ */
+ public function testMinify()
+ {
+ $expect = "\nfunction foo(bar)\n{if(bar==2){return
true;}else{return false;}}";
+ $javascript =
+'
+function foo(bar)
+{
+ if (bar == 2) {
+ return true;
+ } else {
+ return false;
+ }
+}
+';
+ $this->assertEquals($expect, JsMin::minify($javascript));
+ }
+}
Added: incubator/shindig/trunk/php/test/common/LocaleTest.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/common/LocaleTest.php?rev=682199&view=auto
==============================================================================
--- incubator/shindig/trunk/php/test/common/LocaleTest.php (added)
+++ incubator/shindig/trunk/php/test/common/LocaleTest.php Sun Aug 3 12:08:44
2008
@@ -0,0 +1,88 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ *
+ */
+
+/**
+ * Locale test case.
+ */
+class LocaleTest extends PHPUnit_Framework_TestCase {
+
+ /**
+ * @var Locale
+ */
+ private $Locale;
+
+ /**
+ * Prepares the environment before running a test.
+ */
+ protected function setUp()
+ {
+ parent::setUp();
+ $this->Locale = new Locale('EN', 'US');
+ }
+
+ /**
+ * Cleans up the environment after running a test.
+ */
+ protected function tearDown()
+ {
+ $this->Locale = null;
+ parent::tearDown();
+ }
+
+ /**
+ * Constructs the test case.
+ */
+ public function __construct()
+ {
+ }
+
+ /**
+ * Tests Locale->__construct()
+ */
+ public function test__construct()
+ {
+ $this->Locale->__construct('EN', 'US');
+ }
+
+ /**
+ * Tests Locale->equals()
+ */
+ public function testEquals()
+ {
+ $locale = new Locale('EN', 'US');
+ $this->assertTrue($this->Locale->equals($locale));
+ }
+
+ /**
+ * Tests Locale->getCountry()
+ */
+ public function testGetCountry()
+ {
+ $this->assertEquals('US', $this->Locale->getCountry());
+ }
+
+ /**
+ * Tests Locale->getLanguage()
+ */
+ public function testGetLanguage()
+ {
+ $this->assertEquals('EN', $this->Locale->getLanguage());
+ }
+}
Modified: incubator/shindig/trunk/php/test/index.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/index.php?rev=682199&r1=682198&r2=682199&view=diff
==============================================================================
--- incubator/shindig/trunk/php/test/index.php (original)
+++ incubator/shindig/trunk/php/test/index.php Sun Aug 3 12:08:44 2008
@@ -23,6 +23,7 @@
require_once "PHPUnit/Framework/TestSuite.php";
require_once "PHPUnit/TextUI/TestRunner.php";
require_once realpath('../')."/config.php";
+require_once realpath('../')."/test/TestContext.php";
function __autoload($className)
{