<commit_before><?php
/*
 * This file is part of the Foil package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace Foil\Tests\Extension;

use Foil\Tests\TestCase;
use Foil\Extensions\Links;

/**
 * @author  <NAME> <<EMAIL>>
 * @package foil\foil
 * @license http://opensource.org/licenses/MIT MIT
 */
class LinksTest extends TestCase
{
    public function testLinkNoDomainNoDirs()
    {
        $l = new Links();
        assertSame('/foo/bar', $l->link('foo/bar/', 'foo', 'https'));
    }

    public function testLinkDomainNoDirs()
    {
        $l1 = new Links();
        $l1->setup([
            'host'        => 'www.example.com',
            'assets_host' => 'static.example.com',
            'assets_path' => 'path/to/',
        ]);
        $l2 = new Links();
        $l2->setup(['host' => 'http://example.com']);
        assertSame('https://www.example.com/foo/bar', $l1->link('foo/bar/', 'foo', 'https'));
        assertSame('http://example.com/foo/bar', $l2->link('foo/bar/', 'foo', 'bar'));
    }

    public function testLinkNoDomainDirs()
    {
        $l = new Links();
        $l->setup([
            'urls' => ['pdf' => '/url/to/pdf/', 'doc' => 'url/to/doc'],
        ]);
        assertSame('/url/to/pdf/foo.pdf', $l->link('foo.pdf', 'pdf'));
        assertSame('/url/to/doc/foo.doc', $l->link('foo.doc', 'doc'));
    }

    public function testLinkDomainDirs()
    {
        $l = new Links();
        $l->setup([
            'urls'        => ['pdf' => '/url/to/pdf/'],
            'host'        => 'example.com',
            'assets_host' => 'static.example.com',
        ]);
        assertSame('http://example.com/url/to/pdf/foo.pdf', $l->link('foo.pdf', 'pdf'));
        assertSame('https://example.com/url/to/pdf/foo.pdf', $l->link('foo.pdf', 'pdf', 'https'));
    }

    public function testAssetNothing()
    {
        $l = new Links();
        assertSame('/foo.js', $l->asset('foo.js'));
    }

    public function testAssetOnlyUrl()
    {
        $l = new Links();
        $path = FOILTESTSBASEPATH.'/_files/assets';
        $l->setup(['assets_url' => '/assets/']);
        assertSame('/assets/foo.js', $l->asset('foo.js'));
    }

    public function testAssetOnlyDomain()
    {
        $path = FOILTESTSBASEPATH.'/_files/assets';
        $l = new Links();
        $l->setup(['host' => 'example.com']);
        $l2 = new Links();<commit_msg>Remove unused var in LinkTests<commit_after><?php
/*
 * This file is part of the Foil package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace Foil\Tests\Extension;

use Foil\Tests\TestCase;
use Foil\Extensions\Links;

/**
 * @author  <NAME> <<EMAIL>>
 * @package foil\foil
 * @license http://opensource.org/licenses/MIT MIT
 */
class LinksTest extends TestCase
{
    public function testLinkNoDomainNoDirs()
    {
        $l = new Links();
        assertSame('/foo/bar', $l->link('foo/bar/', 'foo', 'https'));
    }

    public function testLinkDomainNoDirs()
    {
        $l1 = new Links();
        $l1->setup([
            'host'        => 'www.example.com',
            'assets_host' => 'static.example.com',
            'assets_path' => 'path/to/',
        ]);
        $l2 = new Links();
        $l2->setup(['host' => 'http://example.com']);
        assertSame('https://www.example.com/foo/bar', $l1->link('foo/bar/', 'foo', 'https'));
        assertSame('http://example.com/foo/bar', $l2->link('foo/bar/', 'foo', 'bar'));
    }

    public function testLinkNoDomainDirs()
    {
        $l = new Links();
        $l->setup([
            'urls' => ['pdf' => '/url/to/pdf/', 'doc' => 'url/to/doc'],
        ]);
        assertSame('/url/to/pdf/foo.pdf', $l->link('foo.pdf', 'pdf'));
        assertSame('/url/to/doc/foo.doc', $l->link('foo.doc', 'doc'));
    }

    public function testLinkDomainDirs()
    {
        $l = new Links();
        $l->setup([
            'urls'        => ['pdf' => '/url/to/pdf/'],
            'host'        => 'example.com',
            'assets_host' => 'static.example.com',
        ]);
        assertSame('http://example.com/url/to/pdf/foo.pdf', $l->link('foo.pdf', 'pdf'));
        assertSame('https://example.com/url/to/pdf/foo.pdf', $l->link('foo.pdf', 'pdf', 'https'));
    }

    public function testAssetNothing()
    {
        $l = new Links();
        assertSame('/foo.js', $l->asset('foo.js'));
    }

    public function testAssetOnlyUrl()
    {
        $l = new Links();
        $l->setup(['assets_url' => '/assets/']);
        assertSame('/assets/foo.js', $l->asset('foo.js'));
    }

    public function testAssetOnlyDomain()
    {
        $l = new Links();
        $l->setup(['host' => 'example.com']);
        $l2 = new Links();
{'fraction_non_alphanumeric': 0.2087170042971148, 'fraction_numerical': 0.002864743196234909, 'mean_word_length': 2.2349437458636663, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 71, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '511247', 'n_tokens_mistral': 1628, 'n_tokens_neox': 1599, 'n_words': 313}