Skip to content

Commit

Permalink
Added test for path amterialization in the eager loader
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Feb 9, 2014
1 parent 4840c96 commit 150880f
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/TestCase/ORM/EagerLoaderTest.php
Expand Up @@ -327,6 +327,50 @@ public function testContainToFieldsDefault() {
$this->assertEquals($expected, $select);
}

/**
* Tests that the path for gettings to a deep assocition is materialized in an
* array key
*
* @return void
*/
public function testNormalizedPath() {
$contains = [
'clients' => [
'orders' => [
'orderTypes',
'stuff' => ['stuffTypes']
],
'companies' => [
'categories'
]
]
];

$query = $this->getMock(
'\Cake\ORM\Query',
['join'],
[$this->connection, $this->table]
);

$loader = new EagerLoader;
$loader->contain($contains);
$normalized = $loader->normalized($this->table);
$this->assertEquals('clients', $normalized['clients']['path']);

$assocs = $normalized['clients']['associations'];
$this->assertEquals('clients.orders', $assocs['orders']['path']);

$assocs = $assocs['orders']['associations'];
$this->assertEquals('clients.orders.orderTypes', $assocs['orderTypes']['path']);
$this->assertEquals('clients.orders.stuff', $assocs['stuff']['path']);

$assocs = $assocs['stuff']['associations'];
$this->assertEquals(
'clients.orders.stuff.stuffTypes',
$assocs['stuffTypes']['path']
);
}

/**
* Helper function sued to quoted both keys and values in an array in case
* the test suite is running with auto quoting enabled
Expand Down

0 comments on commit 150880f

Please sign in to comment.