Exemplo n.º 1
0
 public function testPrioritizesValuesBasedOnQParameter()
 {
     $header = Accept::fromString('Accept: text/plain; q=0.5, text/html, text/xml; q=0, text/x-dvi; q=0.8, text/x-c');
     $expected = array('text/html', 'text/x-c', 'text/x-dvi', 'text/plain');
     $test = array();
     foreach ($header->getPrioritized() as $type) {
         $test[] = $type;
     }
     $this->assertEquals($expected, $test);
 }
Exemplo n.º 2
0
 public function testPrioritizedLevel()
 {
     $header = Accept::fromString('Accept: text/*;q=0.3, text/html;q=0.7, text/html;level=1,text/html;level=2;q=0.4, */*;q=0.5');
     $expected = array('text/html;level=1', 'text/html', '*/*', 'text/html;level=2', 'text/*');
     $test = array();
     foreach ($header->getPrioritized() as $type) {
         $test[] = $type;
     }
     $this->assertEquals($expected, $test);
 }
Exemplo n.º 3
0
 public function testPrioritizing_2()
 {
     $accept = Accept::fromString("Accept: application/text, \tapplication/*");
     $res = $accept->getPrioritized();
     $this->assertEquals('application/text', $res[0]->raw);
     $this->assertEquals('application/*', $res[1]->raw);
     $accept = Accept::fromString("Accept: \tapplication/*, application/text");
     $res = $accept->getPrioritized();
     $this->assertEquals('application/text', $res[0]->raw);
     $this->assertEquals('application/*', $res[1]->raw);
     $accept = Accept::fromString("Accept: text/xml, application/xml");
     $res = $accept->getPrioritized();
     $this->assertEquals('application/xml', $res[0]->raw);
     $this->assertEquals('text/xml', $res[1]->raw);
     $accept = Accept::fromString("Accept: application/xml, text/xml");
     $res = $accept->getPrioritized();
     $this->assertEquals('application/xml', $res[0]->raw);
     $this->assertEquals('text/xml', $res[1]->raw);
     $accept = Accept::fromString("Accept: application/vnd.foobar+xml; q=0.9, text/xml");
     $res = $accept->getPrioritized();
     $this->assertEquals(1.0, $res[0]->getPriority());
     $this->assertEquals(0.9, $res[1]->getPriority());
     $this->assertEquals('application/vnd.foobar+xml', $res[1]->getTypeString());
     $this->assertEquals('vnd.foobar+xml', $res[1]->getSubtypeRaw());
     $this->assertEquals('vnd.foobar', $res[1]->getSubtype());
     $this->assertEquals('xml', $res[1]->getFormat());
     $accept = Accept::fromString('Accept: text/xml, application/vnd.foobar+xml; version="\'Ѿ"');
     $res = $accept->getPrioritized();
     $this->assertEquals('application/vnd.foobar+xml; version="\'Ѿ"', $res[0]->getRaw());
 }
 public function testInvalidModel()
 {
     $arr = array('DoesNotExist' => 'text/xml');
     $header = Accept::fromString('Accept: */*');
     $this->request->getHeaders()->addHeader($header);
     $this->setExpectedException('\\Zend\\Mvc\\Exception\\InvalidArgumentException');
     $this->plugin->getViewModel($arr);
 }
Exemplo n.º 5
0
 public function testAcceptFromStringCreatesValidAcceptHeader()
 {
     $acceptHeader = Accept::fromString('Accept: xxx');
     $this->assertInstanceOf('Zend\\Http\\Header\\HeaderDescription', $acceptHeader);
     $this->assertInstanceOf('Zend\\Http\\Header\\Accept', $acceptHeader);
 }
Exemplo n.º 6
0
 public function testUnknownAccept()
 {
     $this->config['diagnostics']['group']['test1'] = $check1 = new AlwaysSuccessCheck();
     ob_start();
     $request = new \Zend\Http\Request();
     $request->getHeaders()->addHeader(\Zend\Http\Header\Accept::fromString('Accept: application/baz'));
     $result = $this->controller->dispatch($request);
     $this->assertEquals('', ob_get_clean());
     $this->assertInstanceOf('Zend\\View\\Model\\ViewModel', $result);
     $this->assertInstanceOf('ZendDiagnostics\\Result\\Collection', $result->getVariable('results'));
 }