<commit_before><?php

require_once __DIR__ . "/ResolverTestCase.php";

class PathUrlResolverTest extends ResolverTestCase
{

    protected function setUp()
    {
        $this->urlResolver = new \Concrete\Core\Url\Resolver\PathUrlResolver();
    }

    public function testResolveSinglePath()
    {
        $path = '/some/path/to/something';

        $url = $this->canonicalUrlWithPath($path);
        $this->assertEquals($this->urlResolver->resolve(array($path)), (string) $url);
    }

    public function testSkipResolved()
    {
        $path = '/some/path/to/something';

        $resolved = uniqid();
        $this->assertEquals(
            $resolved,
            $this->urlResolver->resolve(array($path), $resolved));
    }

    public function testBadArguments()
    {
        $this->assertEquals(
            null,
            $this->urlResolver->resolve(array()));
    }

    public function testObjectPath()
    {
        $path = '/some/path/to/something';

        $this->assertEquals(
            $this->canonicalUrlWithPath($path),
            $this->urlResolver->resolve(
                array(new \Concrete\Core\Url\Components\Path($path))));
    }

    public function testUrlWithQuery()
    {
        $this->assertEquals(
            null,
            $this->urlResolver->resolve(array()));
    }

    public function testSegmentedPath()
    {
        $path = "/some/path/1/to/something";
        $segments = explode('/', trim($path, '/'));

        $this->assertEquals(
            $this->canonicalUrlWithPath($path),
            $this->urlResolver->resolve($segments));
    }

    public function testFragmentAndQuery()
    {
        $url = $this->urlResolver->resolve(array('/path/to/nothing/?query=true#fragment'));

        $this->assertEquals('fragment', $url->getFragment());
        $this->assertEquals('query=true', $url->getQuery());
    }

    public function testDispatcher()
    {
        $old_value = \Config::get('concrete.seo.url_rewriting');
        \Config::set('concrete.seo.url_rewriting', false);

        $canonical_path = $this->canonicalUrl->getPath();

        $url = $this->urlResolver->resolve(array('test'));
        $this->assertNotNull($url);

        if (!is_null($url)) {
            $dispatcher = DISPATCHER_FILENAME;
            $this->assertEquals("{$dispatcher}/test", $url->getPath()->getRelativePath($canonical_path));
        }


        \Config::set('concrete.seo.url_rewriting', $old_value);
    }

}<commit_msg>Adjust test to pass when $canonical_path is empty<commit_after><?php

require_once __DIR__ . "/ResolverTestCase.php";

class PathUrlResolverTest extends ResolverTestCase
{

    protected function setUp()
    {
        $this->urlResolver = new \Concrete\Core\Url\Resolver\PathUrlResolver();
    }

    public function testResolveSinglePath()
    {
        $path = '/some/path/to/something';

        $url = $this->canonicalUrlWithPath($path);
        $this->assertEquals($this->urlResolver->resolve(array($path)), (string) $url);
    }

    public function testSkipResolved()
    {
        $path = '/some/path/to/something';

        $resolved = uniqid();
        $this->assertEquals(
            $resolved,
            $this->urlResolver->resolve(array($path), $resolved));
    }

    public function testBadArguments()
    {
        $this->assertEquals(
            null,
            $this->urlResolver->resolve(array()));
    }

    public function testObjectPath()
    {
        $path = '/some/path/to/something';

        $this->assertEquals(
            $this->canonicalUrlWithPath($path),
            $this->urlResolver->resolve(
                array(new \Concrete\Core\Url\Components\Path($path))));
    }

    public function testUrlWithQuery()
    {
        $this->assertEquals(
            null,
            $this->urlResolver->resolve(array()));
    }

    public function testSegmentedPath()
    {
        $path = "/some/path/1/to/something";
        $segments = explode('/', trim($path, '/'));

        $this->assertEquals(
            $this->canonicalUrlWithPath($path),
            $this->urlResolver->resolve($segments));
    }

    public function testFragmentAndQuery()
    {
        $url = $this->urlResolver->resolve(array('/path/to/nothing/?query=true#fragment'));

        $this->assertEquals('fragment', $url->getFragment());
        $this->assertEquals('query=true', $url->getQuery());
    }

    public function testDispatcher()
    {
        $old_value = \Config::get('concrete.seo.url_rewriting');
        \Config::set('concrete.seo.url_rewriting', false);

        $canonical_path = $this->canonicalUrl->getPath();

        $url = $this->urlResolver->resolve(array('test'));
        $this->assertNotNull($url);

        if (!is_null($url)) {
            $dispatcher = DISPATCHER_FILENAME;
            $relative_path = (string)trim($canonical_path, '/') ?
                $url->getPath()->getRelativePath($canonical_path) :
                $url->getPath();
            $this->assertEquals("{$dispatcher}/test", $relative_path);
        }


        \Config::set('concrete.seo.url_rewriting', $old_value);
    }

}
{'fraction_non_alphanumeric': 0.16099374021909232, 'fraction_numerical': 0.0003912363067292645, 'mean_word_length': 2.473505434782609, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 76, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6642700', 'n_tokens_mistral': 1500, 'n_tokens_neox': 1438, 'n_words': 205}