CrudAutocompleteListExtensionTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 49
rs 10
c 0
b 0
f 0
wmc 4
lcom 2
cbo 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 9 1
A tearDown() 0 5 1
A testNoAutocompleteList() 0 8 1
A testAutocompleteList() 0 7 1
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 CrudAutocompleteListExtensionTest
23
 *
24
 * @package CakeDC\Api\Test\TestCase\Integration\Service\Extension
25
 */
26
class CrudAutocompleteListExtensionTest 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.CrudAutocompleteList');
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 testNoAutocompleteList()
59
    {
60
        $this->sendRequest('/articles', 'GET', ['limit' => 4, 'autocomplete_list' => false]);
61
        $result = $this->getJsonResponse();
62
        $this->assertSuccess($result);
63
        $this->assertEquals([1, 3, 2, 4], Hash::extract($result, 'data.{n}.author_id'));
64
        $this->assertEquals(['id', 'author_id', 'title', 'body', 'published'], array_keys(Hash::get($result, 'data.0')));
65
    }
66
67
    public function testAutocompleteList()
68
    {
69
        $this->sendRequest('/articles', 'GET', ['limit' => 4, 'autocomplete_list' => true]);
70
        $result = $this->getJsonResponse();
71
        $this->assertSuccess($result);
72
        $this->assertEquals(['id', 'title'], array_keys(Hash::get($result, 'data.0')));
73
    }
74
}
75