Open Journal Systems  3.3.0
AcceptHeaderItemTest.php
1 <?php
2 
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
13 
14 use PHPUnit\Framework\TestCase;
16 
17 class AcceptHeaderItemTest extends TestCase
18 {
22  public function testFromString($string, $value, array $attributes)
23  {
24  $item = AcceptHeaderItem::fromString($string);
25  $this->assertEquals($value, $item->getValue());
26  $this->assertEquals($attributes, $item->getAttributes());
27  }
28 
29  public function provideFromStringData()
30  {
31  return array(
32  array(
33  'text/html',
34  'text/html', array(),
35  ),
36  array(
37  '"this;should,not=matter"',
38  'this;should,not=matter', array(),
39  ),
40  array(
41  "text/plain; charset=utf-8;param=\"this;should,not=matter\";\tfootnotes=true",
42  'text/plain', array('charset' => 'utf-8', 'param' => 'this;should,not=matter', 'footnotes' => 'true'),
43  ),
44  array(
45  '"this;should,not=matter";charset=utf-8',
46  'this;should,not=matter', array('charset' => 'utf-8'),
47  ),
48  );
49  }
50 
54  public function testToString($value, array $attributes, $string)
55  {
56  $item = new AcceptHeaderItem($value, $attributes);
57  $this->assertEquals($string, (string) $item);
58  }
59 
60  public function provideToStringData()
61  {
62  return array(
63  array(
64  'text/html', array(),
65  'text/html',
66  ),
67  array(
68  'text/plain', array('charset' => 'utf-8', 'param' => 'this;should,not=matter', 'footnotes' => 'true'),
69  'text/plain;charset=utf-8;param="this;should,not=matter";footnotes=true',
70  ),
71  );
72  }
73 
74  public function testValue()
75  {
76  $item = new AcceptHeaderItem('value', array());
77  $this->assertEquals('value', $item->getValue());
78 
79  $item->setValue('new value');
80  $this->assertEquals('new value', $item->getValue());
81 
82  $item->setValue(1);
83  $this->assertEquals('1', $item->getValue());
84  }
85 
86  public function testQuality()
87  {
88  $item = new AcceptHeaderItem('value', array());
89  $this->assertEquals(1.0, $item->getQuality());
90 
91  $item->setQuality(0.5);
92  $this->assertEquals(0.5, $item->getQuality());
93 
94  $item->setAttribute('q', 0.75);
95  $this->assertEquals(0.75, $item->getQuality());
96  $this->assertFalse($item->hasAttribute('q'));
97  }
98 
99  public function testAttribute()
100  {
101  $item = new AcceptHeaderItem('value', array());
102  $this->assertEquals(array(), $item->getAttributes());
103  $this->assertFalse($item->hasAttribute('test'));
104  $this->assertNull($item->getAttribute('test'));
105  $this->assertEquals('default', $item->getAttribute('test', 'default'));
106 
107  $item->setAttribute('test', 'value');
108  $this->assertEquals(array('test' => 'value'), $item->getAttributes());
109  $this->assertTrue($item->hasAttribute('test'));
110  $this->assertEquals('value', $item->getAttribute('test'));
111  $this->assertEquals('value', $item->getAttribute('test', 'default'));
112  }
113 }
Symfony\Component\HttpFoundation\Tests\AcceptHeaderItemTest\testAttribute
testAttribute()
Definition: AcceptHeaderItemTest.php:99
Symfony\Component\HttpFoundation\AcceptHeaderItem
Definition: lib/vendor/symfony/http-foundation/AcceptHeaderItem.php:19
Symfony\Component\HttpFoundation\Tests\AcceptHeaderItemTest\provideFromStringData
provideFromStringData()
Definition: AcceptHeaderItemTest.php:29
Symfony\Component\HttpFoundation\Tests\AcceptHeaderItemTest
Definition: AcceptHeaderItemTest.php:17
Symfony\Component\HttpFoundation\AcceptHeaderItem\fromString
static fromString($itemValue)
Definition: lib/vendor/symfony/http-foundation/AcceptHeaderItem.php:74
Symfony\Component\HttpFoundation\Tests\AcceptHeaderItemTest\testFromString
testFromString($string, $value, array $attributes)
Definition: AcceptHeaderItemTest.php:22
Symfony\Component\HttpFoundation\Tests\AcceptHeaderItemTest\testValue
testValue()
Definition: AcceptHeaderItemTest.php:74
Symfony\Component\HttpFoundation\Tests\AcceptHeaderItemTest\provideToStringData
provideToStringData()
Definition: AcceptHeaderItemTest.php:60
Symfony\Component\HttpFoundation\Tests
Definition: AcceptHeaderItemTest.php:12
Symfony\Component\HttpFoundation\Tests\AcceptHeaderItemTest\testToString
testToString($value, array $attributes, $string)
Definition: AcceptHeaderItemTest.php:54
Symfony\Component\HttpFoundation\Tests\AcceptHeaderItemTest\testQuality
testQuality()
Definition: AcceptHeaderItemTest.php:86