| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- App::uses('CustomFindsBehavior', 'Tools.Model/Behavior');
- App::uses('AppModel', 'Model');
- App::uses('MyCakeTestCase', 'Tools.TestSuite');
- class Test extends AppModel {
- public $useTable = false;
- public $actsAs = array('Tools.CustomFinds');
- }
- class CustomFindsBehaviorTest extends MyCakeTestCase {
- public function setUp() {
- $this->CustomFinds = new CustomFindsBehavior();
- $this->Model = new Test();
- $this->Model->customFinds = array(
- 'topSellers' => array(
- 'fields' => array('Product.name','Product.price'),
- 'contain' => array('ProductImage.source'),
- 'conditions' => array('Product.countSeller >' => 20, 'Product.is_active' => 1),
- 'recursive' => 1,
- //All other find options
- )
- );
- }
- public function tearDown() {
- }
- public function testObject() {
- $this->assertTrue(is_a($this->CustomFinds, 'CustomFindsBehavior'));
- }
- public function testModify() {
- $query = array(
- 'custom' => 'topSellers',
- 'recursive' => 0,
- 'conditions' => array('Product.count >'=>0),
- );
- $res = $this->Model->Behaviors->CustomFinds->beforeFind($this->Model, $query);
- pr($res);
- $queryResult = $this->Model->customFinds['topSellers'];
- $queryResult['recursive'] = 0;
- $queryResult['conditions']['Product.count >'] = 0;
- $this->assertTrue(!empty($res));
- $this->assertSame($queryResult['recursive'], $res['recursive']);
- $this->assertSame($queryResult['conditions'], $res['conditions']);
- }
- public function testModifyWithRemove() {
- $query = array(
- 'custom' => 'topSellers',
- 'conditions' => array('Product.count >'=>0),
- 'remove' => array('conditions')
- );
- $res = $this->Model->Behaviors->CustomFinds->beforeFind($this->Model, $query);
- pr($res);
- $queryResult = $this->Model->customFinds['topSellers'];
- $queryResult['conditions'] = array('Product.count >'=>0);
- $this->assertTrue(!empty($res));
- $this->assertSame($queryResult['recursive'], $res['recursive']);
- $this->assertSame($queryResult['conditions'], $res['conditions']);
- $query = array(
- 'custom' => 'topSellers',
- 'conditions' => array('Product.count >'=>0),
- 'remove' => array('conditions'=>array('Product.countSeller >'))
- );
- $res = $this->Model->Behaviors->CustomFinds->beforeFind($this->Model, $query);
- pr($res);
- $queryResult = $this->Model->customFinds['topSellers'];
- unset($queryResult['conditions']['Product.countSeller >']);
- $queryResult['conditions']['Product.count >'] = 0;
- $this->assertTrue(!empty($res));
- $this->assertSame($queryResult['conditions'], $res['conditions']);
- }
- }
|