/**
  * <p>Creates an Expansion object from an array.</p>
  *
  * @param array $expansions <p>If the property does not have offset or
  * limit, the property name must be the value; if it does, the
  * key must be the property name and the value must be a nested
  * array with 'offset' and/or 'limit' as key(s) and
  * the number(s) as value(s).</p>
  * @return Expansion the created expansion object.
  */
 public static function format(array $expansions)
 {
     $expansion = new Expansion();
     foreach ($expansions as $key => $exp) {
         $expansion->addProperty(is_string($key) ? $key : $exp, is_array($exp) ? $exp : array($exp));
     }
     return $expansion;
 }
 public function testGroupsCollectionOptions()
 {
     $account = self::$account;
     $groups = $account->getGroups();
     $groups->offset = 1;
     $groups->limit = 2;
     $groups->order = \Stormpath\Resource\Order::format(array('name'), 'desc');
     $search = new \Stormpath\Resource\Search();
     $groups->search = $search->setFilter(9);
     $groups->expansion = \Stormpath\Resource\Expansion::format(array('directory'));
     $this->assertGroupOptions($groups);
     $groups->search = 'q=9';
     $groups->order = 'name desc';
     $groups->expansion = array('directory');
     $this->assertGroupOptions($groups);
     $groups->search = array('q' => 9);
     $groups->expansion = 'directory';
     $this->assertGroupOptions($groups);
     $order = new \Stormpath\Resource\Order(array('name'), 'd');
     $groups->order = strval($order);
     $search = new \Stormpath\Resource\Search();
     $groups->search = $search->addStartsWith('description', 'group description')->addEndsWith('name', 'name')->addEquals('status', 'enabled');
     $this->assertGroupOptions($groups);
     $groups->search = $search->addMatchAnywhere('name', 9);
     $this->assertGroupOptions($groups);
 }
 /**
  * Sets the expansion criteria for this collection resource.
  * @param Expansion object|array|string $expansion<p>
  * If it's an array, and the property does not have offset or
  * limit, the property name and the value must be a nested
  * array with 'offset' and/or 'limit' as key(s) and
  * the number(s) as value(s).</p>
  * <p>If it's a string, it must not contain the 'expand' keyword.</p>
  * @return $this for method chaining.
  */
 public function setExpansion($expansion)
 {
     if ($expansion instanceof Expansion) {
         $this->options = array_replace($this->options, $expansion->toExpansionArray());
     } elseif (is_array($expansion)) {
         $this->options = array_replace($this->options, Expansion::format($expansion)->toExpansionArray());
     } elseif (is_string($expansion)) {
         $this->options = array_replace($this->options, array(Stormpath::EXPAND => $expansion));
     }
     return $this;
 }