CoreFiles by mySites.guru
LinksTraitTest.php58 lines, 1,816 bytes, from Joomla_4.1.2-Stable-Full_Package.zip
Raw History Compare with 4.1.1
md5
7447d6c09f1cacc3e16cf459b115032e
sha1
560b08aedb906fb9bdfffc0013751104d9053393
sha256
8628b03aa09178b73f483858b133301df0c02dfd6532faf367fde1b46e036786
<?php

/*
 * This file is part of JSON-API.
 *
 * (c) Toby Zerner <[email protected]>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Tobscure\Tests\JsonApi;

use Tobscure\JsonApi\LinksTrait;

/**
 * This is the document test class.
 *
 * @author Toby Zerner <[email protected]>
 */
class LinksTraitTest extends AbstractTestCase
{
    public function testAddPaginationLinks()
    {
        $document = new Document;
        $document->addPaginationLinks('http://example.org', [], 0, 20);

        $this->assertEquals([
            'first' => 'http://example.org',
            'next' => 'http://example.org?page%5Boffset%5D=20'
        ], $document->getLinks());

        $document = new Document;
        $document->addPaginationLinks('http://example.org', ['foo' => 'bar', 'page' => ['limit' => 20]], 30, 20, 100);

        $this->assertEquals([
            'first' => 'http://example.org?foo=bar&page%5Blimit%5D=20',
            'prev' => 'http://example.org?foo=bar&page%5Blimit%5D=20&page%5Boffset%5D=10',
            'next' => 'http://example.org?foo=bar&page%5Blimit%5D=20&page%5Boffset%5D=50',
            'last' => 'http://example.org?foo=bar&page%5Blimit%5D=20&page%5Boffset%5D=80'
        ], $document->getLinks());

        $document = new Document;
        $document->addPaginationLinks('http://example.org', ['page' => ['number' => 2]], 50, 20, 100);

        $this->assertEquals([
            'first' => 'http://example.org',
            'prev' => 'http://example.org?page%5Bnumber%5D=2',
            'next' => 'http://example.org?page%5Bnumber%5D=4',
            'last' => 'http://example.org?page%5Bnumber%5D=5'
        ], $document->getLinks());
    }
}

class Document
{
    use LinksTrait;
}

The same content is in 9 releases, Joomla 4.1.0-rc1 to 4.1.2. See them all, or every version of this file.