--- /dev/null
+<?php
+
+class SugarFicheInstallationTest extends AlloServeurTest {
+
+ const SUGAR_ID = "1111-2222-3333-4444";
+ const MOCK_EXCEPTION = "exception mock";
+
+ /** @var SugarWrapper */
+ private $sugarWrapper;
+
+ /** @var SugarFicheInstallation */
+ private $sugarFicheInstallation;
+
+ /** @var PdoApplianceVersionManager */
+ private $pdoApplianceVersionManager;
+
+ protected function setUp() {
+ parent::setUp();
+ $this->sugarWrapper = $this->getMockBuilder("SugarWrapper")->disableOriginalConstructor()->getMock();
+ $this->sugarWrapper->expects($this->any())->method("setEntry")->willReturn(array('id'=>self::SUGAR_ID));
+ $this->sugarFicheInstallation = new SugarFicheInstallation($this->sugarWrapper);
+ $this->pdoApplianceVersionManager = new PdoApplianceVersionManager();
+ }
+
+ private function getApplianceVersion(){
+ return $this->pdoApplianceVersionManager->get(1);
+ }
+
+ public function testCreate(){
+ $this->assertEquals(self::SUGAR_ID,$this->sugarFicheInstallation->edit($this->getApplianceVersion()));
+ $this->assertEquals(self::SUGAR_ID,$this->getApplianceVersion()->sugar_id);
+ }
+
+ public function testUpdate(){
+ /** @var PHPUnit_Framework_MockObject_MockObject $sugar_wrapper */
+ $sugar_wrapper = $this->sugarWrapper;
+ $sugar_wrapper->expects($this->any())->method("entryExists")->willReturn(true);
+ $this->assertEquals(self::SUGAR_ID,$this->sugarFicheInstallation->edit($this->getApplianceVersion()));
+ $this->assertEquals(self::SUGAR_ID,$this->getApplianceVersion()->sugar_id);
+ }
+
+ public function testCreateNoSugarId(){
+ $this->assertEquals(self::SUGAR_ID,$this->sugarFicheInstallation->edit($this->pdoApplianceVersionManager->get(2)));
+ $this->assertEquals(self::SUGAR_ID,$this->getApplianceVersion()->sugar_id);
+ }
+
+ public function testSugarFailed(){
+ $sugarWrapper = $this->getMockBuilder("SugarWrapper")->disableOriginalConstructor()->getMock();
+ $sugarWrapper->expects($this->any())->method("setEntry")->willReturn(false);
+ /** @var SugarWrapper $sugarWrapper*/
+ $sugarFicheInstallation = new SugarFicheInstallation($sugarWrapper);
+ $this->setExpectedException("Exception","Impossible d'éditer la fiche Sugar");
+ $sugarFicheInstallation->edit($this->getApplianceVersion());
+ }
+
+ public function testSugarUpdateFailed(){
+ $sugarWrapper = $this->getMockBuilder("SugarWrapper")->disableOriginalConstructor()->getMock();
+ $sugarWrapper->expects($this->any())->method("setEntry")->willReturn(false);
+ $sugarWrapper->expects($this->any())->method("entryExists")->willReturn(true);
+
+ /** @var SugarWrapper $sugarWrapper*/
+ $sugarFicheInstallation = new SugarFicheInstallation($sugarWrapper);
+ $this->setExpectedException("Exception","Impossible d'éditer la fiche Sugar");
+ $sugarFicheInstallation->edit($this->getApplianceVersion());
+ }
+}
\ No newline at end of file