You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by bh...@apache.org on 2010/08/16 23:26:21 UTC
svn commit: r986132 - in /shindig/trunk/php: ./ config/ src/common/
src/common/sample/ src/gadgets/ src/social/sample/ src/social/servlet/
test/ test/certs/ test/common/ test/gadgets/ test/misc/upload/ test/social/
Author: bhofmann
Date: Mon Aug 16 21:26:20 2010
New Revision: 986132
URL: http://svn.apache.org/viewvc?rev=986132&view=rev
Log:
various fixes and improvements for php unit tests
including:
- tests provide their own certificates for testing of signing functionality
- rest api tests do not rely on a working apache instance of shindig anymore.
any http calls are mocked instead.
- tests work from command line. any needes $_SERVER variables are set in the
tests
- tests can override the main configuration with own values
- some fixes in the provided sample json database
- deleted needles make-release.sh script
- deleted needles index.php in tests folder
http://codereview.appspot.com/1988044/show
Added:
shindig/trunk/php/config/test.php
shindig/trunk/php/test/certs/
shindig/trunk/php/test/certs/README
shindig/trunk/php/test/certs/private.key
shindig/trunk/php/test/certs/public.crt
Removed:
shindig/trunk/php/make-release.sh
shindig/trunk/php/test/index.php
Modified:
shindig/trunk/php/src/common/Config.php
shindig/trunk/php/src/common/sample/BasicRemoteContentFetcher.php
shindig/trunk/php/src/gadgets/ContainerConfig.php
shindig/trunk/php/src/social/sample/JsonDbOpensocialService.php
shindig/trunk/php/src/social/servlet/ApiServlet.php
shindig/trunk/php/test/ShindigAllTests.php
shindig/trunk/php/test/common/BasicRemoteContentTest.php
shindig/trunk/php/test/common/HttpServletTest.php
shindig/trunk/php/test/gadgets/ContainerConfigTest.php
shindig/trunk/php/test/gadgets/MakeRequestTest.php
shindig/trunk/php/test/misc/upload/upload.xml
shindig/trunk/php/test/social/InputAtomConverterTest.php
shindig/trunk/php/test/social/InputJsonConverterTest.php
shindig/trunk/php/test/social/InputXmlConverterTest.php
shindig/trunk/php/test/social/MediaItemRestTest.php
shindig/trunk/php/test/social/OutputAtomConverterTest.php
shindig/trunk/php/test/social/OutputJsonConverterTest.php
shindig/trunk/php/test/social/OutputXmlConverterTest.php
shindig/trunk/php/test/social/RestBase.php
shindig/trunk/php/test/social/RestRequestItemTest.php
Added: shindig/trunk/php/config/test.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/config/test.php?rev=986132&view=auto
==============================================================================
--- shindig/trunk/php/config/test.php (added)
+++ shindig/trunk/php/config/test.php Mon Aug 16 21:26:20 2010
@@ -0,0 +1,29 @@
+<?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.
+ */
+
+/**
+ * this configuration overrides some values for unit testing purposes
+ * you should not use these settings in production
+ */
+$shindigConfig = array(
+ 'private_key_file' => realpath(dirname(__FILE__) . '/../test/certs') . '/private.key',
+ 'public_key_file' => realpath(dirname(__FILE__) . '/../test/certs') . '/public.crt',
+ 'private_key_phrase' => 'partuza',
+);
\ No newline at end of file
Modified: shindig/trunk/php/src/common/Config.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/src/common/Config.php?rev=986132&r1=986131&r2=986132&view=diff
==============================================================================
--- shindig/trunk/php/src/common/Config.php (original)
+++ shindig/trunk/php/src/common/Config.php Mon Aug 16 21:26:20 2010
@@ -28,18 +28,20 @@ class ConfigException extends Exception
class Config {
private static $config = false;
- static private function loadConfig() {
+ static public function loadConfig($local = 'local') {
global $shindigConfig;
if (! self::$config) {
// load default configuration
include_once realpath(dirname(__FILE__) . "/../../config") . '/container.php';
self::$config = $shindigConfig;
- $localConfigPath = realpath(dirname(__FILE__) . "/../../config") . '/local.php';
- if (file_exists($localConfigPath)) {
- // include local.php if it exists and merge the config arrays.
- // the second array values overwrites the first one's
- include_once $localConfigPath;
- self::$config = array_merge(self::$config, $shindigConfig);
+ if ($local) {
+ $localConfigPath = realpath(dirname(__FILE__) . "/../../config") . '/' . $local . '.php';
+ if (file_exists($localConfigPath)) {
+ // include local.php if it exists and merge the config arrays.
+ // the second array values overwrites the first one's
+ include_once $localConfigPath;
+ self::$config = array_merge(self::$config, $shindigConfig);
+ }
}
}
}
Modified: shindig/trunk/php/src/common/sample/BasicRemoteContentFetcher.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/src/common/sample/BasicRemoteContentFetcher.php?rev=986132&r1=986131&r2=986132&view=diff
==============================================================================
--- shindig/trunk/php/src/common/sample/BasicRemoteContentFetcher.php (original)
+++ shindig/trunk/php/src/common/sample/BasicRemoteContentFetcher.php Mon Aug 16 21:26:20 2010
@@ -83,7 +83,7 @@ class BasicRemoteContentFetcher extends
* @param RemoteContentRequest $request
* @param string $content
*/
- private function parseResult(RemoteContentRequest $request, $content) {
+ protected function parseResult(RemoteContentRequest $request, $content) {
$headers = '';
$body = '';
$httpCode = curl_getinfo($request->handle, CURLINFO_HTTP_CODE);
Modified: shindig/trunk/php/src/gadgets/ContainerConfig.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/src/gadgets/ContainerConfig.php?rev=986132&r1=986131&r2=986132&view=diff
==============================================================================
--- shindig/trunk/php/src/gadgets/ContainerConfig.php (original)
+++ shindig/trunk/php/src/gadgets/ContainerConfig.php Mon Aug 16 21:26:20 2010
@@ -48,7 +48,7 @@ class ContainerConfig {
private function loadFromFile($file) {
$contents = file_get_contents($file);
- $contents = self::removeComments($contents);
+ $contents = $this->removeComments($contents);
$config = json_decode($contents, true);
if ($config == $contents) {
throw new Exception("Failed to json_decode the container configuration");
@@ -63,7 +63,7 @@ class ContainerConfig {
}
}
- public static function removeComments($str) {
+ public function removeComments($str) {
// remove /* */ style comments
$str = preg_replace('@/\\*.*?\\*/@s', '', $str);
// remove // style comments, but keep 'http://' 'https://' and '"//'
Modified: shindig/trunk/php/src/social/sample/JsonDbOpensocialService.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/src/social/sample/JsonDbOpensocialService.php?rev=986132&r1=986131&r2=986132&view=diff
==============================================================================
--- shindig/trunk/php/src/social/sample/JsonDbOpensocialService.php (original)
+++ shindig/trunk/php/src/social/sample/JsonDbOpensocialService.php Mon Aug 16 21:26:20 2010
@@ -124,6 +124,10 @@ class JsonDbOpensocialService implements
}
}
+ public function resetDb() {
+ @unlink(sys_get_temp_dir() . '/' . $this->jsonDbFileName);
+ }
+
private function getAllPeople() {
$db = $this->getDb();
$peopleTable = $db[self::$PEOPLE_TABLE];
@@ -774,7 +778,7 @@ class JsonDbOpensocialService implements
public function updateAlbum($userId, $groupId, $album, $token) {
$all = $this->getAllAlbums();
- if (! $all[$userId->getUserId($token)] || ! $all[$userId->getUserId($token)][$album['id']]) {
+ if (! $album['id'] || ! $all[$userId->getUserId($token)] || ! $all[$userId->getUserId($token)][$album['id']]) {
throw new SocialSpiException("Album not found.", ResponseError::$BAD_REQUEST);
}
$origin = $all[$userId->getUserId($token)][$album['id']];
@@ -797,7 +801,8 @@ class JsonDbOpensocialService implements
public function deleteAlbum($userId, $groupId, $albumId, $token) {
$all = $this->getAllAlbums();
- if (! $all[$userId->getUserId($token)] || ! $all[$userId->getUserId($token)][$albumId]) {
+ $albumId = $albumId[0];
+ if (! $albumId || ! $all[$userId->getUserId($token)] || ! $all[$userId->getUserId($token)][$albumId]) {
throw new SocialSpiException("Album not found.", ResponseError::$BAD_REQUEST);
}
if ($all[$userId->getUserId($token)][$albumId]['ownerId'] != $userId->getUserId($token)) {
@@ -836,6 +841,8 @@ class JsonDbOpensocialService implements
$id = isset($all[$albumId]) ? (count($all[$albumId]) + 1) : 0;
$mediaItem['id'] = $id;
$mediaItem['lastUpdated'] = time();
+ $mediaItem['created'] = $mediaItem['lastUpdated'];
+ $mediaItem['numComments'] = 0;
if (isset($mediaItem['type'])) {
$mediaItem['type'] = strtoupper($mediaItem['type']);
if (! in_array($mediaItem['type'], MediaItem::$TYPES)) {
@@ -861,7 +868,6 @@ class JsonDbOpensocialService implements
$origin = $all[$mediaItem['albumId']][$mediaItem['id']];
$mediaItem['lastUpdated'] = time();
$mediaItem['created'] = $origin['created'];
- $mediaItem['fileSize'] = $orgin['fileSize'];
$mediaItem['numComments'] = $origin['numComments'];
if (isset($mediaItem['type'])) {
$mediaItem['type'] = strtoupper($mediaItem['type']);
Modified: shindig/trunk/php/src/social/servlet/ApiServlet.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/src/social/servlet/ApiServlet.php?rev=986132&r1=986131&r2=986132&view=diff
==============================================================================
--- shindig/trunk/php/src/social/servlet/ApiServlet.php (original)
+++ shindig/trunk/php/src/social/servlet/ApiServlet.php Mon Aug 16 21:26:20 2010
@@ -18,30 +18,30 @@
* under the License.
*/
-require 'src/social/service/DataRequestHandler.php';
-require 'src/common/SecurityToken.php';
-require 'src/common/BlobCrypter.php';
-require 'src/social/converters/InputConverter.php';
-require 'src/social/converters/InputJsonConverter.php';
-require 'src/social/converters/OutputConverter.php';
-require 'src/social/converters/OutputJsonConverter.php';
-require 'src/social/service/RequestItem.php';
-require 'src/social/service/RestRequestItem.php';
-require 'src/social/service/RpcRequestItem.php';
-require 'src/social/spi/GroupId.php';
-require 'src/social/spi/UserId.php';
-require 'src/social/spi/CollectionOptions.php';
-require 'src/common/Cache.php';
-require 'src/social/model/ComplexField.php';
-require 'src/social/model/Name.php';
-require 'src/social/model/Enum.php';
-require 'src/social/model/Person.php';
-require 'src/social/model/ListField.php';
-require 'src/social/model/Photo.php';
-require 'src/social/spi/RestfulCollection.php';
-require 'src/social/spi/DataCollection.php';
-require 'src/social/service/ResponseItem.php';
-require 'src/common/ShindigOAuth.php';
+require_once 'src/social/service/DataRequestHandler.php';
+require_once 'src/common/SecurityToken.php';
+require_once 'src/common/BlobCrypter.php';
+require_once 'src/social/converters/InputConverter.php';
+require_once 'src/social/converters/InputJsonConverter.php';
+require_once 'src/social/converters/OutputConverter.php';
+require_once 'src/social/converters/OutputJsonConverter.php';
+require_once 'src/social/service/RequestItem.php';
+require_once 'src/social/service/RestRequestItem.php';
+require_once 'src/social/service/RpcRequestItem.php';
+require_once 'src/social/spi/GroupId.php';
+require_once 'src/social/spi/UserId.php';
+require_once 'src/social/spi/CollectionOptions.php';
+require_once 'src/common/Cache.php';
+require_once 'src/social/model/ComplexField.php';
+require_once 'src/social/model/Name.php';
+require_once 'src/social/model/Enum.php';
+require_once 'src/social/model/Person.php';
+require_once 'src/social/model/ListField.php';
+require_once 'src/social/model/Photo.php';
+require_once 'src/social/spi/RestfulCollection.php';
+require_once 'src/social/spi/DataCollection.php';
+require_once 'src/social/service/ResponseItem.php';
+require_once 'src/common/ShindigOAuth.php';
/**
* Common base class for API servlets.
Modified: shindig/trunk/php/test/ShindigAllTests.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/test/ShindigAllTests.php?rev=986132&r1=986131&r2=986132&view=diff
==============================================================================
--- shindig/trunk/php/test/ShindigAllTests.php (original)
+++ shindig/trunk/php/test/ShindigAllTests.php Mon Aug 16 21:26:20 2010
@@ -21,15 +21,15 @@
/*
* This file is meant to be run through a php command line or cruiscontrol build, and not called directly
* through the web browser. To run these tests from the command line:
- * # cd /path/to/shindig
- * # phpunit ShindigAllTests php/test/ShindigAllTests.php
+ * # cd /path/to/shindig/php
+ * # phpunit ShindigAllTests test/ShindigAllTests.php
*/
function __autoload($className) {
- $basePath = realpath('./php');
+ $basePath = realpath('./');
$locations = array('src/common', 'src/common/sample', 'src/gadgets', 'src/gadgets/http', 'src/gadgets/oauth',
- 'src/gadgets/sample', 'src/social', 'src/social/http', 'src/social/service',
- 'src/social/converters', 'src/social/opensocial', 'src/social/spi', 'src/social/model',
+ 'src/gadgets/sample', 'src/gadgets/render', 'src/gadgets/rewrite', 'src/gadgets/templates', 'src/social', 'src/social/http', 'src/social/service',
+ 'src/social/converters', 'src/social/opensocial', 'src/social/spi', 'src/social/model', 'src/social/servlet',
'src/social/sample', 'src/social/oauth');
$extension_class_paths = Config::get('extension_class_paths');
if (! empty($extension_class_paths)) {
@@ -45,11 +45,11 @@ function __autoload($className) {
}
}
-set_include_path(get_include_path() . PATH_SEPARATOR . realpath('./php') . PATH_SEPARATOR . realpath('./php/external'));
+set_include_path(get_include_path() . PATH_SEPARATOR . realpath('.') . PATH_SEPARATOR . realpath('./external'));
error_reporting(E_ALL | E_STRICT);
require_once 'src/common/Config.php';
+Config::loadConfig('test');
require_once 'test/TestContext.php';
-
if (defined('PHPUnit_MAIN_METHOD') === false) {
define('PHPUnit_MAIN_METHOD', 'ShindigAllTests::main');
}
@@ -63,7 +63,7 @@ class ShindigAllTests {
public static function suite() {
$suite = new PHPUnit_Framework_TestSuite();
$suite->setName('Shindig');
- $path = realpath('./php/test/');
+ $path = realpath('./test/');
$testTypes = array('common', 'gadgets', 'social');
foreach ($testTypes as $type) {
foreach (glob("$path/{$type}/*Test.php") as $file) {
Added: shindig/trunk/php/test/certs/README
URL: http://svn.apache.org/viewvc/shindig/trunk/php/test/certs/README?rev=986132&view=auto
==============================================================================
--- shindig/trunk/php/test/certs/README (added)
+++ shindig/trunk/php/test/certs/README Mon Aug 16 21:26:20 2010
@@ -0,0 +1,5 @@
+These keys are just used for unit test and should never be used in production.
+
+Goto the certs directory shindig/php/certs and create your own public and private keys
+with your own password there.
+
Added: shindig/trunk/php/test/certs/private.key
URL: http://svn.apache.org/viewvc/shindig/trunk/php/test/certs/private.key?rev=986132&view=auto
==============================================================================
--- shindig/trunk/php/test/certs/private.key (added)
+++ shindig/trunk/php/test/certs/private.key Mon Aug 16 21:26:20 2010
@@ -0,0 +1,18 @@
+-----BEGIN RSA PRIVATE KEY-----
+Proc-Type: 4,ENCRYPTED
+DEK-Info: DES-EDE3-CBC,FA1FDD216DED3C69
+
+BFekZznDqWZAAtEryw/br7Yh3U8b0NWxgWQXPlaxlE3gQQYA8PJB4Jh/cjw7V4kQ
+PcZddQSZ3KcN9a915aVoLdOJfp3RTOXk8wIRYBQ2o17ap7T/ylJlT0/qQdWp/3bh
+s3FnY19ZaX2dAfh2ETCqWFoLMn+RuT8xgju3uMM9N9NmaQ080n/KGvl09Ljb9ul3
+91J3SrDT5IpfbAGicpcmyAV3WsQQC1FQsP3oJyADp/63oZeIuVFsrfAgRfR2xUwd
+sS0mawHHEIDsZBPc/9tiiSA+a9QZrrcrra3RtOg2gFF6oErZuO0Ot7lI+Q6QbKPk
+tNrMitIwMd6qQdTT3gBHbAzhk1D6db2k5gWOki74bxJMyWVDX01i5ncU8jn34p2g
+6yDrjiEGdVACS/xHKeGJk/mBL8y/0wMq4yENHeEnQbFbYBo9NUOCsMc+Ja9DuLKs
+o+dUWBHrGk6wyWBHi6I0Jox3hBQqrE8a5bVj+jvlck5Z+/ncOvVu8K7eL57yhQzr
+RVW43qx/rqg5Diz3HEajo/I9qBEOidIBtijPXPkR9lSjXZlQrF6ItIA7HV14grCW
+ZvycEttN5Z9OlnujbHddYHbTNb7ncLG+XfemWBVMWzDGLEEq8uYaLnFRTtbOdTT4
+EBARGw2MF6JRxYmEkf1yYGq61Hp1LAduF+UHodgH4tAg82KxLEKBC1ZPdSSF8pNq
+3iaspbPSJo/ZGvI9uWUY+lyv4tsCa4HC62cU/TMjxNB6ll+HC5CYNyi96pdryeEW
++tPkpYxX6Oyv20gzwaqyv3MaYuHz+nHsJt87bW6CrGX4v2fzP2/maA==
+-----END RSA PRIVATE KEY-----
Added: shindig/trunk/php/test/certs/public.crt
URL: http://svn.apache.org/viewvc/shindig/trunk/php/test/certs/public.crt?rev=986132&view=auto
==============================================================================
--- shindig/trunk/php/test/certs/public.crt (added)
+++ shindig/trunk/php/test/certs/public.crt Mon Aug 16 21:26:20 2010
@@ -0,0 +1,16 @@
+-----BEGIN CERTIFICATE-----
+MIICkjCCAfugAwIBAgIJAI4XlVLWTYStMA0GCSqGSIb3DQEBBQUAMDsxCzAJBgNV
+BAYTAlVTMRMwEQYDVQQIEwpTb21lLVN0YXRlMRcwFQYDVQQKEw5BcGFjaGUgU2hp
+bmRpZzAeFw0xMDA4MTUxNjAyMDZaFw0xMTA4MTUxNjAyMDZaMDsxCzAJBgNVBAYT
+AlVTMRMwEQYDVQQIEwpTb21lLVN0YXRlMRcwFQYDVQQKEw5BcGFjaGUgU2hpbmRp
+ZzCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAxXdIKgzLkMp1xlHyP+qwlvZX
+Doz2kr/uC3UCoJHEG5bIvO3JZ5YQBDhQeNq2HyWzyi9645HHtU3WsnonJTL0WHYo
+zXCwTesJrgRVDFxoQfvRu2E9p78rX1QtaLSdDgQGJkNO2MFMz7d2V+ADMPEEBJYg
+E2qj2eOwjY5qJv356skCAwEAAaOBnTCBmjAdBgNVHQ4EFgQU/NfE6kopCs7uO3Ni
+602hPU4GWGswawYDVR0jBGQwYoAU/NfE6kopCs7uO3Ni602hPU4GWGuhP6Q9MDsx
+CzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpTb21lLVN0YXRlMRcwFQYDVQQKEw5BcGFj
+aGUgU2hpbmRpZ4IJAI4XlVLWTYStMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEF
+BQADgYEAj/QV42ys1V1TCi1C56BUD9e1oJVArEmlKITjlFQk4MNE55zgdvUSySHF
+rhfkqnQYuczJRL52r5SvzM06bjpNumDJYFwpKOlwYz05LFTCrOLhJF4YmtOPoHJp
+xvYLtrT6xJb192cTHDyiw8aqGa/f0An5C2fD9P9NCmiHZQazg6U=
+-----END CERTIFICATE-----
Modified: shindig/trunk/php/test/common/BasicRemoteContentTest.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/test/common/BasicRemoteContentTest.php?rev=986132&r1=986131&r2=986132&view=diff
==============================================================================
--- shindig/trunk/php/test/common/BasicRemoteContentTest.php (original)
+++ shindig/trunk/php/test/common/BasicRemoteContentTest.php Mon Aug 16 21:26:20 2010
@@ -42,6 +42,7 @@ class MockSigningFetcherFactory {
* @here will create a private key.
*/
public function __construct() {
+ $_SERVER["HTTP_HOST"] = 'localhost';
$privkey = openssl_pkey_new();
$phrase = Config::get('private_key_phrase') != '' ? (Config::get('private_key_phrase')) : null;
openssl_pkey_export($privkey, $rsa_private_key, $phrase);
Modified: shindig/trunk/php/test/common/HttpServletTest.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/test/common/HttpServletTest.php?rev=986132&r1=986131&r2=986132&view=diff
==============================================================================
--- shindig/trunk/php/test/common/HttpServletTest.php (original)
+++ shindig/trunk/php/test/common/HttpServletTest.php Mon Aug 16 21:26:20 2010
@@ -54,6 +54,7 @@ class HttpServletTest extends PHPUnit_Fr
protected function tearDown() {
$this->HttpServlet = null;
+ ob_end_clean();
parent::tearDown();
}
Modified: shindig/trunk/php/test/gadgets/ContainerConfigTest.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/test/gadgets/ContainerConfigTest.php?rev=986132&r1=986131&r2=986132&view=diff
==============================================================================
--- shindig/trunk/php/test/gadgets/ContainerConfigTest.php (original)
+++ shindig/trunk/php/test/gadgets/ContainerConfigTest.php Mon Aug 16 21:26:20 2010
@@ -69,7 +69,8 @@ class ContainerConfigTest extends PHPUni
"gadgets.oauthGadgetCallbackTemplate" : "//%host%/gadgets/oauthcallback"
}
EOD;
- $uncommented = ContainerConfig::removeComments($jsFile);
+ $containerConfig = new ContainerConfig(Config::get('container_path'));
+ $uncommented = $containerConfig->removeComments($jsFile);
$jsonObj = json_decode($uncommented, true);
$this->assertNotEquals($uncommented, $jsonObj);
$this->assertEquals(array("default"), $jsonObj["gadgets.container"]);
Modified: shindig/trunk/php/test/gadgets/MakeRequestTest.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/test/gadgets/MakeRequestTest.php?rev=986132&r1=986131&r2=986132&view=diff
==============================================================================
--- shindig/trunk/php/test/gadgets/MakeRequestTest.php (original)
+++ shindig/trunk/php/test/gadgets/MakeRequestTest.php Mon Aug 16 21:26:20 2010
@@ -35,6 +35,7 @@ class MockMakeRequestFetcher extends Rem
* Constructor.
*/
public function __construct() {
+ $_SERVER["HTTP_HOST"] = 'localhost';
$this->responses = array();
$this->requests = array();
}
@@ -161,7 +162,7 @@ class MakeRequestTest extends PHPUnit_Fr
$params = new MakeRequestOptions('http://www.example.com');
$params->setAuthz('SIGNED')
->setNoCache(true)
- ->setSecurityTokenString(urlencode(base64_encode($token->toSerialForm())));
+ ->setSecurityTokenString(urldecode($token->toSerialForm()));
$request = $this->catchRequest($params, $this->response);
@@ -183,7 +184,7 @@ class MakeRequestTest extends PHPUnit_Fr
$params->setAuthz('SIGNED')
->setNoCache(true)
->setSignViewer(false)
- ->setSecurityTokenString(urlencode(base64_encode($token->toSerialForm())));
+ ->setSecurityTokenString(urldecode($token->toSerialForm()));
$request = $this->catchRequest($params, $this->response);
Modified: shindig/trunk/php/test/misc/upload/upload.xml
URL: http://svn.apache.org/viewvc/shindig/trunk/php/test/misc/upload/upload.xml?rev=986132&r1=986131&r2=986132&view=diff
==============================================================================
--- shindig/trunk/php/test/misc/upload/upload.xml (original)
+++ shindig/trunk/php/test/misc/upload/upload.xml Mon Aug 16 21:26:20 2010
@@ -27,7 +27,7 @@
function initData() {
var jsonInput = document.getElementById("json-input");
- jsonInput.value = ' [ { "method":"mediaitems.create", "params": {"albumId":"1", "mediaItem": { "id" : "11223344", "thumbnailUrl" : "http://pages.example.org/images/11223344-tn.png", "mimeType" : "image/png", "type" : "image", "url" : "@field:1.jpg", "albumId" : "1" } } } ]';
+ jsonInput.value = ' [ { "method":"mediaitems.create", "params": {"albumId":"1", "mediaItem": { "id" : "11223344", "thumbnailUrl" : "http://www.libpng.org/pub/png/img_png/pngnow.png", "mimeType" : "image/png", "type" : "image", "url" : "@field:1.jpg", "albumId" : "1" } } } ]';
gadgets.window.adjustHeight();
}
Modified: shindig/trunk/php/test/social/InputAtomConverterTest.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/test/social/InputAtomConverterTest.php?rev=986132&r1=986131&r2=986132&view=diff
==============================================================================
--- shindig/trunk/php/test/social/InputAtomConverterTest.php (original)
+++ shindig/trunk/php/test/social/InputAtomConverterTest.php Mon Aug 16 21:26:20 2010
@@ -151,7 +151,7 @@ class InputAtomConverterTest extends PHP
<content type="application/xml">
<album xmlns="http://ns.opensocial.org/2008/opensocial">
<id>44332211</id>
- <thumbnailUrl>http://pages.example.org/albums/4433221-tn.png</thumbnailUrl>
+ <thumbnailUrl>http://www.libpng.org/pub/png/img_png/pngnow.png</thumbnailUrl>
<caption>Example Album</caption>
<description>This is an example album, and this text is an example description</description>
<location>
@@ -168,7 +168,7 @@ class InputAtomConverterTest extends PHP
</entry>';
$album = $this->inputAtomConverter->convertAlbums($xml);
$this->assertEquals('44332211', $album['id']);
- $this->assertEquals('http://pages.example.org/albums/4433221-tn.png', $album['thumbnailUrl']);
+ $this->assertEquals('http://www.libpng.org/pub/png/img_png/pngnow.png', $album['thumbnailUrl']);
$this->assertEquals('This is an example album, and this text is an example description', $album['description']);
$this->assertEquals('Example Album', $album['title']);
$this->assertEquals('example.org:55443322', $album['ownerId']);
@@ -182,10 +182,10 @@ class InputAtomConverterTest extends PHP
<content type="application/xml">
<mediaItem xmlns="http://ns.opensocial.org/2008/opensocial">
<id>11223344</id>
- <thumbnailUrl>http://pages.example.org/images/11223344-tn.png</thumbnailUrl>
+ <thumbnailUrl>http://www.libpng.org/pub/png/img_png/pngnow.png</thumbnailUrl>
<mimeType>image/png</mimeType>
<type>image</type>
- <url>http://pages.example.org/images/11223344.png</url>
+ <url>http://www.libpng.org/pub/png/img_png/pngnow.png</url>
<albumId>44332211</albumId>
</mediaItem>
</content>
@@ -196,9 +196,9 @@ class InputAtomConverterTest extends PHP
</entry>';
$mediaItem = $this->inputAtomConverter->convertMediaItems($xml);
$this->assertEquals('11223344', $mediaItem['id']);
- $this->assertEquals('http://pages.example.org/images/11223344-tn.png', $mediaItem['thumbnailUrl']);
+ $this->assertEquals('http://www.libpng.org/pub/png/img_png/pngnow.png', $mediaItem['thumbnailUrl']);
$this->assertEquals('44332211', $mediaItem['albumId']);
- $this->assertEquals('http://pages.example.org/images/11223344.png', $mediaItem['url']);
+ $this->assertEquals('http://www.libpng.org/pub/png/img_png/pngnow.png', $mediaItem['url']);
$this->assertEquals('image/png', $mediaItem['mimeType']);
}
}
Modified: shindig/trunk/php/test/social/InputJsonConverterTest.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/test/social/InputJsonConverterTest.php?rev=986132&r1=986131&r2=986132&view=diff
==============================================================================
--- shindig/trunk/php/test/social/InputJsonConverterTest.php (original)
+++ shindig/trunk/php/test/social/InputJsonConverterTest.php Mon Aug 16 21:26:20 2010
@@ -121,17 +121,17 @@ class InputJsonConverterTest extends PHP
public function testConvertMediaItem() {
$json = '{ "id" : "11223344",
- "thumbnailUrl" : "http://pages.example.org/images/11223344-tn.png",
+ "thumbnailUrl" : "http://www.libpng.org/pub/png/img_png/pngnow.png",
"mimeType" : "image/png",
"type" : "image",
- "url" : "http://pages.example.org/images/11223344.png",
+ "url" : "http://www.libpng.org/pub/png/img_png/pngnow.png",
"albumId" : "44332211"
}';
$mediaItem = $this->inputJsonConverter->convertMediaItems($json);
$this->assertEquals('11223344', $mediaItem['id']);
- $this->assertEquals('http://pages.example.org/images/11223344-tn.png', $mediaItem['thumbnailUrl']);
+ $this->assertEquals('http://www.libpng.org/pub/png/img_png/pngnow.png', $mediaItem['thumbnailUrl']);
$this->assertEquals('44332211', $mediaItem['albumId']);
- $this->assertEquals('http://pages.example.org/images/11223344.png', $mediaItem['url']);
+ $this->assertEquals('http://www.libpng.org/pub/png/img_png/pngnow.png', $mediaItem['url']);
$this->assertEquals('image/png', $mediaItem['mimeType']);
}
}
Modified: shindig/trunk/php/test/social/InputXmlConverterTest.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/test/social/InputXmlConverterTest.php?rev=986132&r1=986131&r2=986132&view=diff
==============================================================================
--- shindig/trunk/php/test/social/InputXmlConverterTest.php (original)
+++ shindig/trunk/php/test/social/InputXmlConverterTest.php Mon Aug 16 21:26:20 2010
@@ -134,7 +134,7 @@ class InputXmlConverterTest extends PHPU
$xml = '<?xml version="1.0" encoding="UTF-8"?>
<album xmlns="http://ns.opensocial.org/2008/opensocial">
<id>44332211</id>
- <thumbnailUrl>http://pages.example.org/albums/4433221-tn.png</thumbnailUrl>
+ <thumbnailUrl>http://www.libpng.org/pub/png/img_png/pngnow.png</thumbnailUrl>
<caption>Example Album</caption>
<description>This is an example album, and this text is an example description</description>
<location>
@@ -145,7 +145,7 @@ class InputXmlConverterTest extends PHPU
</album>';
$album = $this->inputXmlConverter->convertAlbums($xml);
$this->assertEquals('44332211', $album['id']);
- $this->assertEquals('http://pages.example.org/albums/4433221-tn.png', $album['thumbnailUrl']);
+ $this->assertEquals('http://www.libpng.org/pub/png/img_png/pngnow.png', $album['thumbnailUrl']);
$this->assertEquals('This is an example album, and this text is an example description', $album['description']);
$this->assertEquals('Example Album', $album['title']);
$this->assertEquals('example.org:55443322', $album['ownerId']);
@@ -158,17 +158,17 @@ class InputXmlConverterTest extends PHPU
$xml = '<?xml version="1.0" encoding="UTF-8"?>
<mediaItem xmlns="http://ns.opensocial.org/2008/opensocial">
<id>11223344</id>
- <thumbnailUrl>http://pages.example.org/images/11223344-tn.png</thumbnailUrl>
+ <thumbnailUrl>http://www.libpng.org/pub/png/img_png/pngnow.png</thumbnailUrl>
<mimeType>image/png</mimeType>
<type>image</type>
- <url>http://pages.example.org/images/11223344.png</url>
+ <url>http://www.libpng.org/pub/png/img_png/pngnow.png</url>
<albumId>44332211</albumId>
</mediaItem>';
$mediaItem = $this->inputXmlConverter->convertMediaItems($xml);
$this->assertEquals('11223344', $mediaItem['id']);
- $this->assertEquals('http://pages.example.org/images/11223344-tn.png', $mediaItem['thumbnailUrl']);
+ $this->assertEquals('http://www.libpng.org/pub/png/img_png/pngnow.png', $mediaItem['thumbnailUrl']);
$this->assertEquals('44332211', $mediaItem['albumId']);
- $this->assertEquals('http://pages.example.org/images/11223344.png', $mediaItem['url']);
+ $this->assertEquals('http://www.libpng.org/pub/png/img_png/pngnow.png', $mediaItem['url']);
$this->assertEquals('image/png', $mediaItem['mimeType']);
}
}
\ No newline at end of file
Modified: shindig/trunk/php/test/social/MediaItemRestTest.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/test/social/MediaItemRestTest.php?rev=986132&r1=986131&r2=986132&view=diff
==============================================================================
--- shindig/trunk/php/test/social/MediaItemRestTest.php (original)
+++ shindig/trunk/php/test/social/MediaItemRestTest.php Mon Aug 16 21:26:20 2010
@@ -24,7 +24,7 @@ class MediaItemRestTest extends RestBase
protected function setUp() {
$postData = '{ "id" : "44332211",
- "thumbnailUrl" : "http://pages.example.org/albums/4433221-tn.png",
+ "thumbnailUrl" : "http://www.libpng.org/pub/png/img_png/pngnow.png",
"title" : "Example Album",
"description" : "This is an example album, and this text is an example description",
"location" : { "latitude": 0, "longitude": 0 },
@@ -45,16 +45,6 @@ class MediaItemRestTest extends RestBase
// $this->assertTrue(empty($ret), "Delete the created album failed. Response: $ret");
}
- private function curlGet($url) {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- $ret = curl_exec($ch);
- curl_close($ch);
- return $ret;
- }
-
private function verifyLifeCycle($postData, $postDataFormat) {
$url = '/mediaitems/1/@self/' . $this->album['id'];
$ret = $this->curlRest($url, $postData, $postDataFormat);
@@ -65,10 +55,8 @@ class MediaItemRestTest extends RestBase
$this->assertFalse(empty($ret));
$fetched = json_decode($ret, true);
$fetched = $fetched['entry'][0];
- $data = $this->curlGet($fetched['url']);
- $this->assertTrue(substr($data, 0, strlen('GIF')) == 'GIF');
- $this->assertEquals('http://pages.example.org/images/11223344-tn.png', $fetched['thumbnailUrl'], "thumbnailUrl should be same.");
- $this->assertEquals('image/gif', $fetched['mimeType'], "mimeType should be same.");
+ $this->assertEquals('http://www.libpng.org/pub/png/img_png/pngnow.png', $fetched['thumbnailUrl'], "thumbnailUrl should be same.");
+ $this->assertEquals('image/png', $fetched['mimeType'], "mimeType should be same.");
$this->assertEquals('IMAGE', $fetched['type'], "type should be same.");
$fetched['thumbnailUrl'] = 'http://changed.com/tn.png';
$ret = $this->curlRest($url . '/' . urlencode($mediaItem['id']), json_encode($fetched), 'application/json', 'PUT');
@@ -77,7 +65,7 @@ class MediaItemRestTest extends RestBase
$fetched = json_decode($ret, true);
$fetched = $fetched['entry'][0];
$this->assertEquals('http://changed.com/tn.png', $fetched['thumbnailUrl'], "thumbnailUrl should be same.");
- $this->assertEquals('image/gif', $fetched['mimeType'], "mimeType should be same.");
+ $this->assertEquals('image/png', $fetched['mimeType'], "mimeType should be same.");
$this->assertEquals('IMAGE', $fetched['type'], "type should be same.");
$ret = $this->curlRest($url . '/' . urlencode($mediaItem['id']), '', 'application/json', 'DELETE');
@@ -91,7 +79,7 @@ class MediaItemRestTest extends RestBase
public function testLifeCycleInJson() {
$postData = '{ "id" : "11223344",
- "thumbnailUrl" : "http://pages.example.org/images/11223344-tn.png",
+ "thumbnailUrl" : "http://www.libpng.org/pub/png/img_png/pngnow.png",
"mimeType" : "image/png",
"type" : "image",
"url" : "http://www.google.com/intl/en_ALL/images/logo.gif",
@@ -104,7 +92,7 @@ class MediaItemRestTest extends RestBase
$postData = '<?xml version="1.0" encoding="UTF-8"?>
<mediaItem xmlns="http://ns.opensocial.org/2008/opensocial">
<id>11223344</id>
- <thumbnailUrl>http://pages.example.org/images/11223344-tn.png</thumbnailUrl>
+ <thumbnailUrl>http://www.libpng.org/pub/png/img_png/pngnow.png</thumbnailUrl>
<mimeType>image/png</mimeType>
<type>image</type>
<url>http://www.google.com/intl/en_ALL/images/logo.gif</url>
@@ -118,7 +106,7 @@ class MediaItemRestTest extends RestBase
<content type="application/xml">
<mediaItem xmlns="http://ns.opensocial.org/2008/opensocial">
<id>11223344</id>
- <thumbnailUrl>http://pages.example.org/images/11223344-tn.png</thumbnailUrl>
+ <thumbnailUrl>http://www.libpng.org/pub/png/img_png/pngnow.png</thumbnailUrl>
<mimeType>image/png</mimeType>
<type>image</type>
<url>http://www.google.com/intl/en_ALL/images/logo.gif</url>
@@ -136,10 +124,10 @@ class MediaItemRestTest extends RestBase
public function testLifeCycleWithActivity() {
// Creates the media item.
$postData = '{ "id" : "11223344",
- "thumbnailUrl" : "http://pages.example.org/images/11223344-tn.png",
+ "thumbnailUrl" : "http://www.libpng.org/pub/png/img_png/pngnow.png",
"mimeType" : "image/png",
"type" : "image",
- "url" : "http://pages.example.org/images/11223344.png",
+ "url" : "http://www.libpng.org/pub/png/img_png/pngnow.png",
"albumId" : "' . $this->album['id'] . '"
}';
$url = '/mediaitems/1/@self/' . $this->album['id'];
Modified: shindig/trunk/php/test/social/OutputAtomConverterTest.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/test/social/OutputAtomConverterTest.php?rev=986132&r1=986131&r2=986132&view=diff
==============================================================================
--- shindig/trunk/php/test/social/OutputAtomConverterTest.php (original)
+++ shindig/trunk/php/test/social/OutputAtomConverterTest.php Mon Aug 16 21:26:20 2010
@@ -32,6 +32,8 @@ class OutputAtomConverterTest extends PH
* Prepares the environment before running a test.
*/
protected function setUp() {
+ $_SERVER['REQUEST_METHOD'] = 'GET';
+ $_SERVER["HTTP_HOST"] = 'localhost';
parent::setUp();
$this->OutputAtomConverter = new OutputAtomConverter();
}
Modified: shindig/trunk/php/test/social/OutputJsonConverterTest.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/test/social/OutputJsonConverterTest.php?rev=986132&r1=986131&r2=986132&view=diff
==============================================================================
--- shindig/trunk/php/test/social/OutputJsonConverterTest.php (original)
+++ shindig/trunk/php/test/social/OutputJsonConverterTest.php Mon Aug 16 21:26:20 2010
@@ -32,6 +32,7 @@ class OutputJsonConverterTest extends PH
* Prepares the environment before running a test.
*/
protected function setUp() {
+ $_SERVER['REQUEST_METHOD'] = 'GET';
parent::setUp();
$this->OutputJsonConverter = new OutputJsonConverter();
}
Modified: shindig/trunk/php/test/social/OutputXmlConverterTest.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/test/social/OutputXmlConverterTest.php?rev=986132&r1=986131&r2=986132&view=diff
==============================================================================
--- shindig/trunk/php/test/social/OutputXmlConverterTest.php (original)
+++ shindig/trunk/php/test/social/OutputXmlConverterTest.php Mon Aug 16 21:26:20 2010
@@ -32,6 +32,7 @@ class OutputXmlConverterTest extends PHP
* Prepares the environment before running a test.
*/
protected function setUp() {
+ $_SERVER['REQUEST_METHOD'] = 'GET';
parent::setUp();
$this->OutputXmlConverter = new OutputXmlConverter();
}
Modified: shindig/trunk/php/test/social/RestBase.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/test/social/RestBase.php?rev=986132&r1=986131&r2=986132&view=diff
==============================================================================
--- shindig/trunk/php/test/social/RestBase.php (original)
+++ shindig/trunk/php/test/social/RestBase.php Mon Aug 16 21:26:20 2010
@@ -24,32 +24,34 @@
*/
class RestBase extends PHPUnit_Framework_TestCase {
- /* Modify this if you want to test in a different social graph then partuza. The security token
- * only works if ALLOW_PLAINTEXT_TOKEN is set to true in the file shindig/php/config/containerphp
- * The format of the plain text token is owner:viewer:appId:domain:appUrl:moduleId:containerId
- */
- private $securityToken = '1:1:1:partuza:test.com:1:0';
+ private $securityToken;
// The server to test against. You may need to add shindig to 127.0.0.1 mapping in /etc/hosts.
private $restUrl = '';
public function __construct() {
- $this->restUrl = 'http://' . $_SERVER["HTTP_HOST"] . Config::get('web_prefix') . '/social/rest';
+ $db = new JsonDbOpensocialService();
+ $db->resetDb();
+ $this->securityToken = BasicSecurityToken::createFromValues(1, 1, 1, 'partuza', 'test.com', 1, 0)->toSerialForm();
+ $this->securityToken = urldecode($this->securityToken);
+ $this->restUrl = 'http://localhost' . Config::get('web_prefix') . '/social/rest';
}
- protected function curlRest($url, $postData, $contentType, $method = 'POST') {
- $ch = curl_init();
- if (substr($url, 0, 1) != '/') {
- $url = '/' . $url;
- }
+ protected function curlRest($url, $postData, $contentType = 'application/json', $method = 'POST') {
+ $_SERVER['CONTENT_TYPE'] = $contentType;
$sep = strpos($url, '?') !== false ? '&' : '?';
- curl_setopt($ch, CURLOPT_URL, $this->restUrl . $url . $sep . 'st=' . $this->securityToken);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: $contentType"));
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- $ret = curl_exec($ch);
- curl_close($ch);
+ $_SERVER["REQUEST_URI"] = $this->restUrl . $url . $sep . 'st=' . $this->securityToken;
+ $parsedUrl = parse_url($_SERVER["REQUEST_URI"]);
+ $GLOBALS['HTTP_RAW_POST_DATA'] = $postData ? $postData : null;
+ $_SERVER['REQUEST_METHOD'] = $method;
+ $_SERVER['QUERY_STRING'] = $parsedUrl['query'];
+ $_SERVER['HTTP_HOST'] = $parsedUrl['host'];
+ $_GET = array('st' => $this->securityToken);
+ $servlet = new DataServiceServlet();
+ $servletMethod = 'do' . ucfirst(strtolower($method));
+ ob_start();
+ $servlet->$servletMethod();
+ $ret = ob_get_clean();
+ //var_dump($ret);
return $ret;
}
Modified: shindig/trunk/php/test/social/RestRequestItemTest.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/test/social/RestRequestItemTest.php?rev=986132&r1=986131&r2=986132&view=diff
==============================================================================
--- shindig/trunk/php/test/social/RestRequestItemTest.php (original)
+++ shindig/trunk/php/test/social/RestRequestItemTest.php Mon Aug 16 21:26:20 2010
@@ -27,6 +27,7 @@ class RestRequestItemTest extends PHPUni
* Prepares the environment before running a test.
*/
protected function setUp() {
+ $_SERVER['REQUEST_METHOD'] = 'GET';
parent::setUp();
}