Author: chabotc
Date: Tue Aug 5 04:29:07 2008
New Revision: 682677
URL: http://svn.apache.org/viewvc?rev=682677&view=rev
Log:
Add tests for auth, featureSpec, specFactory and blacklist; Plus fixes a few
small typos they found
Added:
incubator/shindig/trunk/php/src/gadgets/samplecontainer/BasicGadgetSpecFactory.php
- copied unchanged from r682527,
incubator/shindig/trunk/php/src/gadgets/BasicGadgetSpecFactory.php
incubator/shindig/trunk/php/test/gadgets/AuthTest.php
incubator/shindig/trunk/php/test/gadgets/BasicGadgetBlacklistTest.php
incubator/shindig/trunk/php/test/gadgets/ContainerConfigTest.php
incubator/shindig/trunk/php/test/gadgets/FeatureSpecTest.php
incubator/shindig/trunk/php/test/gadgets/GadgetFeatureRegistryTest.php
Removed:
incubator/shindig/trunk/php/src/gadgets/BasicGadgetSpecFactory.php
Modified:
incubator/shindig/trunk/php/src/gadgets/Auth.php
incubator/shindig/trunk/php/src/gadgets/ContainerConfig.php
incubator/shindig/trunk/php/src/gadgets/rewrite/ContentRewriteFeature.php
incubator/shindig/trunk/php/src/gadgets/samplecontainer/BasicGadgetBlacklist.php
incubator/shindig/trunk/php/test/TestContext.php
Modified: incubator/shindig/trunk/php/src/gadgets/Auth.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/Auth.php?rev=682677&r1=682676&r2=682677&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/Auth.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/Auth.php Tue Aug 5 04:29:07 2008
@@ -34,10 +34,10 @@
$value = trim($value);
if (strlen($value) == 0)
return Auth::$NONE;
- if (strtoupper($value == Auth::$SIGNED)) {
+ if (strtoupper($value) == Auth::$SIGNED) {
return Auth::$SIGNED;
} else
- if (strtoupper($value == Auth::$AUTHENTICATED))
{
+ if (strtoupper($value) == Auth::$AUTHENTICATED)
{
return Auth::$AUTHENTICATED;
} else {
return Auth::$NONE;
Modified: incubator/shindig/trunk/php/src/gadgets/ContainerConfig.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/ContainerConfig.php?rev=682677&r1=682676&r2=682677&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/ContainerConfig.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/ContainerConfig.php Tue Aug 5
04:29:07 2008
@@ -77,7 +77,6 @@
if ($container != $this->default_container &&
isset($this->config[$container][$name])) {
$config =
$this->mergeConfig($this->config[$container][$name], $config);
}
-
return $config;
}
Modified:
incubator/shindig/trunk/php/src/gadgets/rewrite/ContentRewriteFeature.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/rewrite/ContentRewriteFeature.php?rev=682677&r1=682676&r2=682677&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/rewrite/ContentRewriteFeature.php
(original)
+++ incubator/shindig/trunk/php/src/gadgets/rewrite/ContentRewriteFeature.php
Tue Aug 5 04:29:07 2008
@@ -33,6 +33,9 @@
public function createRewriteFeature(Gadget $gadget)
{
$requires = $gadget->getRequires();
+ if (!isset($requires[ContentRewriteFeature::$REWRITE_TAG])) {
+ return;
+ }
$rewriteFeature =
$requires[ContentRewriteFeature::$REWRITE_TAG];
$rewriteParams = $rewriteFeature->getParams();
if
(isset($rewriteParams[ContentRewriteFeature::$INCLUDE_URLS])) {
Modified:
incubator/shindig/trunk/php/src/gadgets/samplecontainer/BasicGadgetBlacklist.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/samplecontainer/BasicGadgetBlacklist.php?rev=682677&r1=682676&r2=682677&view=diff
==============================================================================
---
incubator/shindig/trunk/php/src/gadgets/samplecontainer/BasicGadgetBlacklist.php
(original)
+++
incubator/shindig/trunk/php/src/gadgets/samplecontainer/BasicGadgetBlacklist.php
Tue Aug 5 04:29:07 2008
@@ -18,18 +18,31 @@
*
*/
+/**
+ * Basic example blacklist class. This class takes a text file with regex
+ * rules against which URL's are tested.
+ * The default file location is {$base_path}/blacklist.txt
+ *
+ */
class BasicGadgetBlacklist {
private $rules = array();
- public function __construct()
+ public function __construct($file = false)
{
- $file = Config::get('base_path') . '/blacklist.txt';
- //TODO make this a configurable location
+ if (!$file) {
+ $file = Config::get('base_path') . '/blacklist.txt';
+ }
if (file_exists($file) && is_readable($file)) {
$this->rules = explode("\n", file_get_contents($file));
}
}
+ /**
+ * Check the URL against the blacklist rules
+ *
+ * @param string $url
+ * @return boolean is blacklisted or not?
+ */
function isBlacklisted($url)
{
foreach ($this->rules as $rule) {
Modified: incubator/shindig/trunk/php/test/TestContext.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/TestContext.php?rev=682677&r1=682676&r2=682677&view=diff
==============================================================================
--- incubator/shindig/trunk/php/test/TestContext.php (original)
+++ incubator/shindig/trunk/php/test/TestContext.php Tue Aug 5 04:29:07 2008
@@ -29,7 +29,7 @@
$this->setUrl('http://www.example.org/foo.xml');
$this->setModuleId(1);
$this->setView('profile');
- $this->setContainer('test');
+ $this->setContainer('');
$this->setRefreshInterval(1);
}
}
Added: incubator/shindig/trunk/php/test/gadgets/AuthTest.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/gadgets/AuthTest.php?rev=682677&view=auto
==============================================================================
--- incubator/shindig/trunk/php/test/gadgets/AuthTest.php (added)
+++ incubator/shindig/trunk/php/test/gadgets/AuthTest.php Tue Aug 5 04:29:07
2008
@@ -0,0 +1,59 @@
+<?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.
+ *
+ */
+
+/**
+ * Auth test case.
+ */
+class AuthTest extends PHPUnit_Framework_TestCase {
+
+ /**
+ * @var Auth
+ */
+ private $Auth;
+
+ /**
+ * Prepares the environment before running a test.
+ */
+ protected function setUp()
+ {
+ parent::setUp();
+ $this->Auth = new Auth();
+ }
+
+ /**
+ * Cleans up the environment after running a test.
+ */
+ protected function tearDown()
+ {
+ $this->Auth = null;
+ parent::tearDown();
+ }
+
+ /**
+ * Tests Auth::parse()
+ */
+ public function testParse()
+ {
+ $this->assertEquals(Auth::$AUTHENTICATED,
Auth::parse('authenticated'));
+ $this->assertEquals(Auth::$SIGNED, Auth::parse('signed'));
+ $this->assertEquals(Auth::$NONE, Auth::parse('none'));
+ $this->assertEquals(Auth::$NONE, Auth::parse('foo'));
+ }
+}
Added: incubator/shindig/trunk/php/test/gadgets/BasicGadgetBlacklistTest.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/gadgets/BasicGadgetBlacklistTest.php?rev=682677&view=auto
==============================================================================
--- incubator/shindig/trunk/php/test/gadgets/BasicGadgetBlacklistTest.php
(added)
+++ incubator/shindig/trunk/php/test/gadgets/BasicGadgetBlacklistTest.php Tue
Aug 5 04:29:07 2008
@@ -0,0 +1,63 @@
+<?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.
+ *
+ */
+
+/**
+ * BasicGadgetBlacklist test case.
+ */
+class BasicGadgetBlacklistTest extends PHPUnit_Framework_TestCase {
+
+ /**
+ * @var BasicGadgetBlacklist
+ */
+ private $BasicGadgetBlacklist;
+
+ private $tmpFile;
+
+ /**
+ * Prepares the environment before running a test.
+ */
+ protected function setUp()
+ {
+ parent::setUp();
+ // sys_get_temp_dir() requires php >= 5.2.1
+ $this->tmpFile = tempnam(sys_get_temp_dir(), 'test-blacklist-');
+ file_put_contents($this->tmpFile, "/www/i\n");
+ $this->BasicGadgetBlacklist = new
BasicGadgetBlacklist($this->tmpFile);
+ }
+
+ /**
+ * Cleans up the environment after running a test.
+ */
+ protected function tearDown()
+ {
+ @unlink($this->tmpFile);
+ $this->BasicGadgetBlacklist = null;
+ parent::tearDown();
+ }
+
+ /**
+ * Tests BasicGadgetBlacklist->isBlacklisted()
+ */
+ public function testIsBlacklisted()
+ {
+
$this->assertTrue($this->BasicGadgetBlacklist->isBlacklisted('http://www.foo.com/bar.xml'));
+ }
+}
Added: incubator/shindig/trunk/php/test/gadgets/ContainerConfigTest.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/gadgets/ContainerConfigTest.php?rev=682677&view=auto
==============================================================================
--- incubator/shindig/trunk/php/test/gadgets/ContainerConfigTest.php (added)
+++ incubator/shindig/trunk/php/test/gadgets/ContainerConfigTest.php Tue Aug 5
04:29:07 2008
@@ -0,0 +1,62 @@
+<?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.
+ */
+
+/**
+ * ContainerConfig test case.
+ */
+class ContainerConfigTest extends PHPUnit_Framework_TestCase {
+
+ /**
+ * @var ContainerConfig
+ */
+ private $ContainerConfig;
+
+ /**
+ * Prepares the environment before running a test.
+ */
+ protected function setUp()
+ {
+ parent::setUp();
+ $this->ContainerConfig = new
ContainerConfig(Config::get('container_path'));
+ }
+
+ /**
+ * Cleans up the environment after running a test.
+ */
+ protected function tearDown()
+ {
+ $this->ContainerConfig = null;
+ parent::tearDown();
+ }
+
+ /**
+ * Tests ContainerConfig->getConfig()
+ */
+ public function testGetConfig()
+ {
+ $config = $this->ContainerConfig->getConfig('default',
'gadgets.features');
+ $this->assertArrayHasKey('core.io', $config);
+ $this->assertArrayHasKey('views', $config);
+ $this->assertArrayHasKey('rpc', $config);
+ $this->assertArrayHasKey('skins', $config);
+ $this->assertArrayHasKey('opensocial-0.8', $config);
+ $this->assertArrayHasKey('path', $config['opensocial-0.8']);
+ }
+}
Added: incubator/shindig/trunk/php/test/gadgets/FeatureSpecTest.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/gadgets/FeatureSpecTest.php?rev=682677&view=auto
==============================================================================
--- incubator/shindig/trunk/php/test/gadgets/FeatureSpecTest.php (added)
+++ incubator/shindig/trunk/php/test/gadgets/FeatureSpecTest.php Tue Aug 5
04:29:07 2008
@@ -0,0 +1,75 @@
+<?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.
+ *
+ */
+
+/**
+ * FeatureSpec test case.
+ */
+class FeatureSpecTest extends PHPUnit_Framework_TestCase {
+
+ /**
+ * @var FeatureSpec
+ */
+ private $FeatureSpec;
+
+ /**
+ * Prepares the environment before running a test.
+ */
+ protected function setUp()
+ {
+ parent::setUp();
+ $this->FeatureSpec = new FeatureSpec();
+ $this->FeatureSpec->name = 'name';
+ $this->FeatureSpec->optional = 'optional';
+ $this->FeatureSpec->params = 'params';
+ }
+
+ /**
+ * Cleans up the environment after running a test.
+ */
+ protected function tearDown()
+ {
+ $this->FeatureSpec = null;
+ parent::tearDown();
+ }
+
+ /**
+ * Tests FeatureSpec->getName()
+ */
+ public function testGetName()
+ {
+ $this->assertEquals('name', $this->FeatureSpec->getName());
+ }
+
+ /**
+ * Tests FeatureSpec->getParams()
+ */
+ public function testGetParams()
+ {
+ $this->assertEquals('params', $this->FeatureSpec->getParams());
+ }
+
+ /**
+ * Tests FeatureSpec->isOptional()
+ */
+ public function testIsOptional()
+ {
+ $this->assertEquals('optional',
$this->FeatureSpec->isOptional());
+ }
+}
Added: incubator/shindig/trunk/php/test/gadgets/GadgetFeatureRegistryTest.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/gadgets/GadgetFeatureRegistryTest.php?rev=682677&view=auto
==============================================================================
--- incubator/shindig/trunk/php/test/gadgets/GadgetFeatureRegistryTest.php
(added)
+++ incubator/shindig/trunk/php/test/gadgets/GadgetFeatureRegistryTest.php Tue
Aug 5 04:29:07 2008
@@ -0,0 +1,95 @@
+<?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.
+ *
+ */
+
+/**
+ * GadgetFeatureRegistry test case.
+ */
+class GadgetFeatureRegistryTest extends PHPUnit_Framework_TestCase {
+
+ /**
+ * @var GadgetFeatureRegistry
+ */
+ private $GadgetFeatureRegistry;
+
+ /**
+ * Prepares the environment before running a test.
+ */
+ protected function setUp()
+ {
+ parent::setUp();
+ $this->GadgetFeatureRegistry = new
GadgetFeatureRegistry(Config::get('features_path'));
+ }
+
+ /**
+ * Cleans up the environment after running a test.
+ */
+ protected function tearDown()
+ {
+ $this->GadgetFeatureRegistry = null;
+ parent::tearDown();
+ }
+
+ /**
+ * Tests GadgetFeatureRegistry->__construct()
+ */
+ public function test__construct()
+ {
+
$this->GadgetFeatureRegistry->__construct(Config::get('features_path'));
+ }
+
+ /**
+ * Tests GadgetFeatureRegistry->getAllFeatures()
+ */
+ public function testGetAllFeatures()
+ {
+ $this->assertGreaterThan(0,
count($this->GadgetFeatureRegistry->getAllFeatures()));
+ }
+
+ /**
+ * Tests GadgetFeatureRegistry->getEntry()
+ */
+ public function testGetEntry()
+ {
+ $entry = $this->GadgetFeatureRegistry->getEntry('core');
+ $this->assertTrue($entry instanceof
GadgetFeatureRegistryEntry);
+ $this->assertEquals('core', $entry->getName());
+ $this->assertTrue(is_array($entry->getDependencies()));
+ $this->assertTrue($entry->getFeature() instanceof
JsLibraryFeatureFactory);
+ }
+
+ /**
+ * Tests GadgetFeatureRegistry->getIncludedFeatures()
+ */
+ public function testGetIncludedFeatures()
+ {
+ $needed = array('flash', 'opensocial-0.8', 'settitle',
'setprefs', 'foobar');
+ $resultsFound = array();
+ $resultsMissing = array();
+ $this->GadgetFeatureRegistry->getIncludedFeatures($needed,
$resultsFound, $resultsMissing);
+ $this->assertTrue(in_array('foobar', $resultsMissing));
+ $this->assertTrue(in_array('settitle', $resultsFound));
+ $this->assertTrue(in_array('setprefs', $resultsFound));
+ $this->assertTrue(in_array('rpc', $resultsFound));
+ $this->assertTrue(in_array('flash', $resultsFound));
+ $this->assertTrue(in_array('core', $resultsFound));
+ $this->assertTrue(in_array('core.io', $resultsFound));
+ $this->assertTrue(in_array('opensocial-0.8', $resultsFound));
+ }
+}