/**
  * @test
  */
 public function descendAllKeepsArrayIndexes()
 {
     $array = array(array('name' => 'Foo', 'secret' => TRUE), array('name' => 'Bar', 'secret' => TRUE));
     $this->view->assign('value', $array);
     $this->view->setConfiguration(array('value' => array('_descendAll' => array('_descendAll' => array()))));
     $expectedResult = '[{"name":"Foo","secret":true},{"name":"Bar","secret":true}]';
     $actualResult = $this->view->render();
     $this->assertEquals($expectedResult, $actualResult);
 }
 /**
  * @test
  */
 public function renderTransformsJsonSerializableValues()
 {
     $value = $this->getMock('JsonSerializable', array('jsonSerialize'));
     $value->expects($this->any())->method('jsonSerialize')->will($this->returnValue(array('name' => 'Foo', 'age' => 42)));
     $this->view->assign('value', $value);
     $this->view->setConfiguration(array('value' => array('_only' => array('name'))));
     $expectedResult = '{"name":"Foo"}';
     $actualResult = $this->view->render();
     $this->assertEquals($expectedResult, $actualResult);
 }
 /**
  * Configures rendering according to the set variable(s) and calls
  * render on the parent.
  *
  * @return string
  */
 public function render()
 {
     if (isset($this->variables['assets'])) {
         $this->setConfiguration(array('assets' => array('_descendAll' => array('_only' => array('label', 'tags', 'identifier')))));
         $this->setVariablesToRender(array('assets'));
     } else {
         $this->setConfiguration(array('asset' => array('_only' => array('label', 'tags', 'identifier'))));
         $this->setVariablesToRender(array('asset'));
     }
     return parent::render();
 }
 /**
  * Configures rendering according to the set variable(s) and calls
  * render on the parent.
  *
  * @return string
  */
 public function render()
 {
     if (isset($this->variables['nodes'])) {
         $this->setConfiguration(array('nodes' => array('_descendAll' => array('_only' => array('name', 'path', 'identifier', 'properties', 'nodeType')))));
         $this->setVariablesToRender(array('nodes'));
     } else {
         $this->setConfiguration(array('node' => array('_only' => array('name', 'path', 'identifier', 'properties', 'nodeType'))));
         $this->setVariablesToRender(array('node'));
     }
     return parent::render();
 }
 /**
  * Configures rendering according to the set variable(s) and calls
  * render on the parent.
  *
  * @return string
  */
 public function render()
 {
     if (isset($this->variables['workspaces'])) {
         $this->setConfiguration(array('workspaces' => array('_descendAll' => array())));
         $this->setVariablesToRender(array('workspaces'));
     } else {
         $this->setConfiguration(array('workspace' => array()));
         $this->setVariablesToRender(array('workspace'));
     }
     return parent::render();
 }
 /**
  * @test
  */
 public function viewAcceptsJsonEncodingOptions()
 {
     $array = array('foo' => array('bar' => 'Baz', 'foo' => '1'));
     $this->view->setOption('jsonEncodingOptions', JSON_PRETTY_PRINT);
     $this->view->assign('array', $array);
     $this->view->setVariablesToRender(array('array'));
     $expectedResult = json_encode($array, JSON_PRETTY_PRINT);
     $actualResult = $this->view->render();
     $this->assertEquals($expectedResult, $actualResult);
     $unexpectedResult = json_encode($array);
     $this->assertNotEquals($unexpectedResult, $actualResult);
 }
Exemple #7
0
 /**
  * Transforms the value view variable to a serializable
  * array represantion using a YAML view configuration and JSON encodes
  * the result.
  *
  * @return string The JSON encoded variables
  * @api
  */
 public function render()
 {
     $result = parent::render();
     $this->controllerContext->getResponse()->setHeader('Content-Type', $this->getOption('contentTypeHeader'));
     return $result;
 }