Open Journal Systems  3.3.0
Response/JsonVisitorTest.php
1 <?php
2 
4 
8 
13 {
14  public function testBeforeMethodParsesXml()
15  {
16  $visitor = new Visitor();
17  $command = $this->getMockBuilder('Guzzle\Service\Command\AbstractCommand')
18  ->setMethods(array('getResponse'))
19  ->getMockForAbstractClass();
20  $command->expects($this->once())
21  ->method('getResponse')
22  ->will($this->returnValue(new Response(200, null, '{"foo":"bar"}')));
23  $result = array();
24  $visitor->before($command, $result);
25  $this->assertEquals(array('foo' => 'bar'), $result);
26  }
27 
28  public function testVisitsLocation()
29  {
30  $visitor = new Visitor();
31  $param = new Parameter(array(
32  'name' => 'foo',
33  'type' => 'array',
34  'items' => array(
35  'filters' => 'strtoupper',
36  'type' => 'string'
37  )
38  ));
39  $this->value = array('foo' => array('a', 'b', 'c'));
40  $visitor->visit($this->command, $this->response, $param, $this->value);
41  $this->assertEquals(array('A', 'B', 'C'), $this->value['foo']);
42  }
43 
44  public function testRenamesTopLevelValues()
45  {
46  $visitor = new Visitor();
47  $param = new Parameter(array(
48  'name' => 'foo',
49  'sentAs' => 'Baz',
50  'type' => 'string',
51  ));
52  $this->value = array('Baz' => 'test');
53  $visitor->visit($this->command, $this->response, $param, $this->value);
54  $this->assertEquals(array('foo' => 'test'), $this->value);
55  }
56 
58  {
59  $visitor = new Visitor();
60  $param = new Parameter(array(
61  'name' => 'foo',
62  'type' => 'object',
63  'properties' => array(
64  'bar' => array(
65  'name' => 'bar',
66  'sentAs' => 'baz',
67  ),
68  ),
69  ));
70  $this->value = array('foo' => array('unknown' => 'Unknown'));
71  $visitor->visit($this->command, $this->response, $param, $this->value);
72  $this->assertEquals(array('foo' => array('unknown' => 'Unknown')), $this->value);
73  }
74 
76  {
77  $visitor = new Visitor();
78  $param = new Parameter(array(
79  'name' => 'foo',
80  'type' => 'object',
81  'properties' => array(
82  'foo' => array('filters' => 'strtoupper'),
83  'bar' => array('filters' => 'strtolower')
84  )
85  ));
86  $this->value = array('foo' => array('foo' => 'hello', 'bar' => 'THERE'));
87  $visitor->visit($this->command, $this->response, $param, $this->value);
88  $this->assertEquals(array('foo' => 'HELLO', 'bar' => 'there'), $this->value['foo']);
89  }
90 
96  {
97  $visitor = new Visitor();
98  $param = new Parameter(array(
99  'name' => 'foo',
100  'type' => 'object',
101  'additionalProperties' => false,
102  'properties' => array(
103  'bar' => array(
104  'type' => 'string',
105  'name' => 'bar',
106  ),
107  ),
108  ));
109  $this->value = array('foo' => array('bar' => 15, 'unknown' => 'Unknown'));
110  $visitor->visit($this->command, $this->response, $param, $this->value);
111  $this->assertEquals(array('foo' => array('bar' => 15)), $this->value);
112  }
113 
119  {
120  $visitor = new Visitor();
121  $param = new Parameter(array(
122  'name' => 'foo',
123  'type' => 'object',
124  'additionalProperties' => false,
125  'properties' => array(
126  'bar' => array(
127  'name' => 'bar',
128  'sentAs' => 'baz',
129  ),
130  ),
131  ));
132  $this->value = array('foo' => array('baz' => 15, 'unknown' => 'Unknown'));
133  $visitor->visit($this->command, $this->response, $param, $this->value);
134  $this->assertEquals(array('foo' => array('bar' => 15)), $this->value);
135  }
136 
138  {
139  $visitor = new Visitor();
140  $param = new Parameter(array(
141  'name' => 'foo',
142  'type' => 'object',
143  'additionalProperties' => array(
144  'type' => 'object',
145  'properties' => array(
146  'bar' => array(
147  'type' => 'string',
148  'filters' => array('base64_decode')
149  )
150  ),
151  ),
152  ));
153  $this->value = array('foo' => array('baz' => array('bar' => 'Zm9v')));
154  $visitor->visit($this->command, $this->response, $param, $this->value);
155  $this->assertEquals('foo', $this->value['foo']['baz']['bar']);
156  }
157 }
Guzzle\Service\Command\LocationVisitor\Response\JsonVisitor
Definition: Response/JsonVisitor.php:17
Guzzle\Tests\Service\Command\LocationVisitor\Response\AbstractResponseVisitorTest
Definition: AbstractResponseVisitorTest.php:8
Guzzle\Service\Description\Parameter
Definition: Parameter.php:10
Guzzle\Http\Message\Response
Definition: lib/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Response.php:17
Guzzle\Tests\Service\Command\LocationVisitor\Response\JsonVisitorTest\testWalksAdditionalProperties
testWalksAdditionalProperties()
Definition: Response/JsonVisitorTest.php:137
Guzzle\Tests\Service\Command\LocationVisitor\Response
Definition: AbstractResponseVisitorTest.php:3
Guzzle\Tests\Service\Command\LocationVisitor\Response\JsonVisitorTest\testRenamesDoesNotFailForNonExistentKey
testRenamesDoesNotFailForNonExistentKey()
Definition: Response/JsonVisitorTest.php:57
Guzzle\Tests\Service\Command\LocationVisitor\Response\AbstractResponseVisitorTest\$command
$command
Definition: AbstractResponseVisitorTest.php:20
Guzzle\Tests\Service\Command\LocationVisitor\Response\JsonVisitorTest\testBeforeMethodParsesXml
testBeforeMethodParsesXml()
Definition: Response/JsonVisitorTest.php:14
Guzzle\Tests\Service\Command\LocationVisitor\Response\JsonVisitorTest\testVisitsLocation
testVisitsLocation()
Definition: Response/JsonVisitorTest.php:28
Guzzle\Tests\Service\Command\LocationVisitor\Response\JsonVisitorTest\testTraversesObjectsAndAppliesFilters
testTraversesObjectsAndAppliesFilters()
Definition: Response/JsonVisitorTest.php:75
Guzzle\Tests\Service\Command\LocationVisitor\Response\JsonVisitorTest\testDiscardingUnknownProperties
testDiscardingUnknownProperties()
Definition: Response/JsonVisitorTest.php:95
Guzzle\Tests\Service\Command\LocationVisitor\Response\JsonVisitorTest\testRenamesTopLevelValues
testRenamesTopLevelValues()
Definition: Response/JsonVisitorTest.php:44
Guzzle\Tests\Service\Command\LocationVisitor\Response\JsonVisitorTest\testDiscardingUnknownPropertiesWithAliasing
testDiscardingUnknownPropertiesWithAliasing()
Definition: Response/JsonVisitorTest.php:118
Guzzle\Tests\Service\Command\LocationVisitor\Response\JsonVisitorTest
Definition: Response/JsonVisitorTest.php:12