Skip to content

Commit

Permalink
Merge pull request #214 from FriendsOfCake/cake-36
Browse files Browse the repository at this point in the history
Cake 36
  • Loading branch information
ADmad authored Apr 15, 2018
2 parents ef1a489 + 8c4e650 commit 482191d
Show file tree
Hide file tree
Showing 17 changed files with 155 additions and 144 deletions.
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Git will always convert line endings to LF on checkout.
# You should use this for files that must keep LF endings, even on Windows.
* text eol=lf

# Remove files for archives generated using `git archive`
.editorconfig export-ignore
.gitattributes export-ignore
Expand Down
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ matrix:
- php: 7.0
env: PHPSTAN=1 DEFAULT=0

- php: 5.6
env: PREFER_LOWEST=1

before_script:
- if [[ $TRAVIS_PHP_VERSION != 7.0 ]]; then phpenv config-rm xdebug.ini; fi

- composer install
- if [[ $PREFER_LOWEST != 1 ]]; then composer update --no-interaction ; fi
- if [[ $PREFER_LOWEST == 1 ]]; then composer update --no-interaction --prefer-lowest ; fi

- if [[ $PHPSTAN = 1 ]]; then composer require phpstan/phpstan; fi

Expand Down
24 changes: 13 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,29 @@
"homepage": "http://cakephp.nu/"
},
{
"name":"ADmad",
"role":"Contributor",
"homepage":"https://github.com/admad"
"name": "ADmad",
"role": "Contributor",
"homepage": "https://github.com/admad"
}
],
"require": {
"cakephp/cakephp": "^3.4"
"cakephp/cakephp": "^3.6.0"
},
"require-dev": {
"friendsofcake/cakephp-test-utilities": "dev-master",
"phpunit/phpunit": "<6.0",
"friendsofcake/cakephp-test-utilities": "^1.0",
"phpunit/phpunit": "^5.7.14|^6.0",
"cakephp/cakephp-codesniffer": "^3.0",
"muffin/webservice": "^1.2"
"muffin/webservice": "^1.3"
},
"autoload": {
"psr-4": {
"Search\\": "src"
"Search\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Search\\Test\\": "tests",
"Cake\\Test\\Fixture\\": "./vendor/cakephp/cakephp/tests/Fixture"
"Search\\Test\\": "tests/",
"Cake\\Test\\Fixture\\": "vendor/cakephp/cakephp/tests/Fixture/"
}
},
"support": {
Expand All @@ -48,6 +48,8 @@
"irc": "irc://irc.freenode.org/friendsofcake"
},
"scripts": {
"cs-check": "vendor/bin/phpcs -p --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests"
"cs-check": "phpcs -p --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests",
"cs-fix": "phpcbf --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests",
"test": "phpunit"
}
}
2 changes: 1 addition & 1 deletion src/Controller/Component/PrgComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function startup()
return null;
}

list($url) = explode('?', $this->request->here(false));
list($url) = explode('?', $this->request->getRequestTarget());

