public function testLifecycleSupplier()
 {
     $retVal = $this->_createSupplier();
     $this->assertEquals(4294967, $retVal["number"]);
     $this->assertEquals("Worldwide Electronics International", $retVal["name"]);
     $this->assertEquals("http://wwei.cn", $retVal["url"]);
     $this->assertEquals(NULL, $retVal['description']);
     $this->assertEquals('Yiting', $retVal['cpextern_id']['n_given']);
     $this->assertEquals('Huang', $retVal['cpextern_id']['n_family']);
     $this->assertEquals('Hans Friedrich', $retVal['cpintern_id']['n_given']);
     $this->assertEquals('Ochs', $retVal['cpintern_id']['n_family']);
     // delete record (set deleted=1) of customer and assigned addresses
     $this->_json->deleteSuppliers(array($retVal['id']));
     $customerBackend = new Sales_Backend_Supplier();
     $deletedSupplier = $customerBackend->get($retVal['id'], TRUE);
     $this->assertEquals(1, $deletedSupplier->is_deleted);
     $addressBackend = new Sales_Backend_Address();
     $deletedAddresses = $addressBackend->getMultipleByProperty($retVal['id'], 'customer_id', TRUE);
     $this->assertEquals(1, $deletedAddresses->count());
     foreach ($deletedAddresses as $address) {
         $this->assertEquals(1, $address->is_deleted);
     }
     $this->setExpectedException('Tinebase_Exception_NotFound');
     return $this->_json->getSupplier($retVal['id']);
 }
 /**
  * resolve address records before setting headers, so we know how much addresses exist
  *
  * @param Sales_Model_CustomerFilter $filter
  * @param Sales_Controller_Customer $controller
  */
 protected function _resolveAddresses($filter, $controller)
 {
     $customers = $controller->search($filter);
     $customerIds = $customers->id;
     $contactIds = array_unique(array_merge($customers->cpextern_id, $customers->cpintern_id));
     unset($customers);
     $be = new Sales_Backend_Address();
     $this->_specialFieldDefinitions = array(array('header' => 'Postal Address', 'identifier' => 'postal_address', 'type' => 'postal'));
     foreach (array('billing', 'delivery') as $type) {
         $maxAddresses = $be->getMaxAddressesByType($customerIds, $type);
         $header = $type == 'billing' ? 'Billing Address' : 'Delivery Address';
         if ($maxAddresses > 0) {
             $i = 0;
             while ($i < $maxAddresses) {
                 $this->_specialFieldDefinitions[] = array('header' => $header, 'identifier' => $type . '_address' . ($i > 0 ? $i + 1 : ''), 'type' => $type, 'index' => $i + 1);
                 $i++;
             }
         }
     }
     $filter = new Sales_Model_AddressFilter(array());
     $filter->addFilter(new Tinebase_Model_Filter_Text(array('field' => 'customer_id', 'operator' => 'in', 'value' => $customerIds)));
     $this->_addresses = $be->search($filter);
     $this->_contacts = Addressbook_Controller_Contact::getInstance()->getMultiple($contactIds);
 }
 public function testLifecycleCustomer()
 {
     $retVal = $this->_createCustomer();
     $this->assertEquals(4294967, $retVal["number"]);
     $this->assertEquals("Worldwide Electronics International", $retVal["name"]);
     $this->assertEquals("http://wwei.cn", $retVal["url"]);
     $this->assertEquals(NULL, $retVal['description']);
     $this->assertEquals('Yiting', $retVal['cpextern_id']['n_given']);
     $this->assertEquals('Huang', $retVal['cpextern_id']['n_family']);
     $this->assertEquals('Hans Friedrich', $retVal['cpintern_id']['n_given']);
     $this->assertEquals('Ochs', $retVal['cpintern_id']['n_family']);
     // @see: 0009378: create a test for resolving dependent records recursively
     $this->assertEquals('Sales_Model_Contract', $retVal['billing'][0]['relations'][0]['related_model']);
     $this->assertEquals('Testing', $retVal['billing'][0]['relations'][0]['related_record']['title']);
     $this->assertArrayHasKey('fulltext', $retVal['billing'][0]);
     // @see: 0009378: create a test for resolving dependent records recursively
     $this->assertEquals('Sales_Model_Contract', $retVal['billing'][0]['relations'][0]['related_model']);
     $this->assertEquals('Testing', $retVal['billing'][0]['relations'][0]['related_record']['title']);
     // test billing and delivery addresses get resolved
     $this->assertTrue(is_array($retVal['delivery']));
     $this->assertEquals(1, count($retVal['delivery']));
     $this->assertEquals('Peking', $retVal['delivery'][0]['locality']);
     $this->assertEquals('China', $retVal['delivery'][0]['countryname']);
     $this->assertTrue(is_array($retVal['billing']));
     $this->assertEquals(1, count($retVal['billing']));
     $this->assertEquals('Shenzen', $retVal['billing'][0]['locality']);
     $this->assertEquals('China', $retVal['billing'][0]['countryname']);
     // delete record (set deleted=1) of customer and assigned addresses
     $this->_json->deleteCustomers(array($retVal['id']));
     $customerBackend = new Sales_Backend_Customer();
     $deletedCustomer = $customerBackend->get($retVal['id'], TRUE);
     $this->assertEquals(1, $deletedCustomer->is_deleted);
     $addressBackend = new Sales_Backend_Address();
     $deletedAddresses = $addressBackend->getMultipleByProperty($retVal['id'], 'customer_id', TRUE);
     $this->assertEquals(3, $deletedAddresses->count());
     foreach ($deletedAddresses as $address) {
         $this->assertEquals(1, $address->is_deleted);
     }
     $this->setExpectedException('Tinebase_Exception_NotFound');
     return $this->_json->getCustomer($retVal['id']);
 }
 /**
  * resolve address records before setting headers, so we know how much addresses exist
  *
  * @param Sales_Model_SupplierFilter $filter
  * @param Sales_Controller_Supplier $controller
  */
 protected function _resolveAddresses($filter, $controller)
 {
     $suppliers = $controller->search($filter);
     $supplierIds = $suppliers->id;
     $contactIds = array_unique(array_merge($suppliers->cpextern_id, $suppliers->cpintern_id));
     unset($suppliers);
     $be = new Sales_Backend_Address();
     $this->_specialFieldDefinitions = array(array('header' => 'Postal Address', 'identifier' => 'postal_address', 'type' => 'postal'));
     $filter = new Sales_Model_AddressFilter(array());
     $filter->addFilter(new Tinebase_Model_Filter_Text(array('field' => 'customer_id', 'operator' => 'in', 'value' => $supplierIds)));
     $this->_addresses = $be->search($filter);
     $this->_contacts = Addressbook_Controller_Contact::getInstance()->getMultiple($contactIds);
 }