|
|
@@ -212,6 +212,50 @@ class NamedScopeBehaviorTest extends MyCakeTestCase {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * NamedScopeBehaviorTest::testScopedFindOverwrite()
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testScopedFindOverwrite() {
|
|
|
+ $this->Comment->scopes = array('active' => array('Comment.published' => 'Y'));
|
|
|
+
|
|
|
+ $this->Comment->Behaviors->load('Tools.NamedScope');
|
|
|
+ $this->Comment->User->Behaviors->load('Tools.NamedScope');
|
|
|
+ $this->Comment->scopedFinds = array(
|
|
|
+ 'active' => array(
|
|
|
+ 'name' => 'Active Comentators',
|
|
|
+ 'find' => array(
|
|
|
+ 'type' => 'all',
|
|
|
+ 'virtualFields' => array(
|
|
|
+ 'fullname' => "CONCAT(User.id, '-', User.user)"
|
|
|
+ ),
|
|
|
+ 'options' => array(
|
|
|
+ 'scope' => array('Comment.active'),
|
|
|
+ 'contain' => array('User'),
|
|
|
+ 'fields' => array('User.id', 'fullname'),
|
|
|
+ 'order' => array('fullname' => 'ASC'),
|
|
|
+ 'limit' => 5
|
|
|
+ )
|
|
|
+ )
|
|
|
+ )
|
|
|
+ );
|
|
|
+ $result = $this->Comment->scopedFind('active', array('options' => array('limit' => 2)));
|
|
|
+ $this->assertSame(2, count($result));
|
|
|
+
|
|
|
+ $result = $this->Comment->scopedFind('active', array('type' => 'count'));
|
|
|
+ $this->assertSame(5, $result);
|
|
|
+
|
|
|
+ $result = $this->Comment->scopedFind('active', array('type' => 'first', 'options' => array('fields' => array('User.id', 'User.created'), 'order' => array('User.id' => 'DESC'))));
|
|
|
+ $expected = array(
|
|
|
+ 'User' => array(
|
|
|
+ 'id' => 4,
|
|
|
+ 'created' => '2007-03-17 01:22:23'
|
|
|
+ )
|
|
|
+ );
|
|
|
+ $this->assertEquals($expected, $result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* NamedScopeBehaviorTest::testException()
|
|
|
*
|
|
|
* @expectedException RuntimeException
|