Skip to content

Commit

Permalink
Merge branch 'lecterror:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
gregor-j authored May 18, 2022
2 parents 5debf51 + 23fd64b commit b7593d6
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 111 deletions.
12 changes: 9 additions & 3 deletions Test/Case/Controller/Component/FilterComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@

App::uses('Router', 'Routing');
App::uses('Component', 'Filter.Filter');
require_once(dirname(dirname(dirname(__FILE__))) . DS . 'MockObjects.php');

class FilterTestCase extends CakeTestCase
App::uses('Document', 'Filter.Test/Case/MockObjects');
App::uses('Document2', 'Filter.Test/Case/MockObjects');
App::uses('Document3', 'Filter.Test/Case/MockObjects');
App::uses('DocumentCategory', 'Filter.Test/Case/MockObjects');
App::uses('DocumentTestsController', 'Filter.Test/Case/MockObjects');
App::uses('Item', 'Filter.Test/Case/MockObjects');
App::uses('Metadata', 'Filter.Test/Case/MockObjects');

class FilterComponentTest extends CakeTestCase
{
public $fixtures = array
(
Expand Down
104 changes: 0 additions & 104 deletions Test/Case/MockObjects.php

This file was deleted.

9 changes: 9 additions & 0 deletions Test/Case/MockObjects/Document.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

class Document extends CakeTestModel
{
public $name = 'Document';
public $belongsTo = array('DocumentCategory');
public $hasMany = array('Item');
public $hasOne = array('Metadata');
}
16 changes: 16 additions & 0 deletions Test/Case/MockObjects/Document2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

class Document2 extends CakeTestModel
{
public $name = 'Document';
public $alias = 'Document';
public $belongsTo = array('DocumentCategory');
public $hasMany = array('Item');

public $returnValue = false;

public function beforeDataFilter($query, $options)
{
return $this->returnValue;
}
}
26 changes: 26 additions & 0 deletions Test/Case/MockObjects/Document3.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

class Document3 extends CakeTestModel
{
public $name = 'Document';
public $alias = 'Document';
public $belongsTo = array('DocumentCategory');
public $hasMany = array('Item');

public $itemToUnset = null;

public function afterDataFilter($query, $options)
{
if (!is_string($this->itemToUnset))
{
return $query;
}

if (isset($query['conditions'][$this->itemToUnset]))
{
unset($query['conditions'][$this->itemToUnset]);
}

return $query;
}
}
15 changes: 15 additions & 0 deletions Test/Case/MockObjects/DocumentCategory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

class DocumentCategory extends CakeTestModel
{
public $name = 'DocumentCategory';
public $hasMany = array('Document');

public function customSelector($options = array())
{
$options['conditions']['DocumentCategory.title LIKE'] = '%T%';
$options['nofilter'] = true;

return $this->find('list', $options);
}
}
18 changes: 18 additions & 0 deletions Test/Case/MockObjects/DocumentTestsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

App::uses('Controller', 'Controller');

class DocumentTestsController extends Controller
{
public $name = 'DocumentTests';

public function index()
{
}

// must override this or the tests never complete..
// @TODO: mock partial?
public function redirect($url, $status = null, $exit = true)
{
}
}
7 changes: 7 additions & 0 deletions Test/Case/MockObjects/Item.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

class Item extends CakeTestModel
{
public $name = 'Item';
public $belongsTo = array('Document');
}
7 changes: 7 additions & 0 deletions Test/Case/MockObjects/Metadata.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

class Metadata extends CakeTestModel
{
public $name = 'Metadata';
public $hasOne = array('Document');
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@
*/

App::import('Core', array('AppModel', 'Model'));
require_once(dirname(dirname(dirname(__FILE__))) . DS . 'MockObjects.php');


class FilteredTestCase extends CakeTestCase
App::uses('Document', 'Filter.Test/Case/MockObjects');
App::uses('Document2', 'Filter.Test/Case/MockObjects');
App::uses('Document3', 'Filter.Test/Case/MockObjects');
App::uses('DocumentCategory', 'Filter.Test/Case/MockObjects');
App::uses('DocumentTestsController', 'Filter.Test/Case/MockObjects');
App::uses('Item', 'Filter.Test/Case/MockObjects');
App::uses('Metadata', 'Filter.Test/Case/MockObjects');

class FilteredBehaviorTest extends CakeTestCase
{
public $fixtures = array
(
Expand Down

0 comments on commit b7593d6

Please sign in to comment.