Browse Source

Applying patch from @tigrang for ensuring keys from all eagerly loaded
assocs

Jose Lorenzo Rodriguez 12 years ago
parent
commit
258b20187b

+ 7 - 4
tests/TestCase/ORM/CompositeKeysTest.php

@@ -108,7 +108,8 @@ class CompositeKeyTest extends TestCase {
 			[
 				'id' => 2,
 				'name' => 'juan',
-				'site_id' => 2
+				'site_id' => 2,
+				'articles' => [],
 			],
 			[
 				'id' => 3,
@@ -127,7 +128,8 @@ class CompositeKeyTest extends TestCase {
 			[
 				'id' => 4,
 				'name' => 'andy',
-				'site_id' => 1
+				'site_id' => 1,
+				'articles' => [],
 			]
 		];
 		$this->assertEquals($expected, $results);
@@ -137,7 +139,7 @@ class CompositeKeyTest extends TestCase {
 			->contain(['SiteArticles' => ['conditions' => ['id' => 2]]])
 			->hydrate(false)
 			->toArray();
-		unset($expected[0]['articles']);
+		$expected[0]['articles'] = [];
 		$this->assertEquals($expected, $results);
 		$this->assertEquals($table->association('SiteArticles')->strategy(), $strategy);
 	}
@@ -206,7 +208,8 @@ class CompositeKeyTest extends TestCase {
 				'title' => 'Third Article',
 				'body' => 'Third Article Body',
 				'author_id' => 1,
-				'site_id' => 2
+				'site_id' => 2,
+				'tags' => [],
 			],
 			[
 				'id' => 4,

+ 14 - 4
tests/TestCase/ORM/QueryTest.php

@@ -220,6 +220,7 @@ class QueryTest extends TestCase {
 			[
 				'id' => 2,
 				'name' => 'nate',
+				'articles' => [],
 			],
 			[
 				'id' => 3,
@@ -237,6 +238,7 @@ class QueryTest extends TestCase {
 			[
 				'id' => 4,
 				'name' => 'garrett',
+				'articles' => [],
 			]
 		];
 		$this->assertEquals($expected, $results);
@@ -246,7 +248,7 @@ class QueryTest extends TestCase {
 			->contain(['articles' => ['conditions' => ['id' => 2]]])
 			->hydrate(false)
 			->toArray();
-		unset($expected[0]['articles']);
+		$expected[0]['articles'] = [];
 		$this->assertEquals($expected, $results);
 		$this->assertEquals($table->association('articles')->strategy(), $strategy);
 	}
@@ -315,6 +317,7 @@ class QueryTest extends TestCase {
 			[
 				'id' => 2,
 				'name' => 'nate',
+				'articles' => [],
 			],
 			[
 				'id' => 3,
@@ -326,6 +329,7 @@ class QueryTest extends TestCase {
 			[
 				'id' => 4,
 				'name' => 'garrett',
+				'articles' => [],
 			],
 		];
 		$this->assertEquals($expected, $results);
@@ -377,7 +381,8 @@ class QueryTest extends TestCase {
 			],
 			[
 				'id' => 2,
-				'name' => 'nate'
+				'name' => 'nate',
+				'articles' => [],
 			],
 			[
 				'id' => 3,
@@ -395,7 +400,8 @@ class QueryTest extends TestCase {
 			],
 			[
 				'id' => 4,
-				'name' => 'garrett'
+				'name' => 'garrett',
+				'articles' => [],
 			]
 		];
 		$this->assertEquals($expected, $results);
@@ -565,6 +571,7 @@ class QueryTest extends TestCase {
 				'body' => 'Third Article Body',
 				'author_id' => 1,
 				'published' => 'Y',
+				'tags' => [],
 			],
 		];
 		$this->assertEquals($expected, $results);
@@ -580,6 +587,7 @@ class QueryTest extends TestCase {
 				'title' => 'First Article',
 				'body' => 'First Article Body',
 				'published' => 'Y',
+				'tags' => [],
 			],
 			[
 				'id' => 2,
@@ -601,6 +609,7 @@ class QueryTest extends TestCase {
 				'body' => 'Third Article Body',
 				'author_id' => 1,
 				'published' => 'Y',
+				'tags' => [],
 			],
 		];
 		$this->assertEquals($expected, $results);
@@ -1199,7 +1208,7 @@ class QueryTest extends TestCase {
 		$this->assertInstanceOf('\Cake\ORM\Entity', $first->articles[0]->author);
 		$expected = ['id' => 1, 'name' => 'mariano'];
 		$this->assertEquals($expected, $first->articles[0]->author->toArray());
-		$this->assertFalse(isset($results[3]->articles));
+		$this->assertTrue(isset($results[3]->articles));
 	}
 
 /**
@@ -1756,6 +1765,7 @@ class QueryTest extends TestCase {
 				}
 			}
 		});
+
 		$expected = ['tag1 - visited', 'tag2 - visited', 'tag1 - visited', 'tag3 - visited'];
 		$this->assertEquals($expected, $query->toArray());
 	}

+ 3 - 3
tests/TestCase/ORM/TableTest.php

@@ -2926,7 +2926,7 @@ class TableTest extends \Cake\TestSuite\TestCase {
 
 		$table->association('tags')->unlink($article, $tags);
 		$left = $table->find('all')->where(['id' => 1])->contain(['tags'])->first();
-		$this->assertNull($left->tags);
+		$this->assertEmpty($left->tags);
 	}
 
 /**
@@ -2952,7 +2952,7 @@ class TableTest extends \Cake\TestSuite\TestCase {
 
 		$table->association('tags')->unlink($article, $tags);
 		$left = $table->find('all')->where(['id' => 1])->contain(['tags'])->first();
-		$this->assertNull($left->tags);
+		$this->assertEmpty($left->tags);
 	}
 
 /**
@@ -3001,7 +3001,7 @@ class TableTest extends \Cake\TestSuite\TestCase {
 		$table->association('tags')->replaceLinks($article, $tags);
 		$this->assertSame($tags, $article->tags);
 		$article = $table->find('all')->where(['id' => 1])->contain(['tags'])->first();
-		$this->assertNull($article->tags);
+		$this->assertEmpty($article->tags);
 	}
 
 /**