Created
October 31, 2012 16:53
-
-
Save Kedrigern/3988252 to your computer and use it in GitHub Desktop.
OOP model dodavatele v eshopu
This file contains hidden or 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
| <?php | |
| namespace test; | |
| class objednavkaDopravaInfo | |
| { | |
| public $kg; | |
| public $psc; | |
| public $typ; | |
| public $dostupnost; // dostupnost u nas | |
| public function __construct($kg, $dostupnost, $typ = "normalni") | |
| { | |
| $this->kg = $kg; | |
| $this->dostupnost = $dostupnost; | |
| $this->typ = $typ; | |
| } | |
| } | |
| class info | |
| { | |
| public $name; | |
| public $cena; | |
| public $dobaDodani; | |
| public $adresa; | |
| public $kontakt; | |
| public function __construct($name, $cena, $dobaDodani, $kontakt) | |
| { | |
| $this->name = $name; | |
| $this->cena = $cena; | |
| $this->dobaDodani = $dobaDodani; | |
| $this->kontakt = $kontakt; | |
| } | |
| public function getHtml() | |
| { | |
| return '<div class="span4"> | |
| <h4>' . $this->name . '</h4> | |
| <p>Cena: ' . $this->cena . 'Kč</p> | |
| </div>'; | |
| } | |
| } | |
| abstract class dodavatel | |
| { | |
| public $name; | |
| public $adresa; | |
| public $kontakt; | |
| /** | |
| * @return bool | |
| */ | |
| abstract public function lzePouzit( objednavkaDopravaInfo $info ); | |
| /** | |
| * @return info | |
| */ | |
| abstract public function info( objednavkaDopravaInfo $info ); | |
| } | |
| class osobne extends dodavatel | |
| { | |
| public function __construct() | |
| { | |
| $this->name = "Osovní odběr"; | |
| $this->adresa = "Adrsa k nám..."; | |
| $this->kontakt = "+420 000 000 000"; | |
| } | |
| public function lzePouzit( objednavkaDopravaInfo $info ) | |
| { | |
| return true; | |
| } | |
| public function info( objednavkaDopravaInfo $info ) | |
| { | |
| } | |
| } | |
| class ceska_posta extends dodavatel | |
| { | |
| public function lzePouzit( objednavkaDopravaInfo $info ) | |
| { | |
| if( $info->kg > 20 ) | |
| return false; | |
| if ($info->typ == "nadmerna_velikost" ) | |
| return false; | |
| return true; | |
| } | |
| public function info( objednavkaDopravaInfo $info ) | |
| { | |
| } | |
| } | |
| class toptrans extends dodavatel | |
| { | |
| private $psc_sck_pha = array( "110 00", "120 000" ); | |
| public function lzePouzit( objednavkaDopravaInfo $info ) | |
| { | |
| if ( in_array( $info->psc , $this->psc_sck_pha ) ) | |
| return true; | |
| else | |
| return false; | |
| } | |
| public function info( objednavkaDopravaInfo $info ) | |
| { | |
| } | |
| } |
This file contains hidden or 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
| <?php | |
| require_once("model.php"); | |
| class DodavatelTest extends PHPUnit_Framework_TestCase | |
| { | |
| public $data_z_kosiku; | |
| public $dodavatele; | |
| protected function setUp() | |
| { | |
| $this->data_z_kosiku['1'] = new \test\objednavkaDopravaInfo(10, "normalni"); | |
| $this->data_z_kosiku['2'] = new \test\objednavkaDopravaInfo(21, "nadmerna_velikost"); | |
| $this->data_z_kosiku['3'] = new \test\objednavkaDopravaInfo(21, "normalni"); | |
| $this->dodavatele['osobne'] = new \test\osobne(); | |
| $this->dodavatele['posta'] = new \test\ceska_posta(); | |
| $this->dodavatele['toptrans'] = new \test\toptrans(); | |
| } | |
| public function testDodavatelu() | |
| { | |
| foreach( $this->data_z_kosiku as $item) | |
| { | |
| $this->assertNotNull( $item, ""); | |
| } | |
| foreach( $this->dodavatele as $dodavatel ) | |
| { | |
| $this->assertNotNull( $dodavatel, "" ); | |
| } | |
| // Osobně lze vše | |
| foreach( $this->data_z_kosiku as $item ) | |
| { | |
| $this->assertTrue( $this->dodavatele['osobne']->lzePouzit( $item ) ); | |
| } | |
| // Poštou ne nad 20 | |
| $this->assertTrue( $this->dodavatele['posta']->lzePouzit( $this->data_z_kosiku['1'] ) ); | |
| $this->assertFalse( $this->dodavatele['posta']->lzePouzit( $this->data_z_kosiku['2'] ) ); | |
| $this->assertFalse( $this->dodavatele['posta']->lzePouzit( $this->data_z_kosiku['3'] ) ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment