Added: incubator/shindig/trunk/php/test/gadgets/UserPrefsTest.php URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/gadgets/UserPrefsTest.php?rev=681982&view=auto ============================================================================== --- incubator/shindig/trunk/php/test/gadgets/UserPrefsTest.php (added) +++ incubator/shindig/trunk/php/test/gadgets/UserPrefsTest.php Sat Aug 2 07:11:35 2008 @@ -0,0 +1,80 @@ +<?php + +require_once 'src/gadgets/UserPrefs.php'; + +require_once 'PHPUnit/Framework/TestCase.php'; + +/** + * UserPrefs test case. + */ +class UserPrefsTest extends PHPUnit_Framework_TestCase { + + /** + * @var UserPrefs + */ + private $UserPrefs; + + /** + * @var UserPrefsArrays + */ + private $UserPrefsArrays = array('Test1' => 'value for test1', 'Test2' => 'value for test2'); + + /** + * Prepares the environment before running a test. + */ + protected function setUp() + { + parent::setUp(); + $this->UserPrefs = new UserPrefs($this->UserPrefsArrays); + + } + + /** + * Cleans up the environment after running a test. + */ + protected function tearDown() + { + $this->UserPrefs = null; + + parent::tearDown(); + } + + /** + * Tests UserPrefs->getPref() + */ + public function testGetPref() + { + $this->assertEquals($this->UserPrefsArrays['Test1'], $this->UserPrefs->getPref('Test1')); + + } + + /** + * Tests UserPrefs->getPrefs() + */ + public function testGetPrefs() + { + $this->assertEquals($this->UserPrefsArrays, $this->UserPrefs->getPrefs()); + + } + + /** + * Tests UserPrefs->getPrefs() + */ + public function testGetPrefsReturn() + { + $key = 'Test1'; + $this->assertEquals($this->UserPrefsArrays[$key], $this->UserPrefs->getPref($key)); + + } + + /** + * Tests UserPrefs->getPrefs() + */ + public function testGetPrefsReturnNull() + { + $key = 'non_existing_key'; + $this->assertNull($this->UserPrefs->getPref($key)); + + } +} +
Added: incubator/shindig/trunk/php/test/gadgets/ViewSpecTest.php URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/gadgets/ViewSpecTest.php?rev=681982&view=auto ============================================================================== --- incubator/shindig/trunk/php/test/gadgets/ViewSpecTest.php (added) +++ incubator/shindig/trunk/php/test/gadgets/ViewSpecTest.php Sat Aug 2 07:11:35 2008 @@ -0,0 +1,65 @@ +<?php + +require_once 'src/gadgets/ViewSpec.php'; +require_once 'PHPUnit/Framework/TestCase.php'; + +require_once 'src/gadgets/GadgetSpecParser.php'; + +/** + * ViewSpec test case. + */ +class ViewSpecTest extends PHPUnit_Framework_TestCase { + + /** + * @var ViewSpec + */ + private $ViewSpec; + + /** + * @var GadgetXML + */ + private $GadgetXML = '<?xml version="1.0" encoding="UTF-8" ?> +<Module> + <ModulePrefs title="Dummie gadget" /> + <Require feature="rpc"> + </Require> + <Content type="html"> + <![CDATA[<h1>Hello, world!</h1>]]> + </Content> +</Module> + '; + + /** + * Prepares the environment before running a test. + */ + protected function setUp() + { + parent::setUp(); + } + + /** + * Cleans up the environment after running a test. + */ + protected function tearDown() + { + parent::tearDown(); + } + + /** + * Tests ViewSpec->__construct() + */ + public function test__construct() + { + $doc = simplexml_load_string($this->GadgetXML, 'SimpleXMLElement', LIBXML_NOCDATA); + $content = $doc->Content[0]; + $attributes = $content->attributes(); + $view = isset($attributes['view']) ? trim($attributes['view']) : DEFAULT_VIEW; + $attributes['type'] = 'url'; + + $this->setExpectedException('SpecParserException'); + $this->ViewSpec = new ViewSpec($view, $content); + + } + +} + Added: incubator/shindig/trunk/php/test/gadgets/dummie_script.js URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/gadgets/dummie_script.js?rev=681982&view=auto ============================================================================== --- incubator/shindig/trunk/php/test/gadgets/dummie_script.js (added) +++ incubator/shindig/trunk/php/test/gadgets/dummie_script.js Sat Aug 2 07:11:35 2008 @@ -0,0 +1,7 @@ +<?xml version="1.0"?> +<feature> + <name>Dummie</name> + <gadget> + <script src="dummie_script.js"/> + </gadget> +</feature> Added: incubator/shindig/trunk/php/test/gadgets/example.xml URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/gadgets/example.xml?rev=681982&view=auto ============================================================================== --- incubator/shindig/trunk/php/test/gadgets/example.xml (added) +++ incubator/shindig/trunk/php/test/gadgets/example.xml Sat Aug 2 07:11:35 2008 @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<Module> + <ModulePrefs title="Sample Gadget" /> + <Content type="html"> + <![CDATA[ + <style type="text/css"> + h1{background-color:#efefef; border:1px solid #444; padding:10px; text-align:center} + </style> + <h1>Hello, world!</h1> + ]]> + </Content> +</Module> \ No newline at end of file Added: incubator/shindig/trunk/php/test/index.php URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/index.php?rev=681982&view=auto ============================================================================== --- incubator/shindig/trunk/php/test/index.php (added) +++ incubator/shindig/trunk/php/test/index.php Sat Aug 2 07:11:35 2008 @@ -0,0 +1,61 @@ +<?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. + * + */ +set_include_path(realpath("../") . PATH_SEPARATOR . realpath("../external/")); +ini_set('error_reporting', E_COMPILE_ERROR | E_ERROR | E_CORE_ERROR); + +require_once "PHPUnit/Framework/TestSuite.php"; +require_once "PHPUnit/TextUI/TestRunner.php"; + +class AllTests { + + public static function main() + { + PHPUnit_TextUI_TestRunner::run(self::suite(), array()); + } + + public static function suite() + { + $suite = new PHPUnit_Framework_TestSuite(); + $suite->setName('Shindig'); + $path = dirname($_SERVER['SCRIPT_FILENAME']); + $testTypes = array('common', 'gadgets', 'social-api'); + foreach ($testTypes as $type) { + foreach (glob("$path/{$type}/*Test.php") as $file) { + if (is_readable($file)) { + require_once $file; + $className = str_replace('.php', '', basename($file)); + $suite->addTestSuite($className); + } + } + } + return $suite; + } +} + +echo "<html><body><pre>"; +AllTests::main(); +echo "</pre></body></html>"; + +// make sure the result page isn't cached, some of the tests set caching headers which is bad here +header("Expires: Mon, 26 Jul 1997 05:00:00 GMT", true); +header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT', true); +header('Cache-Control: no-store, no-cache, must-revalidate', true); +header('Cache-Control: pre-check=0, post-check=0, max-age=0', true); +header("Pragma: no-cache", true);
