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 2011/03/31 12:37:39 UTC

svn commit: r1087241 - in /shindig/trunk/php: src/gadgets/GadgetContext.php src/gadgets/GadgetFactory.php test/gadgets/GadgetContextTest.php test/gadgets/GadgetFactoryTest.php

Author: bhofmann
Date: Thu Mar 31 10:37:39 2011
New Revision: 1087241

URL: http://svn.apache.org/viewvc?rev=1087241&view=rev
Log:
PHP: added support for the rawxml parameter in the GadgetRenderingServlet

Added:
    shindig/trunk/php/test/gadgets/GadgetFactoryTest.php
Modified:
    shindig/trunk/php/src/gadgets/GadgetContext.php
    shindig/trunk/php/src/gadgets/GadgetFactory.php
    shindig/trunk/php/test/gadgets/GadgetContextTest.php

Modified: shindig/trunk/php/src/gadgets/GadgetContext.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/src/gadgets/GadgetContext.php?rev=1087241&r1=1087240&r2=1087241&view=diff
==============================================================================
--- shindig/trunk/php/src/gadgets/GadgetContext.php (original)
+++ shindig/trunk/php/src/gadgets/GadgetContext.php Thu Mar 31 10:37:39 2011
@@ -90,6 +90,13 @@ class GadgetContext {
    * @var string
    */
   protected $container = null;
+
+  /**
+   *
+   * @var string
+   */
+  protected $rawXml = null;
+
   /**
    *
    * @var int
@@ -108,6 +115,7 @@ class GadgetContext {
     $this->setIgnoreCache($this->getIgnoreCacheParam());
     $this->setForcedJsLibs($this->getForcedJsLibsParam());
     $this->setUrl($this->getUrlParam());
+    $this->setRawXml($this->getRawXmlParam());
     $this->setModuleId($this->getModuleIdParam());
     $this->setView($this->getViewParam());
     $this->setContainer($this->getContainerParam());
@@ -174,6 +182,19 @@ class GadgetContext {
 
   /**
    *
+   * @return string
+   */
+  protected function getRawXmlParam() {
+    if (! empty($_GET['rawxml'])) {
+      return $_GET['rawxml'];
+    } elseif (! empty($_POST['rawxml'])) {
+      return $_POST['rawxml'];
+    }
+    return null;
+  }
+
+  /**
+   *
    * @return int
    */
   protected function getModuleIdParam() {
@@ -295,6 +316,14 @@ class GadgetContext {
    *
    * @return string
    */
+  public function getRawXml() {
+    return $this->rawXml;
+  }
+
+  /**
+   *
+   * @return string
+   */
   public function getView() {
     return $this->view;
   }
@@ -388,6 +417,13 @@ class GadgetContext {
   }
 
   /**
+   * @param string $rawXml
+   */
+  public function setRawXml($rawXml) {
+    $this->rawXml = $rawXml;
+  }
+
+  /**
    *
    * @param string $view
    */

Modified: shindig/trunk/php/src/gadgets/GadgetFactory.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/src/gadgets/GadgetFactory.php?rev=1087241&r1=1087240&r2=1087241&view=diff
==============================================================================
--- shindig/trunk/php/src/gadgets/GadgetFactory.php (original)
+++ shindig/trunk/php/src/gadgets/GadgetFactory.php Thu Mar 31 10:37:39 2011
@@ -41,12 +41,14 @@ class GadgetFactory {
    * @return Gadget
    */
   public function createGadget() {
-    $gadgetUrl = $this->context->getUrl();
-    if ($this->context->getBlacklist() != null && $this->context->getBlacklist()->isBlacklisted($gadgetUrl)) {
-      throw new GadgetException("The Gadget ($gadgetUrl) is blacklisted and can not be rendered");
+    if (! $gadgetContent = $this->context->getRawXml()) {
+      $gadgetUrl = $this->context->getUrl();
+      if ($this->context->getBlacklist() != null && $this->context->getBlacklist()->isBlacklisted($gadgetUrl)) {
+        throw new GadgetException("The Gadget ($gadgetUrl) is blacklisted and can not be rendered");
+      }
+      // Fetch the gadget's content and create a GadgetSpec
+      $gadgetContent = $this->fetchGadget($gadgetUrl);
     }
-    // Fetch the gadget's content and create a GadgetSpec
-    $gadgetContent = $this->fetchGadget($gadgetUrl);
     $gadgetSpecParserClass = Config::get('gadget_spec_parser');
     $gadgetSpecParser = new $gadgetSpecParserClass();
     $gadgetSpec = $gadgetSpecParser->parse($gadgetContent, $this->context);

Modified: shindig/trunk/php/test/gadgets/GadgetContextTest.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/test/gadgets/GadgetContextTest.php?rev=1087241&r1=1087240&r2=1087241&view=diff
==============================================================================
--- shindig/trunk/php/test/gadgets/GadgetContextTest.php (original)
+++ shindig/trunk/php/test/gadgets/GadgetContextTest.php Thu Mar 31 10:37:39 2011
@@ -32,7 +32,7 @@ class GadgetContextTest extends PHPUnit_
    * @var testData
    */
   private $testData = array('url' => 'http://www.google.com/gadget', 'libs' => '', 'synd' => 'default', 
-      'nocache' => '', 'container' => 'default', 'view' => 'default', 'mid' => '123', 
+      'nocache' => '', 'rawxml' => '<foo></foo>', 'container' => 'default', 'view' => 'default', 'mid' => '123',
       'bcp' => '');
   
   /**
@@ -144,6 +144,10 @@ class GadgetContextTest extends PHPUnit_
   
   }
 
+  public function testGetRawXml() {
+    $this->assertEquals($this->testData['rawxml'], $this->GadgetContext->getRawXml());
+  }
+
   /**
    * Tests GadgetContext->getView()
    */
@@ -169,7 +173,12 @@ class GadgetContextTest extends PHPUnit_
     $url = 'Dummie_url';
     $this->GadgetContext->setUrl($url);
     $this->assertEquals($url, $this->GadgetContext->getUrl());
-  
+  }
+
+  public function testSetRawXml() {
+    $xml = 'Dummie_xml';
+    $this->GadgetContext->setRawXml($xml);
+    $this->assertEquals($xml, $this->GadgetContext->getRawXml());
   }
 
   /**

Added: shindig/trunk/php/test/gadgets/GadgetFactoryTest.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/test/gadgets/GadgetFactoryTest.php?rev=1087241&view=auto
==============================================================================
--- shindig/trunk/php/test/gadgets/GadgetFactoryTest.php (added)
+++ shindig/trunk/php/test/gadgets/GadgetFactoryTest.php Thu Mar 31 10:37:39 2011
@@ -0,0 +1,91 @@
+<?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 GadgetFactoryTest extends PHPUnit_Framework_TestCase {
+    private $oldGet;
+    private $oldPost;
+    private $token;
+    public function setUp()
+    {
+        $this->oldGet = $_GET;
+        $this->oldPost = $_POST;
+        $this->token = BasicSecurityToken::createFromValues(1, 1, 1, 'example.com', 'http://example.com/gadget', 1, 1);
+    }
+
+    public function tearDown()
+    {
+        $_GET = $this->oldGet;
+        $_POST = $this->oldPost;
+    }
+    
+    public function testCreateGadgetFromRawXml()
+    {
+        $_GET = array(
+            'rawxml' => '<?xml version="1.0" encoding="UTF-8" ?>
+<Module>
+  <ModulePrefs title="title">
+    <Require feature="opensocial-0.8" />
+    <Require feature="dynamic-height" />
+    <Require feature="flash" />
+    <Require feature="minimessage" />
+  </ModulePrefs>
+  <Content type="html" view="home">
+  <![CDATA[
+    <h1>Hello, world!</h1>
+  ]]>
+  </Content>
+</Module>'
+        );
+        $_POST = array();
+        $context = new GadgetContext('GADGET');
+        $gadgetFactory = new GadgetFactory($context, $this->token);
+        $gadget = $gadgetFactory->createGadget();
+
+        $this->assertEquals('title', $gadget->gadgetSpec->title);
+        $this->assertEquals('<h1>Hello, world!</h1>', trim($gadget->gadgetSpec->views['home']['content']));
+    }
+
+    public function testCreateGadgetFromRawXmlInPost()
+    {
+        $_POST = array(
+            'rawxml' => '<?xml version="1.0" encoding="UTF-8" ?>
+<Module>
+  <ModulePrefs title="title">
+    <Require feature="opensocial-0.8" />
+    <Require feature="dynamic-height" />
+    <Require feature="flash" />
+    <Require feature="minimessage" />
+  </ModulePrefs>
+  <Content type="html" view="home">
+  <![CDATA[
+    <h1>Hello, world!</h1>
+  ]]>
+  </Content>
+</Module>'
+        );
+        $_GET = array();
+        $context = new GadgetContext('GADGET');
+        $gadgetFactory = new GadgetFactory($context, $this->token);
+        $gadget = $gadgetFactory->createGadget();
+
+        $this->assertEquals('title', $gadget->gadgetSpec->title);
+        $this->assertEquals('<h1>Hello, world!</h1>', trim($gadget->gadgetSpec->views['home']['content']));
+    }
+}
\ No newline at end of file