--- /dev/null
+<?php
+
+class PdoApplianceManagerTest extends AlloServeurTest {
+
+ const FQDN_INTERNE = 'allo-interne.libriciel.fr';
+ const UUID = 'XYT';
+
+ /** @var PdoApplianceManager */
+ private $pdoApplianceManager;
+
+ protected function setUp(){
+ parent::setUp();
+ $this->pdoApplianceManager = new PdoApplianceManager();
+ }
+
+ private function getApplianceInfo(){
+ return array(
+ 'produit'=>'FOO',
+ 'version'=>42,
+ 'reference'=>'CDG85/TOTO',
+ 'fqdn_interne'=>self::FQDN_INTERNE,
+ 'fqdn_externe'=>'allo.libriciel.fr',
+ 'systeme' => 'Ubuntu 14.04',
+ 'disques' => 'non',
+ 'canal'=>'QUALIF',
+ 'usager_type' => "client",
+ 'uuid' => self::UUID,
+ );
+ }
+
+ private function createProduct($name = "FOO",$diminutif="BAR"){
+ $pdoProductManager = new PdoProductManager();
+ $product = new Product();
+ $product->name = $name;
+ $product->diminutif = $diminutif;
+ return $pdoProductManager->createProduct($product);
+ }
+
+ private function createVersion($name = "FOO",$version_number="42"){
+ $product_id = $this->createProduct($name);
+ $pdoVersionManager = new PdoVersionManager();
+ $version = new Version();
+ $version->product = $product_id;
+ $version->value = $version_number;
+ return $pdoVersionManager->createVersion($version);
+ }
+
+ public function testCheckUploadInfoValidityNoProduct(){
+ $this->setExpectedException("Exception","La clé produit n'a pas été trouvée dans les informations fournies.");
+ $this->pdoApplianceManager->checkUploadInfoValidity(array());
+ }
+
+ public function testCheckUploadBadProduct(){
+ $this->setExpectedException("Exception","Le produit « FOO » n'est pas valide.");
+ $this->pdoApplianceManager->checkUploadInfoValidity($this->getApplianceInfo());
+ }
+
+ public function testCheckBadVersion(){
+ $this->createProduct();
+ $this->setExpectedException("Exception","La version « 42 » n'est pas disponible pour le produit « FOO ».");
+ $this->pdoApplianceManager->checkUploadInfoValidity($this->getApplianceInfo());
+ }
+
+ public function testCheckUploadOK(){
+ $this->createVersion();
+ $this->assertTrue($this->pdoApplianceManager->checkUploadInfoValidity($this->getApplianceInfo()));
+ }
+
+
+ public function testGetAppliances(){
+ $result = $this->pdoApplianceManager->getAppliances();
+ $this->assertEquals("pastell.baucaire.org",$result[0]->external_fqdn);
+ }
+
+ public function testRemoveAppliances(){
+ $appliance = $this->pdoApplianceManager->getAppliance(1);
+ $this->pdoApplianceManager->removeAppliance($appliance);
+ $result = $this->pdoApplianceManager->getAppliances();
+ $this->assertEmpty($result);
+ }
+
+ public function testGetNbAppliances(){
+ $this->assertEquals(1,$this->pdoApplianceManager->getNbAppliances());
+ }
+
+ public function testEditAppliance(){
+ $appliance = new Appliance();
+ $appliance->importFromArray($this->getApplianceInfo());
+ $appliance_id = $this->pdoApplianceManager->editAppliance($appliance);
+ $appliance = $this->pdoApplianceManager->getAppliance($appliance_id);
+ $this->assertEquals(self::UUID,$appliance->uuid);
+ }
+
+ public function testGetApplianceForOutput(){
+ $this->assertEquals(1,count($this->pdoApplianceManager->getApplianceForOutput(0,10)));
+ }
+
+ public function testGetInfoByUUID(){
+ $this->assertEmpty($this->pdoApplianceManager->getInfoByUUID("42"));
+ }
+
+ public function testGetNextPatchByUUID(){
+ $this->assertEmpty($this->pdoApplianceManager->getNextPatchByUUID("42"));
+ }
+
+ public function testGetInfoByCustomerId(){
+ $this->assertEmpty($this->pdoApplianceManager->getInfoByCustomerId("42"));
+ }
+
+ public function testGetInfo(){
+ $this->assertEmpty($this->pdoApplianceManager->getInfo("42"));
+ }
+
+ public function testGetHistorique(){
+ $this->assertEmpty($this->pdoApplianceManager->getHistorique("42"));
+ }
+
+ public function testlistAValider(){
+ $this->assertEmpty($this->pdoApplianceManager->listAValider(0,10));
+ }
+
+ public function testSetValider(){
+ $this->pdoApplianceManager->setValider(1,1);
+ }
+
+ public function testDelete(){
+ $this->pdoApplianceManager->delete(1);
+ }
+ public function testNbValider(){
+ $this->assertEmpty($this->pdoApplianceManager->nbAValider());
+ }
+
+ public function testGetByUUIDFalse(){
+ $this->assertFalse($this->pdoApplianceManager->getByUUID(self::UUID));
+ }
+
+}
\ No newline at end of file