--- /dev/null
+<?php
+
+class SugarCustomerTest extends AlloServeurTest {
+
+ const SUGAR_ID = "cust_omert_test_1111";
+ const OFFICE_NUMBER_C = "baz";
+ const USER_SUGAR_ID = "user_1111_2222_3333";
+ const USER_EMAIL = "test@libriciel.fr";
+
+ /** @var SugarWrapper */
+ private $sugarWrapper;
+
+ /** @var SugarCustomer */
+ private $sugarCustomer;
+
+
+ protected function setUp() {
+ parent::setUp();
+ $this->sugarWrapper = $this->getMockBuilder("SugarWrapper")->disableOriginalConstructor()->getMock();
+ $entry_list = array(
+ self::SUGAR_ID => array(
+ 'name' => 'bar',
+ 'assigned_user_id' => self::USER_SUGAR_ID,
+ 'officenumber_c' => self::OFFICE_NUMBER_C,
+ )
+ );
+
+ $this->sugarWrapper->expects($this->any())->method("simpleRetrieve")->willReturn($entry_list);
+ $this->sugarCustomer = new SugarCustomer($this->sugarWrapper);
+ }
+
+ private function setAssignedUserEmail(){
+ $assigned_user_entry_result = array(
+ self::USER_SUGAR_ID => array('email1'=>self::USER_EMAIL)
+ );
+ /** @var PHPUnit_Framework_MockObject_MockObject $sugarWrapper */
+ $sugarWrapper = $this->sugarWrapper;
+ $sugarWrapper->expects($this->any())->method("getEntries")->willReturn($assigned_user_entry_result);
+ }
+
+ private function getCustomer(){
+ $pdoCustomerManager = new PdoCustomerManager();
+ return $pdoCustomerManager->getBySugarId(self::SUGAR_ID);
+ }
+
+ public function testSynchronize(){
+ $this->sugarCustomer->synchronize();
+ $this->assertEquals(self::OFFICE_NUMBER_C,$this->getCustomer()->ap_id);
+ }
+
+ public function testSynchronizeWithEmail(){
+ $this->setAssignedUserEmail();
+ $this->sugarCustomer->synchronize();
+ $this->assertEquals(self::USER_EMAIL,$this->getCustomer()->ap_contact);
+ }
+}
\ No newline at end of file