Skip to content

Commit

Permalink
Merge pull request #129 from ndm2/tests-fixes-and-clean-up
Browse files Browse the repository at this point in the history
Tests, fixes, and clean-up.
  • Loading branch information
ADmad authored Sep 24, 2016
2 parents 34f4332 + 8b478b2 commit b7a9d10
Show file tree
Hide file tree
Showing 17 changed files with 701 additions and 121 deletions.
16 changes: 15 additions & 1 deletion src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function getFilters($collection = 'default')
{
if (!isset($this->_filters[$collection])) {
throw new InvalidArgumentException(
sprintf('The collection "{0}" does not exist.', $collection)
sprintf('The collection "%s" does not exist.', $collection)
);
}

Expand Down Expand Up @@ -137,6 +137,20 @@ public function remove($name)
unset($this->_filters[$this->_collection][$name]);
}

/**
* boolean method
*
* @param string $name Name
* @param array $config Config
* @return $this
*/
public function boolean($name, array $config = [])
{
$this->add($name, 'Search.Boolean', $config);

return $this;
}

/**
* like method
*
Expand Down
12 changes: 12 additions & 0 deletions tests/TestApp/Model/Filter/TestFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
namespace Search\Test\TestApp\Model\Filter;

use Search\Model\Filter\Base;

class TestFilter extends Base
{

public function process()
{
}
}
23 changes: 23 additions & 0 deletions tests/TestApp/Model/Table/ArticlesTable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
namespace Search\Test\TestApp\Model\Table;

use Cake\ORM\Table;
use Search\Manager;

/**
* @mixin \Search\Model\Behavior\SearchBehavior
*/
class ArticlesTable extends Table
{

public function searchConfiguration()
{
$manager = new Manager($this);

return $manager
->value('foo')
->like('search', ['filterEmpty' => true])
->value('baz')
->value('group', ['field' => 'Articles.group']);
}
}
28 changes: 28 additions & 0 deletions tests/TestApp/Model/Table/CommentsTable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
namespace Search\Test\TestApp\Model\Table;

use Cake\ORM\Table;
use Search\Manager;

/**
* @mixin \Search\Model\Behavior\SearchBehavior
*/
class CommentsTable extends Table
{

/**
* @return \Search\Manager
*/
public function searchConfiguration()
{
$manager = new Manager($this);

return $manager
->value('Comments.foo')
->like('Comments.search', ['filterEmpty' => true, 'multiValue' => true])
->value('Comments.baz')
->value('Comments.group', ['field' => 'Comments.group'])
->value('group', ['multiValue' => true])
->value('published');
}
}
25 changes: 25 additions & 0 deletions tests/TestApp/Model/Table/FinderArticlesTable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
namespace Search\Test\TestApp\Model\Table;

use Cake\ORM\Query;
use Cake\ORM\Table;

/**
* @mixin \Search\Model\Behavior\SearchBehavior
*/
class FinderArticlesTable extends Table
{
public function initialize(array $config)
{
parent::initialize($config);

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

public function findActive(Query $query, array $options)
{
return $query->where([
'Articles.is_active' => true
] + $options['active']);
}
}
23 changes: 23 additions & 0 deletions tests/TestApp/Model/Table/GroupsTable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
namespace Search\Test\TestApp\Model\Table;

use Cake\ORM\Table;
use Search\Manager;

/**
* @mixin \Search\Model\Behavior\SearchBehavior
*/
class GroupsTable extends Table
{

public function searchConfiguration()
{
$manager = new Manager($this);

return $manager
->collection('frontend')
->value('title')
->collection('backend')
->like('title', ['before' => true, 'after' => true]);
}
}
64 changes: 64 additions & 0 deletions tests/TestApp/Model/TestRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
namespace Search\Test\TestApp\Model;

use Cake\Datasource\EntityInterface;
use Cake\Datasource\RepositoryInterface;

class TestRepository implements RepositoryInterface
{
public function alias($alias = null)
{
}

public function hasField($field)
{
}

public function find($type = 'all', $options = [])
{
}

public function get($primaryKey, $options = [])
{
}

public function query()
{
}

public function updateAll($fields, $conditions)
{
}

public function deleteAll($conditions)
{
}

public function exists($conditions)
{
}

public function save(EntityInterface $entity, $options = [])
{
}

public function delete(EntityInterface $entity, $options = [])
{
}

public function newEntity($data = null, array $options = [])
{
}

public function newEntities(array $data, array $options = [])
{
}

public function patchEntity(EntityInterface $entity, array $data, array $options = [])
{
}

public function patchEntities($entities, array $data, array $options = [])
{
}
}
27 changes: 25 additions & 2 deletions tests/TestCase/Controller/Component/PrgComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,23 @@

use Cake\Controller\Controller;
use Cake\Network\Request;
use Cake\Routing\RouteBuilder;
use Cake\Routing\Router;
use Cake\TestSuite\TestCase;
use Search\Controller\Component\PrgComponent;

class SearchComponentTest extends TestCase
{
/**
* @var \Cake\Controller\Controller
*/
public $Controller;

/**
* @var \Search\Controller\Component\PrgComponent
*/
public $Prg;

/**
* @return void
*/
Expand All @@ -17,7 +28,7 @@ public function setUp()
parent::setUp();

Router::$initialized = true;
Router::scope('/', function ($routes) {
Router::scope('/', function (RouteBuilder $routes) {
$routes->connect(
'/users/my-predictions',
['controller' => 'UserAnswers', 'action' => 'index', 'type' => 'open'],
Expand All @@ -26,7 +37,10 @@ public function setUp()
$routes->fallbacks();
});
$request = new Request();
$response = $this->getMock('Cake\Network\Response', ['stop']);
$response = $this
->getMockBuilder('Cake\Network\Response')
->setMethods(['stop'])
->getMock();

$this->Controller = new Controller($request, $response);
$this->Prg = new PrgComponent($this->Controller->components());
Expand Down Expand Up @@ -151,4 +165,13 @@ public function testInitializePostWithQueryStringWhitelistEmpty()
$response = $this->Prg->startup();
$this->assertEquals('http://localhost/Posts/index/pass?foo=bar', $response->header()['Location']);
}

/**
* @return void
*/
public function testConversionWithoutRedirect()
{
$this->Controller->request->env('REQUEST_METHOD', 'POST');
$this->assertNull($this->Prg->conversion(false));
}
}
Loading

0 comments on commit b7a9d10

Please sign in to comment.