/**
  * @dataProvider provideContextParameters
  */
 public function testParameterReader($params, $name, $contexts, $results)
 {
     $reader = new ContextParameterReader($params, $name);
     $context_results = array();
     foreach ($contexts as $context) {
         $context_results[$context] = $reader->getContext($context);
     }
     $resultKeys = array_keys($results);
     $contextKeys = $contexts;
     array_push($contextKeys, $name);
     sort($resultKeys);
     sort($contextKeys);
     $this->assertEquals($resultKeys, $contextKeys);
     foreach ($contexts as $context) {
         $this->assertEquals($results[$context], $context_results[$context], "Unexpected difference in context {$context}: %s");
     }
     $this->assertEquals($results[$name], $reader->getContext($name));
 }
Example #2
0
 /**
  * Reads configurations of multiple networks from $_POST or $_GET ($_POST preferred). These
  * parameters are used to configure channels for each network. The resulting array contains
  * the keys 'host' and 'deployed' for the host and deployed networks, respectively. It also may
  * contain additional network configurations by ID. 
  * <br />
  * The main context (fb_sig) will have the following parameters:<br />
  * <ul>
  *   <li>in_canvas</li>
  *   <li>request_method</li>
  *   <li>locale</li>
  *   <li>position_fix</li>
  *   <li>time</li>
  *   <li>added</li>
  *   <li>profile_update_time</li>
  *   <li>friends</li>
  *   <li>is_ajax</li>
  *   <li>flavor</li>
  *   <li>host</li>
  *   <li>deployed</li>
  *   <li>networks</li>
  * </ul>
  * 
  * Every context (including the main context) will have the following parameters:<br />
  * <ul>
  *   <li>user</li>
  *   <li>session_key</li>
  *   <li>expires</li>
  *   <li>secret (optional)</li>
  *   <li>api_key</li>
  *   <li>rest_url</li>
  *   <li>login_url</li>
  *   <li>canvas_url</li>
  * </ul>
  * 
  * @return array having the keys 'host', 'deployed', and one for each network key
  * 				  configured for this application.
  */
 protected function readNetworkParameters(ContextParameterReader $reader, array $source)
 {
     $allNetworkParameters = array();
     $mainContextName = $reader->getMainContextName();
     $networks = array();
     error_log("Processing source: " . var_export($source, true));
     if (isset($source[$mainContextName . '_networks'])) {
         $networks = explode(',', $source[$mainContextName . '_networks']);
         error_log("Reading network parameters for " . sizeof($networks) . " networks");
         foreach ($networks as $network) {
             $networkParameters = $reader->getContext($mainContextName . '_' . $network);
             $allNetworkParameters[$network] = $networkParameters;
         }
     }
     // Now read the main context, putting those parameters into the host network context
     $remainderContext = $reader->getContext();
     if (isset($remainderContext['host'])) {
         $hostNetwork = $remainderContext['host'];
         // Make sure host network ID is actually configured
         if (isset($allNetworkParameters[$hostNetwork])) {
             // Merge the main context into the host network, but prefer explicit parameters over "default" values
             $allNetworkParameters[$hostNetwork] = array_merge($remainderContext, $allNetworkParameters[$hostNetwork]);
         } else {
             $allNetworkParameters[$hostNetwork] = $remainderContext;
         }
     }
     return $allNetworkParameters;
 }