lithium\tests\cases\net\http\MediaTest::testMediaTypes PHP Method

testMediaTypes() public method

Tests setting, getting and removing custom media types.
public testMediaTypes ( )
    public function testMediaTypes()
    {
        // Get a list of all available media types:
        $types = Media::types();
        // returns array('html', 'json', 'rss', ...);
        $expected = array('html', 'htm', 'form', 'json', 'rss', 'atom', 'css', 'js', 'text', 'txt', 'xml');
        $this->assertEqual($expected, $types);
        $this->assertEqual($expected, Media::formats());
        $result = Media::type('json');
        $expected = array('application/json');
        $this->assertEqual($expected, $result['content']);
        $expected = array('cast' => true, 'encode' => 'json_encode', 'decode' => $result['options']['decode']);
        $this->assertEqual($expected, $result['options']);
        // Add a custom media type with a custom view class:
        Media::type('my', 'text/x-my', array('view' => 'my\\custom\\View', 'paths' => array('layout' => false)));
        $result = Media::types();
        $this->assertTrue(in_array('my', $result));
        $result = Media::type('my');
        $expected = array('text/x-my');
        $this->assertEqual($expected, $result['content']);
        $expected = array('view' => 'my\\custom\\View', 'paths' => array('template' => '{:library}/views/{:controller}/{:template}.{:type}.php', 'layout' => false, 'element' => '{:library}/views/elements/{:template}.{:type}.php'), 'encode' => null, 'decode' => null, 'cast' => true, 'conditions' => array());
        $this->assertEqual($expected, $result['options']);
        // Remove a custom media type:
        Media::type('my', false);
        $result = Media::types();
        $this->assertFalse(in_array('my', $result));
    }