Open Journal Systems  3.3.0
UriTemplateTest.php
1 <?php
2 
4 
6 
11 {
15  public function testExpandsUriTemplates($template, $expansion, $params)
16  {
17  $uri = new UriTemplate($template);
18  $this->assertEquals($expansion, $uri->expand($template, $params));
19  }
20 
21  public function expressionProvider()
22  {
23  return array(
24  array(
25  '{+var*}', array(
26  'operator' => '+',
27  'values' => array(
28  array('value' => 'var', 'modifier' => '*')
29  )
30  ),
31  ),
32  array(
33  '{?keys,var,val}', array(
34  'operator' => '?',
35  'values' => array(
36  array('value' => 'keys', 'modifier' => ''),
37  array('value' => 'var', 'modifier' => ''),
38  array('value' => 'val', 'modifier' => '')
39  )
40  ),
41  ),
42  array(
43  '{+x,hello,y}', array(
44  'operator' => '+',
45  'values' => array(
46  array('value' => 'x', 'modifier' => ''),
47  array('value' => 'hello', 'modifier' => ''),
48  array('value' => 'y', 'modifier' => '')
49  )
50  )
51  )
52  );
53  }
54 
58  public function testParsesExpressions($exp, $data)
59  {
60  $template = new UriTemplate($exp);
61 
62  // Access the config object
63  $class = new \ReflectionClass($template);
64  $method = $class->getMethod('parseExpression');
65  $method->setAccessible(true);
66 
67  $exp = substr($exp, 1, -1);
68  $this->assertEquals($data, $method->invokeArgs($template, array($exp)));
69  }
70 
75  {
76  $template = new UriTemplate();
77 
78  $result = $template->expand('http://example.com{+path}{/segments}{?query,data*,foo*}', array(
79  'path' => '/foo/bar',
80  'segments' => array('one', 'two'),
81  'query' => 'test',
82  'data' => array(
83  'more' => array('fun', 'ice cream')
84  ),
85  'foo' => array(
86  'baz' => array(
87  'bar' => 'fizz',
88  'test' => 'buzz'
89  ),
90  'bam' => 'boo'
91  )
92  ));
93 
94  $this->assertEquals('http://example.com/foo/bar/one,two?query=test&more%5B0%5D=fun&more%5B1%5D=ice%20cream&baz%5Bbar%5D=fizz&baz%5Btest%5D=buzz&bam=boo', $result);
95  }
96 
100  public function testSetRegex()
101  {
102  $template = new UriTemplate();
103  $template->setRegex('/<\$(.+)>/');
104  $this->assertSame('/foo', $template->expand('/<$a>', array('a' => 'foo')));
105  }
106 }
Guzzle\Tests\Parsers\UriTemplate\UriTemplateTest\testAllowsNestedArrayExpansion
testAllowsNestedArrayExpansion()
Definition: UriTemplateTest.php:74
Guzzle\Tests\Parsers\UriTemplate\AbstractUriTemplateTest
Definition: AbstractUriTemplateTest.php:5
Guzzle\Parser\UriTemplate\UriTemplate
Definition: lib/vendor/guzzle/guzzle/src/Guzzle/Parser/UriTemplate/UriTemplate.php:10
Guzzle\Tests\Parsers\UriTemplate\UriTemplateTest\testSetRegex
testSetRegex()
Definition: UriTemplateTest.php:100
Guzzle\Tests\Parsers\UriTemplate\UriTemplateTest\expressionProvider
expressionProvider()
Definition: UriTemplateTest.php:21
Guzzle\Tests\Parsers\UriTemplate\UriTemplateTest\testParsesExpressions
testParsesExpressions($exp, $data)
Definition: UriTemplateTest.php:58
Guzzle\Tests\Parsers\UriTemplate
Definition: AbstractUriTemplateTest.php:3
Guzzle\Tests\Parsers\UriTemplate\UriTemplateTest
Definition: UriTemplateTest.php:10
Guzzle\Tests\Parsers\UriTemplate\UriTemplateTest\testExpandsUriTemplates
testExpandsUriTemplates($template, $expansion, $params)
Definition: UriTemplateTest.php:15