FilterExtensionTest::testFilterByFields()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 17
rs 9.7
c 0
b 0
f 0
1
<?php
2
/**
3
 * Copyright 2016 - 2018, Cake Development Corporation (http://cakedc.com)
4
 *
5
 * Licensed under The MIT License
6
 * Redistributions of files must retain the above copyright notice.
7
 *
8
 * @copyright Copyright 2016 - 2018, Cake Development Corporation (http://cakedc.com)
9
 * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
10
 */
11
12
namespace CakeDC\Api\Test\TestCase\Integration\Service\Action\Extension;
13
14
use CakeDC\Api\TestSuite\IntegrationTestCase;
15
use CakeDC\Api\Test\ConfigTrait;
16
use CakeDC\Api\Test\FixturesTrait;
17
use CakeDC\Api\Test\Settings;
18
use Cake\Core\Configure;
19
use Cake\Utility\Hash;
20
21
/**
22
 * Class FilterExtensionTest
23
 *
24
 * @package CakeDC\Api\Test\TestCase\Integration\Service\Extension
25
 */
26
class FilterExtensionTest extends IntegrationTestCase
27
{
28
29
    use ConfigTrait;
30
    use FixturesTrait;
31
32
    /**
33
     * setUp
34
     *
35
     * @return void
36
     */
37
    public function setUp()
38
    {
39
        parent::setUp();
40
        Configure::write('App.fullBaseUrl', 'http://example.com');
41
        $this->_tokenAccess();
42
        $this->_loadDefaultExtensions('CakeDC/Api.Filter');
43
        $this->_loadDefaultExtensions('CakeDC/Api.Paginate');
44
        $this->getDefaultUser(Settings::USER1);
45
    }
46
47
    /**
48
     * tearDown
49
     *
50
     * @return void
51
     */
52
    public function tearDown()
53
    {
54
        parent::tearDown();
55
        Configure::write('Test.Api.Extension', null);
56
    }
57
58
    public function testFilterByFields()
59
    {
60
        $this->sendRequest('/articles', 'GET', ['limit' => 4, 'title' => 'Article N4']);
61
        $result = $this->getJsonResponse();
62
        $this->assertSuccess($result);
63
        $this->assertEquals([4], Hash::extract($result, 'data.{n}.id'));
64
65
        $this->sendRequest('/articles', 'GET', ['limit' => 4, 'title$like' => 'Article N']);
66
        $result = $this->getJsonResponse();
67
        $this->assertSuccess($result);
68
        $this->assertEquals([4, 5, 6, 7], Hash::extract($result, 'data.{n}.id'));
69
70
        $this->sendRequest('/articles', 'GET', ['limit' => 4, 'id$gt' => '5', 'id$lt' => 7]);
71
        $result = $this->getJsonResponse();
72
        $this->assertSuccess($result);
73
        $this->assertEquals([6], Hash::extract($result, 'data.{n}.id'));
74
    }
75
}
76