Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding tests and fixtures, proves problem with COUNT queries for pagi…

…nation
  • Loading branch information...
commit 97764ef805e8098798ebd1e9539ae014eca55762 1 parent ef9ada6
Arjen Terr authored
138 tests/cases/models/behaviors/linkable.test.php
View
@@ -0,0 +1,138 @@
+<?php
+
+App::import('Model', 'Model');
+App::import('Controller', 'Controller');
+
+class TestModel extends CakeTestModel
+{
+ public $actsAs = array(
+ 'Containable',
+ 'Linkable.Linkable'
+ );
+}
+
+class User extends TestModel
+{
+ public $name = 'User';
+ public $useDbConfig = 'test_suite';
+
+ public $hasOne = array(
+ 'Profile'
+ );
+}
+
+class Profile extends TestModel
+{
+ public $name = 'Profile';
+ public $useDbConfig = 'test_suite';
+
+ public $belongsTo = array(
+ 'User'
+ );
+}
+
+class LinkableTestCase extends CakeTestCase
+{
+ public $fixtures = array(
+ 'plugin.linkable.user',
+ 'plugin.linkable.profile'
+ );
+
+ public $Post;
+
+ public function startTest()
+ {
+ $this->User =& ClassRegistry::init('User');
+ }
+
+ public function testLinkable()
+ {
+ $arrayExpected = array(
+ 'User' => array('id' => 1, 'username' => 'CakePHP'),
+ 'Profile' => array ('id' => 1, 'user_id' => 1, 'biography' => 'CakePHP is a rapid development framework for PHP that provides an extensible architecture for developing, maintaining, and deploying applications.')
+ );
+
+ $arrayResult = $this->User->find('first');
+ $this->assertTrue(isset($arrayResult['Profile']), 'Association via Containable: %s');
+ $this->assertEqual($arrayResult, $arrayExpected, 'Association via Containable: %s');
+
+ $arrayResult = $this->User->find('first', array(
+ 'fields' => array(
+ 'id',
+ 'username'
+ ),
+ 'contain' => false,
+ 'link' => array(
+ 'Profile' => array(
+ 'fields' => array(
+ 'id',
+ 'user_id',
+ 'biography'
+ )
+ )
+ )
+ ));
+
+ // Same association, but this time with Linkable
+ $this->assertTrue(isset($arrayResult['Profile']), 'Association via Linkable: %s');
+ $this->assertEqual($arrayResult, $arrayExpected, 'Association via Linkable: %s');
+
+ $arrayResult = $this->User->find('first', array(
+ 'contain' => false,
+ 'link' => array(
+ 'Profile'
+ )
+ ));
+
+ $this->assertTrue(isset($arrayResult['Profile']), 'Association via Linkable (automatic fields): %s');
+ $this->assertEqual($arrayResult, $arrayExpected, 'Association via Linkable (automatic fields): %s');
+
+ // No field list for primary model
+ $arrayExpected = array(
+ 'User' => array('id' => 1, 'username' => 'CakePHP'),
+ 'Profile' => array ('biography' => 'CakePHP is a rapid development framework for PHP that provides an extensible architecture for developing, maintaining, and deploying applications.')
+ );
+
+ $arrayResult = $this->User->find('first', array(
+ 'contain' => false,
+ 'link' => array(
+ 'Profile' => array(
+ 'fields' => array(
+ 'biography'
+ )
+ )
+ )
+ ));
+
+ $this->assertTrue(isset($arrayResult['Profile']), 'Association via Linkable (no primary fields): %s');
+ $this->assertEqual($arrayResult, $arrayExpected, 'Association via Linkable (no primary fields): %s');
+ }
+
+ public function testPagination()
+ {
+ $objController = new Controller();
+ $objController->uses = array('User');
+ $objController->constructClasses();
+ $objController->params['url']['url'] = '/';
+
+ $objController->paginate = array(
+ 'fields' => array(
+ 'username'
+ ),
+ 'contain' => false,
+ 'link' => array(
+ 'Profile' => array(
+ 'fields' => array(
+ 'biography'
+ )
+ )
+ ),
+
+ 'limit' => 2
+ );
+
+ $arrayResult = $objController->paginate('User');
+
+ $this->assertEqual($objController->params['paging']['User']['count'], 4, 'Paging: total records count: %s');
+ }
+}
19 tests/fixtures/profile_fixture.php
View
@@ -0,0 +1,19 @@
+<?php
+
+class ProfileFixture extends CakeTestFixture
+{
+ var $name = 'Profile';
+
+ var $fields = array(
+ 'id' => array('type' => 'integer', 'key' => 'primary'),
+ 'user_id' => array('type' => 'integer'),
+ 'biography' => array('type' => 'string', 'length' => 255, 'null' => false)
+ );
+
+ var $records = array(
+ array ('id' => 1, 'user_id' => 1, 'biography' => 'CakePHP is a rapid development framework for PHP that provides an extensible architecture for developing, maintaining, and deploying applications.'),
+ array ('id' => 2, 'user_id' => 2, 'biography' => ''),
+ array ('id' => 3, 'user_id' => 3, 'biography' => ''),
+ array ('id' => 4, 'user_id' => 4, 'biography' => '')
+ );
+}
18 tests/fixtures/user_fixture.php
View
@@ -0,0 +1,18 @@
+<?php
+
+class UserFixture extends CakeTestFixture
+{
+ var $name = 'User';
+
+ var $fields = array(
+ 'id' => array('type' => 'integer', 'key' => 'primary'),
+ 'username' => array('type' => 'string', 'length' => 255, 'null' => false)
+ );
+
+ var $records = array(
+ array('id' => 1, 'username' => 'CakePHP'),
+ array('id' => 2, 'username' => 'Zend'),
+ array('id' => 3, 'username' => 'Symfony'),
+ array('id' => 4, 'username' => 'CodeIgniter')
+ );
+}
Please sign in to comment.
Something went wrong with that request. Please try again.