Skip to content
This repository has been archived by the owner on Oct 25, 2021. It is now read-only.

Commit

Permalink
Added test to confirm issue #2
Browse files Browse the repository at this point in the history
  • Loading branch information
Terr committed Jan 7, 2011
1 parent d936ae0 commit 110d45c
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 1 deletion.
54 changes: 53 additions & 1 deletion tests/cases/models/behaviors/linkable.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,27 @@ class LegacyCompany extends TestModel
);
}

class Shipment extends TestModel
{
public $belongsTo = array(
'OrderItem'
);
}

class OrderItem extends TestModel
{
public $hasMany = array(
'Shipment'
);

public $belongsTo = array(
'ActiveShipment' => array(
'className' => 'Shipment',
'foreignKey' => 'active_shipment_id',
),
);
}

class LinkableTestCase extends CakeTestCase
{
public $fixtures = array(
Expand All @@ -100,7 +121,9 @@ class LinkableTestCase extends CakeTestCase
'plugin.linkable.tag',
'plugin.linkable.user',
'plugin.linkable.legacy_product',
'plugin.linkable.legacy_company'
'plugin.linkable.legacy_company',
'plugin.linkable.shipment',
'plugin.linkable.order_item',
);

public $Post;
Expand Down Expand Up @@ -513,4 +536,33 @@ public function testNonstandardAssociationNames()

$this->assertEqual($arrayExpected, $arrayResult, 'hasMany association with custom foreignKey: %s');
}

public function testAliasedBelongsToWithSameModelAsHasMany()
{
$this->OrderItem =& ClassRegistry::init('OrderItem');

$arrayExpected = array(
0 => array(
'OrderItem' => array(
'id' => 50,
'active_shipment_id' => 320
),
'ActiveShipment' => array(
'id' => 320,
'ship_date' => '2011-01-07',
'order_item_id' => 50
)
)
);

$arrayResult = $this->OrderItem->find('all', array(
'recursive' => -1,
'conditions' => array(
'ActiveShipment.ship_date' => date('2011-01-07'),
),
'link' => array('ActiveShipment'),
));

$this->assertEqual($arrayExpected, $arrayResult, 'belongsTo association with alias (requested), with hasMany to the same model without alias: %s');
}
}
15 changes: 15 additions & 0 deletions tests/fixtures/order_item_fixture.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

class OrderItemFixture extends CakeTestFixture
{
var $name = 'OrderItem';

var $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'active_shipment_id' => array('type' => 'integer'),
);

var $records = array(
array ('id' => 50, 'active_shipment_id' => 320)
);
}
18 changes: 18 additions & 0 deletions tests/fixtures/shipment_fixture.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

class ShipmentFixture extends CakeTestFixture
{
var $name = 'Shipment';

var $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'ship_date' => array('type' => 'date'),
'order_item_id' => array('type' => 'integer')
);

var $records = array(
array ('id' => 320, 'ship_date' => '2011-01-07', 'order_item_id' => 50),
array ('id' => 319, 'ship_date' => '2011-01-07', 'order_item_id' => 50),
array ('id' => 310, 'ship_date' => '2011-01-07', 'order_item_id' => 50)
);
}

0 comments on commit 110d45c

Please sign in to comment.