$params = $this->_filterParams();
if ($params) {
Expand Down
4 changes: 2 additions & 2 deletions src/Model/Filter/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ public function manager()
*/
public function field()
{
$field = $this->config('field');
if (!$this->config('aliasField')) {
$field = $this->getConfig('field');
if (!$this->getConfig('aliasField')) {
return $field;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Model/Filter/Like.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ protected function _formatWildcards($value)
protected function _setEscaper()
{
if ($this->getConfig('escaper') === null) {
$driver = get_class($this->getQuery()->connection()->driver());
$driver = get_class($this->getQuery()->getConnection()->getDriver());
$driverName = 'Sqlserver';
if (substr_compare($driver, $driverName, -strlen($driverName)) === 0) {
$this->setConfig('escaper', 'Search.Sqlserver');
Expand Down
2 changes: 1 addition & 1 deletion src/Model/SearchTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ protected function _flattenParams($params, $filters)
$flattened = [];
foreach ($params as $key => $value) {
if (!is_array($value) ||
(!empty($filters[$key]) && $filters[$key]->config()['flatten'] === false)
(!empty($filters[$key]) && $filters[$key]->getConfig('flatten') === false)
) {
$flattened[$key] = $value;
continue;
Expand Down
2 changes: 1 addition & 1 deletion tests/TestApp/Model/Table/FinderArticlesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function initialize(array $config)
{
parent::initialize($config);

$this->table('articles');
$this->setTable('articles');
}

/**
Expand Down
117 changes: 59 additions & 58 deletions tests/TestCase/Controller/Component/PrgComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
namespace Search\Test\TestCase\Controller\Component;

use Cake\Controller\Controller;
use Cake\Network\Request;
use Cake\Http\ServerRequest;
use Cake\ORM\Table;
use Cake\Routing\RouteBuilder;
use Cake\Routing\Router;
Expand Down Expand Up @@ -44,9 +44,9 @@ public function setUp()
);
$routes->fallbacks();
});
$request = new Request();
$request = new ServerRequest();
$response = $this
->getMockBuilder('Cake\Network\Response')
->getMockBuilder('Cake\Http\Response')
->setMethods(['stop'])
->getMock();

Expand All @@ -59,150 +59,151 @@ public function setUp()
*/
public function testInitializePost()
{
$this->Controller->request->params = [
$this->Controller->request = $this->Controller->request->withAttribute('params', [
'controller' => 'Posts',
'action' => 'index',
'pass' => ['pass']
];
$this->Controller->request->here = '/Posts/index/pass';
$this->Controller->request->data = ['foo' => 'bar'];
$this->Controller->request->env('REQUEST_METHOD', 'POST');
]);
$this->Controller->request = $this->Controller->request->withRequestTarget('/Posts/index/pass');
$this->Controller->request = $this->Controller->request->withData('foo', 'bar');
$this->Controller->request = $this->Controller->request->withEnv('REQUEST_METHOD', 'POST');

$response = $this->Prg->startup();
$this->assertEquals('http://localhost/Posts/index/pass?foo=bar', $response->header()['Location']);
$this->assertEquals('http://localhost/Posts/index/pass?foo=bar', $response->getHeaderLine('Location'));

$this->Prg->config('actions', false);
$this->Prg->setConfig('actions', false);
$response = $this->Prg->startup();
$this->assertNull($response);

$this->Prg->config('actions', 'does-not-exist', false);
$this->Prg->setConfig('actions', 'does-not-exist', false);
$response = $this->Prg->startup();
$this->assertNull($response);

$this->Prg->config('actions', 'index', false);
$this->Controller->response->header('Location', '');
$this->Prg->setConfig('actions', 'index', false);
$this->Controller->response = $this->Controller->response->withHeader('Location', '');
$response = $this->Prg->startup();
$this->assertEquals('http://localhost/Posts/index/pass?foo=bar', $response->header()['Location']);
$this->assertEquals('http://localhost/Posts/index/pass?foo=bar', $response->getHeaderLine('Location'));

$this->Prg->config('actions', ['index', 'does-not-exist'], false);
$this->Controller->response->header('Location', '');
$this->Prg->setConfig('actions', ['index', 'does-not-exist'], false);
$this->Controller->response = $this->Controller->response->withHeader('Location', '');
$response = $this->Prg->startup();
$this->assertEquals('http://localhost/Posts/index/pass?foo=bar', $response->header()['Location']);
$this->assertEquals('http://localhost/Posts/index/pass?foo=bar', $response->getHeaderLine('Location'));

$this->Prg->config('actions', true);
$this->Controller->request->params = [
$this->Prg->setConfig('actions', true);
$this->Controller->request = $this->Controller->request->withAttribute('params', [
'controller' => 'UserAnswers',
'action' => 'index',
'type' => 'open',
'pass' => ['open']
];
$this->Controller->request->here = '/users/my-predictions';
$this->Controller->response->header('Location', '');
]);
$this->Controller->request = $this->Controller->request->withRequestTarget('/users/my-predictions');
$this->Controller->response = $this->Controller->response->withHeader('Location', '');
$response = $this->Prg->startup();
$this->assertEquals('http://localhost/users/my-predictions?foo=bar', $response->header()['Location']);
$this->assertEquals('http://localhost/users/my-predictions?foo=bar', $response->getHeaderLine('Location'));

$this->Controller->request->data = ['foo' => ''];
$this->Controller->response->header('Location', '');
$this->Controller->request = $this->Controller->request->withData('foo', '');
$this->Controller->response = $this->Controller->response->withHeader('Location', '');
$response = $this->Prg->startup();
$this->assertEquals('http://localhost/users/my-predictions', $response->header()['Location']);
$this->assertEquals('http://localhost/users/my-predictions', $response->getHeaderLine('Location'));
}

/**
* @return void
*/
public function testInitializePostWithEmptyValues()
{
$this->Controller->request->params = [
$this->Controller->request = $this->Controller->request->withAttribute('params', [
'controller' => 'Posts',
'action' => 'index',
'pass' => ['pass']
];
$this->Controller->request->here = '/Posts/index/pass';
$this->Controller->request->data = ['foo' => 'bar', 'checkbox' => '0'];
$this->Controller->request->env('REQUEST_METHOD', 'POST');
]);
$this->Controller->request = $this->Controller->request->withRequestTarget('/Posts/index/pass');
$this->Controller->request = $this->Controller->request = $this->Controller->request = $this->Controller->request->withData('foo', 'bar');
$this->Controller->request = $this->Controller->request = $this->Controller->request = $this->Controller->request->withData('checkbox', '0');
$this->Controller->request = $this->Controller->request->withEnv('REQUEST_METHOD', 'POST');

$this->Prg->configShallow('emptyValues', [
'checkbox' => '0',
]);
$response = $this->Prg->startup();
$this->assertEquals('http://localhost/Posts/index/pass?foo=bar', $response->header()['Location']);
$this->assertEquals('http://localhost/Posts/index/pass?foo=bar', $response->getHeaderLine('Location'));
}

/**
* @return void
*/
public function testInitializePostWithQueryStringWhitelist()
{
$this->Controller->request->query = [
$this->Controller->request = $this->Controller->request->withQueryParams([
'sort' => 'created',
'direction' => 'desc',
'page' => 9,
];
$this->Controller->request->params = [
]);
$this->Controller->request = $this->Controller->request->withAttribute('params', [
'controller' => 'Posts',
'action' => 'index',
'pass' => ['pass']
];
$this->Controller->request->here = '/Posts/index/pass';
$this->Controller->request->data = ['foo' => 'bar'];
$this->Controller->request->env('REQUEST_METHOD', 'POST');
]);
$this->Controller->request = $this->Controller->request->withRequestTarget('/Posts/index/pass');
$this->Controller->request = $this->Controller->request->withData('foo', 'bar');
$this->Controller->request = $this->Controller->request->withEnv('REQUEST_METHOD', 'POST');

$response = $this->Prg->startup();
$this->assertEquals('http://localhost/Posts/index/pass?foo=bar&sort=created&direction=desc', $response->header()['Location']);
$this->assertEquals('http://localhost/Posts/index/pass?foo=bar&sort=created&direction=desc', $response->getHeaderLine('Location'));
}

/**
* @return void
*/
public function testInitializePostWithQueryStringWhitelistEmpty()
{
$this->Controller->request->query = [
$this->Controller->request = $this->Controller->request->withQueryParams([
'sort' => 'created',
'direction' => 'desc',
'page' => 9,
];
$this->Controller->request->params = [
]);
$this->Controller->request = $this->Controller->request->withAttribute('params', [
'controller' => 'Posts',
'action' => 'index',
'pass' => ['pass']
];
$this->Controller->request->here = '/Posts/index/pass';
$this->Controller->request->data = ['foo' => 'bar'];
$this->Controller->request->env('REQUEST_METHOD', 'POST');
]);
$this->Controller->request = $this->Controller->request->withRequestTarget('/Posts/index/pass');
$this->Controller->request = $this->Controller->request->withData('foo', 'bar');
$this->Controller->request = $this->Controller->request->withEnv('REQUEST_METHOD', 'POST');

// Needed as config() would not do anything here due to internal default behavior of merging here
$this->Prg->configShallow('queryStringWhitelist', []);
$response = $this->Prg->startup();
$this->assertEquals('http://localhost/Posts/index/pass?foo=bar', $response->header()['Location']);
$this->assertEquals('http://localhost/Posts/index/pass?foo=bar', $response->getHeaderLine('Location'));
}

/**
* @return void
*/
public function testConversionWithRedirect()
{
$this->Controller->request->params = [
$this->Controller->request = $this->Controller->request->withAttribute('params', [
'controller' => 'Posts',
'action' => 'index',
'pass' => ['pass']
];
$this->Controller->request->here = '/Posts/index/pass';
$this->Controller->request->data = ['foo' => 'bar'];
$this->Controller->request->env('REQUEST_METHOD', 'POST');
]);
$this->Controller->request = $this->Controller->request->withRequestTarget('/Posts/index/pass');
$this->Controller->request = $this->Controller->request->withData('foo', 'bar');
$this->Controller->request = $this->Controller->request->withEnv('REQUEST_METHOD', 'POST');

$response = $this->Prg->startup();
$this->assertEquals('http://localhost/Posts/index/pass?foo=bar', $response->header()['Location']);
$this->assertEquals('http://localhost/Posts/index/pass?foo=bar', $response->getHeaderLine('Location'));
}

/**
* @return void
*/
public function testIsSearchFalse()
{
$this->Controller->request->params = [
$this->Controller->request = $this->Controller->request->withAttribute('params', [
'controller' => 'Articles',
'action' => 'index',
];
]);
$this->Controller->modelClass = 'Articles';
$this->Controller->loadModel('Articles');
$this->Controller->Articles->addBehavior('Search.Search');
Expand All @@ -219,10 +220,10 @@ public function testIsSearchFalse()
*/
public function testIsSearchTrue()
{
$this->Controller->request->params = [
$this->Controller->request = $this->Controller->request->withAttribute('params', [
'controller' => 'Articles',
'action' => 'index',
];
]);
$this->Controller->modelClass = 'SomePlugin.Articles';
$this->Controller->Articles = $this->getMockBuilder(Table::class)->setMethods(['isSearch'])->getMock();
$this->Controller->Articles->addBehavior('Search.Search');
Expand Down
16 changes: 8 additions & 8 deletions tests/TestCase/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ public function testShorthandMethods()
$this->assertInstanceOf('\Search\Model\Filter\Like', $result['like']);
$this->assertInstanceOf('\Search\Model\Filter\Value', $result['value']);

$this->assertEquals('bar', $result['boolean']->config('foo'));
$this->assertEquals('bar', $result['callback']->config('foo'));
$this->assertEquals('bar', $result['compare']->config('foo'));
$this->assertEquals('bar', $result['custom']->config('foo'));
$this->assertEquals('bar', $result['finder']->config('foo'));
$this->assertEquals('bar', $result['like']->config('foo'));
$this->assertEquals('bar', $result['value']->config('foo'));
$this->assertEquals('bar', $result['boolean']->getConfig('foo'));
$this->assertEquals('bar', $result['callback']->getConfig('foo'));
$this->assertEquals('bar', $result['compare']->getConfig('foo'));
$this->assertEquals('bar', $result['custom']->getConfig('foo'));
$this->assertEquals('bar', $result['finder']->getConfig('foo'));
$this->assertEquals('bar', $result['like']->getConfig('foo'));
$this->assertEquals('bar', $result['value']->getConfig('foo'));
}

/**
Expand All @@ -76,7 +76,7 @@ public function testMagicShorthandMethods()
$this->assertCount(2, $result);
$this->assertInstanceOf('\Search\Test\TestApp\Model\Filter\TestFilter', $result['test1']);
$this->assertInstanceOf('\Search\Test\TestApp\Model\Filter\TestFilter', $result['test2']);
$this->assertEquals('bar', $result['test2']->config('foo'));
$this->assertEquals('bar', $result['test2']->getConfig('foo'));
}

/**
Expand Down
Loading

0 comments on commit 482191d

Please sign in to comment.