Permalink
Browse files

Test Case to cover support for hasMany associations

  • Loading branch information...
1 parent 1f1545c commit df3d40bbdd1f9b706acc79d0eb270bae78b17ae2 @houseoftech houseoftech committed Oct 17, 2012
Showing with 47 additions and 1 deletion.
  1. +26 −1 Test/Case/Model/Behavior/CsvImportTest.php
  2. +18 −0 Test/Fixture/CommentFixture.php
  3. +3 −0 Test/Tmp/test2.csv
View
@@ -37,7 +37,7 @@ class CsvImportTest extends CakeTestCase {
* @var array
* @access public
*/
- public $fixtures = array('plugin.utils.content');
+ public $fixtures = array('plugin.utils.content', 'plugin.utils.comment');
/**
* Creates the model instance
@@ -97,6 +97,31 @@ public function testImportCSV() {
}
/**
+ * testImportCSVWithHasMany
+ *
+ * @access public
+ * @return void
+ */
+ public function testImportCSVWithHasMany() {
+ $this->Content->bindModel(array(
+ 'hasMany' => array(
+ 'Comment'
+ )
+ ), false);
+ $this->Content->Behaviors->load('Utils.CsvImport');
+ $path = App::pluginPath('Utils');
+ $result = $this->Content->importCSV($path . 'Test' . DS . 'tmp' . DS . 'test2.csv');
+ $this->assertTrue($result);
+
+ $records = $this->Content->find('all', array('order' => 'created DESC', 'limit' => 2));
+ $titles = Set::extract('/Comment/body', $records);
+ $this->assertEqual($titles, array('really? how strange?', 'very good read'));
+
+ $permalinks = Set::extract('/Content/permalink', $records);
+ $this->assertEqual($permalinks, array(13444555, 'A permalink'));
+ }
+
+/**
* testImportCSVWithCallback
*
* @access public
@@ -0,0 +1,18 @@
+<?php
+// For the inheritable behavior
+class CommentFixture extends CakeTestFixture {
+ var $name = 'Comment';
+
+ var $fields = array(
+ 'id' => array('type' => 'integer', 'key' => 'primary'),
+ 'content_id' => array('type' => 'integer', 'null' => false),
+ 'body' => 'text',
+ 'published' => array('type' => 'string', 'length' => 1, 'default' => 'N'),
+ 'permalink' => array('type' => 'string'),
+ 'parent_id' => array('type' => 'integer'),
+ 'created' => 'datetime',
+ 'updated' => 'datetime'
+ );
+
+}
+?>
View
@@ -0,0 +1,3 @@
+user_id;title;body;type;permalink;Comment.0.body
+1;"Unearthed rare monster in london";"very strange discovery...";Article;13444555;"really? how strange?"
+1;"Another Title";"This is a body";Book;"A permalink";"very good read"

0 comments on commit df3d40b

Please sign in to comment.