-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use single-table inheritance for purchase items.
Make the promotions package compatible with openbuildings/purchases:0.5 Model_Purchase_Item_Promotion is replacing the "promotion" type
- Loading branch information
Showing
12 changed files
with
113 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php defined('SYSPATH') OR die('No direct script access.'); | ||
|
||
/** | ||
* @package openbuildings\promotions | ||
* @author Haralan Dobrev <hkdobrev@gmail.com> | ||
* @copyright 2013 OpenBuildings, Inc. | ||
* @license http://spdx.org/licenses/BSD-3-Clause | ||
*/ | ||
class Kohana_Model_Purchase_Item_Promotion extends Model_Purchase_Item { | ||
|
||
/** | ||
* @codeCoverageIgnore | ||
*/ | ||
public static function initialize(Jam_Meta $meta) | ||
{ | ||
parent::initialize($meta); | ||
|
||
$meta->table('purchase_items'); | ||
} | ||
|
||
public function get_price() | ||
{ | ||
return $this->get_reference_paranoid()->price_for_purchase_item($this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php defined('SYSPATH') OR die('No direct script access.'); | ||
|
||
class Model_Purchase_Item_Promotion extends Kohana_Model_Purchase_Item_Promotion {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
/** | ||
* @group model | ||
* @group model.purchase_item_promotion | ||
*/ | ||
class Model_Purchase_Item_PromotionTest extends Testcase_Promotions { | ||
|
||
/** | ||
* @covers Model_Purchase_Item_Promotion::initialize | ||
*/ | ||
public function test_initialize() | ||
{ | ||
$meta = Jam::meta('purchase_item_promotion'); | ||
$this->assertSame('purchase_items', $meta->table()); | ||
} | ||
|
||
/** | ||
* @covers Model_Purchase_Item_Promotion::get_price | ||
*/ | ||
public function test_get_price() | ||
{ | ||
$mock = $this->getMock('stdClass', array( | ||
'price_for_purchase_item' | ||
)); | ||
|
||
$purchase_item = $this->getMock('Model_Purchase_Item_Promotion', array( | ||
'get_reference_paranoid' | ||
), array( | ||
'purchase_item_promotion' | ||
)); | ||
|
||
$purchase_item | ||
->expects($this->once()) | ||
->method('get_reference_paranoid') | ||
->will($this->returnValue($mock)); | ||
|
||
$mock | ||
->expects($this->once()) | ||
->method('price_for_purchase_item') | ||
->with($purchase_item) | ||
->will($this->returnValue(10.25)); | ||
|
||
$this->assertSame(10.25, $purchase_item->get_price()); | ||
} | ||
} |