summaryrefslogtreecommitdiff
path: root/vendor/league/glide/tests/Urls/UrlBuilderTest.php
blob: f700b8bdbcd21a1358fa5e4486c75d50a2ab8698 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php

namespace League\Glide\Urls;

use League\Glide\Signatures\Signature;

class UrlBuilderTest extends \PHPUnit_Framework_TestCase
{
    public function testCreateInstance()
    {
        $this->assertInstanceOf('League\Glide\Urls\UrlBuilder', new UrlBuilder());
    }

    public function testGetUrl()
    {
        $urlBuilder = new UrlBuilder('http://example.com');

        $this->assertEquals(
            'http://example.com/image.jpg?w=100',
            $urlBuilder->getUrl('image.jpg', ['w' => '100'])
        );
    }

    public function testGetUrlWithNoDomain()
    {
        $urlBuilder = new UrlBuilder();

        $this->assertEquals(
            '/image.jpg?w=100',
            $urlBuilder->getUrl('image.jpg', ['w' => '100'])
        );
    }

    public function testGetUrlWithDomainAndPort()
    {
        $urlBuilder = new UrlBuilder('http://localhost:8000');

        $this->assertEquals(
            'http://localhost:8000/image.jpg?w=100',
            $urlBuilder->getUrl('image.jpg', ['w' => '100'])
        );
    }

    public function testGetUrlWithProtocolRelativeDomain()
    {
        $urlBuilder = new UrlBuilder('//localhost:8000');

        $this->assertEquals(
            '//localhost:8000/image.jpg?w=100',
            $urlBuilder->getUrl('image.jpg', ['w' => '100'])
        );
    }

    public function testGetUrlWithToken()
    {
        $urlBuilder = new UrlBuilder('http://example.com', new Signature('example-sign-key'));

        $this->assertEquals(
            'http://example.com/image.jpg?w=100&s=e1b69d4b79ecf33283128819fd008906',
            $urlBuilder->getUrl('image.jpg', ['w' => '100'])
        );
    }

    public function testGetInvalidUrl()
    {
        $this->setExpectedException('\InvalidArgumentException', 'Not a valid path.');

        $urlBuilder = new UrlBuilder(':80');
        $urlBuilder->getUrl('image.jpg');
    }
}