protected function tearDown()
 {
     if ($this->_provider && $this->_provider->getId()) {
         $this->_provider->delete();
     }
     if ($this->_master && $this->_master->getId()) {
         $this->_master->delete();
     }
     parent::tearDown();
 }
 protected function _createTree()
 {
     if ($this->_masterOrg && $this->_masterOrg instanceof Model\PersistentAbstract && $this->_masterOrg->getId()) {
         $this->_masterOrg->delete();
     }
     if ($this->_providerOrg && $this->_providerOrg instanceof Model\PersistentAbstract && $this->_providerOrg->getId()) {
         $this->_providerOrg->delete();
     }
     $this->_masterOrg = new Model\Organization\OrgMasterModel(array('name' => 'ORG_TEST' . microtime(true), 'description' => "Description", 'status' => Model\Organization\OrgMasterModel::ORG_STATUS_ACTIVATED, 'defaultLanguage' => 'es', 'primaryContact' => array('firstName' => 'pcfn', 'lastName' => 'pcln', 'phone' => '933453212', 'email' => '*****@*****.**', 'mobile' => '665348765', 'fax' => '933453232'), 'companyAddress' => array('line1' => 'line1', 'line2' => 'line2', 'city' => 'Barcelona', 'state' => 'Catalunya', 'region' => 'Barcelona', 'country' => 'ES', 'postalCode' => '08005')));
     $this->_masterOrg->save();
     $this->_providerOrg = new Model\Organization\OrgServiceProviderModel(array('name' => 'Service provider name' . microtime(true), 'description' => "Description", 'commercialName' => 'Service provider commercial name', 'status' => Model\Organization\OrgServiceProviderModel::ORG_STATUS_ACTIVATED, 'defaultLanguage' => 'es', 'parentId' => $this->_masterOrg->getId(), 'GGSNProvisioning' => true, 'pluralSIMProvisioning' => false, 'fiscalNumber' => 'X4543545643', 'countryVATNumber' => '45634556', 'brand' => 'o2', 'primaryContact' => array('firstName' => 'Pepe', 'lastName' => 'González', 'phone' => '934443344', 'email' => '*****@*****.**', 'mobile' => '655445533', 'fax' => '934443344'), 'billingAddress' => array('line1' => 'name line here', 'line2' => 'name line here', 'city' => 'Barcelona', 'state' => 'Catalonia', 'country' => 'ES', 'postalCode' => '08080'), 'shippingAddress' => array('line1' => 'line1', 'line2' => 'line2', 'city' => 'Barcelona', 'state' => 'Catalonia', 'country' => 'ES', 'postalCode' => '08080'), 'companyAddress' => array('line1' => 'line1', 'line2' => 'line2', 'city' => 'Barcelona', 'state' => 'Catalonia', 'country' => 'ES', 'postalCode' => '08080')));
     $this->_providerOrg->save();
     return $this->_providerOrg->getId();
 }
 public function testFindAllByParentId()
 {
     //TODO: @alfred dice que lo arregla, lo curioso es que si ejecutas el
     //test solo funciona, si ejecutas todos da un error de permisos
     $this->markTestIncomplete();
     $masterData = array('name' => 'ORG_TEST_PARENT1' . microtime(true), 'description' => "Description", 'status' => OrgMasterModel::ORG_STATUS_ACTIVATED, 'defaultLanguage' => "es", 'type' => OrgMasterModel::ORG_TYPE, 'primaryContact' => array('firstName' => 'pcfn', 'lastName' => 'pcln', 'phone' => '933453212', 'email' => '*****@*****.**', 'mobile' => '665348765', 'fax' => '933453232'), 'companyAddress' => array('line1' => 'line1', 'line2' => 'line2', 'city' => 'Barcelona', 'state' => 'Catalunya', 'region' => 'Barcelona', 'country' => 'ES', 'postalCode' => '08005'));
     $masters = array(new OrgMasterModel($masterData), new OrgMasterModel(array('name' => 'ORG_TEST_PARENT2' . microtime(true)) + $masterData));
     foreach ($masters as $parent) {
         $parent->save();
     }
     $childData = $this->_model->exportData();
     if (isset($childData['id'])) {
         unset($childData['id']);
     }
     $parentId = $masters[0]->getId();
     //         $this->_addUser(OrganizationMapper::cleanOrgId($parentId), OrgMasterModel::ORG_TYPE);
     $childData['parentId'] = $parentId;
     for ($i = 0; $i < 3; $i++) {
         $childData['name'] = 'child' . $i . 'ofParent1' . microtime(true);
         $childData['commercialName'] = 'child' . $i . 'ofParent1-' . microtime(true);
         $child = new OrgServiceProviderModel($childData);
         $child->save();
     }
     $filterList = \Application\Service\OrgService::getInstance()->buildFilterList(array('parentId' => $parentId, 'type' => OrgServiceProviderModel::ORG_TYPE));
     $childsParent1 = $this->_mapper->findAll(array('filterList' => $filterList))->getItems();
     $this->assertTrue(is_array($childsParent1));
     $this->assertEquals(3, count($childsParent1));
     $parentId = $masters[1]->getId();
     $this->_addUser(OrganizationMapper::cleanOrgId($parentId), OrgMasterModel::ORG_TYPE);
     $childData['parentId'] = $parentId;
     for ($i = 0; $i < 5; $i++) {
         $childData['name'] = 'child' . $i . 'ofParent2' . microtime(true);
         $childData['commercialName'] = 'child' . $i . 'ofParent2-' . microtime(true);
         $child = new OrgServiceProviderModel($childData);
         $child->save();
     }
     $filterList = Application\Service\OrgService::getInstance()->buildFilterList(array('parentId' => $parentId, 'type' => OrgServiceProviderModel::ORG_TYPE));
     $childsParent2 = $this->_mapper->findAll(array('filterList' => $filterList))->getItems();
     $this->assertTrue(is_array($childsParent2));
     $this->assertEquals(5, count($childsParent2));
     $this->_addUser(OrganizationMapper::cleanOrgId($masters[0]), OrgMasterModel::ORG_TYPE);
     foreach ($childsParent1 as $child) {
         $child->delete();
     }
     $this->_addUser(OrganizationMapper::cleanOrgId($masters[1]), OrgMasterModel::ORG_TYPE);
     foreach ($childsParent2 as $child) {
         $child->delete();
     }
     foreach ($masters as $parent) {
         $parent->delete();
     }
 }
 protected function _createTree()
 {
     if ($this->_masterOrg && $this->_masterOrg instanceof Model\PersistentAbstract && $this->_masterOrg->getId()) {
         $this->_masterOrg->delete();
     }
     if ($this->_providerOrg && $this->_providerOrg instanceof Model\PersistentAbstract && $this->_providerOrg->getId()) {
         $this->_providerOrg->delete();
     }
     if ($this->_customerOrg && $this->_customerOrg instanceof Model\PersistentAbstract && $this->_customerOrg->getId()) {
         $this->_customerOrg->delete();
     }
     $this->_masterOrg = new Model\Organization\OrgMasterModel(array('name' => 'ORG_TEST' . microtime(true), 'description' => "Description", 'status' => Model\Organization\OrgMasterModel::ORG_STATUS_ACTIVATED, 'defaultLanguage' => 'es', 'primaryContact' => array('firstName' => 'pcfn', 'lastName' => 'pcln', 'phone' => '933453212', 'email' => '*****@*****.**', 'mobile' => '665348765', 'fax' => '933453232'), 'companyAddress' => array('line1' => 'line1', 'line2' => 'line2', 'city' => 'Barcelona', 'state' => 'Catalunya', 'region' => 'Barcelona', 'country' => 'ES', 'postalCode' => '08005')));
     $this->_masterOrg->save();
     $this->_providerOrg = new Model\Organization\OrgServiceProviderModel(array('name' => 'Service provider name' . microtime(true), 'description' => "Description", 'commercialName' => 'Service provider commercial name', 'status' => Model\Organization\OrgServiceProviderModel::ORG_STATUS_ACTIVATED, 'defaultLanguage' => 'es', 'parentId' => $this->_masterOrg->getId(), 'GGSNProvisioning' => true, 'pluralSIMProvisioning' => false, 'fiscalNumber' => 'X4543545643', 'countryVATNumber' => '45634556', 'brand' => 'o2', 'primaryContact' => array('firstName' => 'Pepe', 'lastName' => 'González', 'phone' => '934443344', 'email' => '*****@*****.**', 'mobile' => '655445533', 'fax' => '934443344'), 'billingAddress' => array('line1' => 'name line here', 'line2' => 'name line here', 'city' => 'Barcelona', 'state' => 'Catalonia', 'country' => 'ES', 'postalCode' => '08080'), 'shippingAddress' => array('line1' => 'line1', 'line2' => 'line2', 'city' => 'Barcelona', 'state' => 'Catalonia', 'country' => 'ES', 'postalCode' => '08080'), 'companyAddress' => array('line1' => 'line1', 'line2' => 'line2', 'city' => 'Barcelona', 'state' => 'Catalonia', 'country' => 'ES', 'postalCode' => '08080')));
     $this->_providerOrg->save();
     $customerData = '
     {
     "type": "customer",
     "name": "M2M_CUSTOMER_' . microtime(true) . '",
     "description": "Description",
     "status": 1,
     "defaultLanguage": "es",
     "billingCycleStart": {
     "dayOfMonth": 13,
     "timezone": "Europe/Madrid"
     },
     "currency": "978",
     "companyType": "1",
     "sector": "1",
     "companyAddress": {
     "line1": "cfsfsvsa",
     "line2": "Telefónica",
     "city": "Barcelona",
     "state": "Catalunya",
     "country": "ES",
     "postalCode": "5"
     },
     "primaryContact": {
     "firstName": "Alberto",
     "lastName": "Pastor",
     "phone": "931233372",
     "email": "*****@*****.**",
     "mobile": "653229800",
     "fax": "898989898"
     },
     "primaryContactAddressIsCompanyAddress": true,
     "primaryContactAddress": {
     "line1": "cfsfsvsa",
     "line2": "Telefónica",
     "city": "Barcelona",
     "state": "Catalunya",
     "country": "ES",
     "postalCode": "5"
     },
     "billingContactIsPrimaryContact": true,
     "billingContact": {
     "firstName": "Alberto",
     "lastName": "Pastor",
     "phone": "931233372",
     "email": "*****@*****.**",
     "mobile": "653229800",
     "fax": "898989898"
     },
     "billingContactAddressIsCompanyAddress": true,
     "billingContactAddress": {
     "line1": "cfsfsvsa",
     "line2": "Telefónica",
     "city": "Barcelona",
     "state": "Catalunya",
     "country": "ES",
     "postalCode": "5"
     },
     "shippingAddressIsCompanyAddress": true,
     "shippingAddress": {
     "line1": "cfsfsvsa",
     "line2": "Telefónica",
     "city": "Barcelona",
     "state": "Catalunya",
     "country": "ES",
     "postalCode": "76854"
     },
     "defaultBillingAccount": {
     "billingAccountName": "Default billing account",
     "billingAccountId": "",
     "fiscalNumber": "B244235457",
     "billable": true,
     "automaticPrebill": true,
     "crmBillingAccountId": "1",
     "addressIsCompanyAddress": true,
     "address": {
     "line1": "cfsfsvsa",
     "line2": "Telefónica",
     "city": "Barcelona",
     "state": "Catalunya",
     "country": "ES",
     "postalCode": "ES"
     },
     "contactIsPrimaryContact": true,
     "contact": {
     "firstName": "Alberto",
     "lastName": "Pastor",
     "phone": "931233372",
     "email": "*****@*****.**",
     "mobile": "653229800",
     "fax": "898989898"
     },
     "commercialGroups": [
     ""
     ],
     "numSubscriptions": 0,
     "taxes": {
     "tax": [
     {
     "name": "tax1",
     "value": 100
     },
     {
     "name": "tax2",
     "value": 200
     }
     ]
     },
     "discounts": {
     "discount": [
     {
     "name": "discount1",
     "steps": [
     {
     "threshold": 20,
     "value": 300
     },
     {
     "threshold": 20,
     "value": 300
     }
     ]
     },
     {
     "name": "discount2",
     "steps": [
     {
     "threshold": 60,
     "value": 300
     },
     {
     "threshold": 70,
     "value": 300
     }
     ]
     }
     ]
     },
     "paymentMethod": "visa",
     "paymentRelatedData": "1306101600"
     },
     "billingAccounts": {
     "billingAccount": [
     {
     "billingAccountName": "default",
     "billingAccountId": "",
     "fiscalNumber": "B244235457",
     "billable": true,
     "automaticPrebill": true,
     "crmBillingAccountId": "1",
     "addressIsCompanyAddress": true,
     "address": {
     "line1": "cfsfsvsa",
     "line2": "Telefónica",
     "city": "Barcelona",
     "state": "Catalunya",
     "country": "ES",
     "postalCode": "ES"
     },
     "contactIsPrimaryContact": false,
     "contact": {
     "firstName": "Alberto",
     "lastName": "Pastor",
     "phone": "931233372",
     "email": "*****@*****.**",
     "mobile": "653229800",
     "fax": "898989898"
     },
     "commercialGroups": [
     ""
     ],
     "numSubscriptions": 0,
     "taxes": {
     "tax": [
     {
     "name": "tax1",
     "value": 100
     },
     {
     "name": "tax2",
     "value": 200
     }
     ]
     },
     "discounts": {
     "discount": [
     {
     "name": "discount1",
     "steps": [
     {
     "threshold": 20,
     "value": 300
     },
     {
     "threshold": 20,
     "value": 300
     }
     ]
     },
     {
     "name": "discount2",
     "steps": [
     {
     "threshold": 60,
     "value": 300
     },
     {
     "threshold": 70,
     "value": 300
     }
     ]
     }
     ]
     },
     "paymentMethod": "visa",
     "paymentRelatedData": "1306101600"
     },
     {
     "billingAccountName": "default",
     "billingAccountId": "",
     "fiscalNumber": "B244235457",
     "billable": true,
     "automaticPrebill": true,
     "crmBillingAccountId": "1",
     "addressIsCompanyAddress": true,
     "address": {
     "line1": "cfsfsvsa",
     "line2": "Telefónica",
     "city": "Barcelona",
     "state": "Catalunya",
     "country": "ES",
     "postalCode": "ES"
     },
     "contactIsPrimaryContact": true,
     "contact": {
     "firstName": "Alberto",
     "lastName": "Pastor",
     "phone": "931233372",
     "email": "*****@*****.**",
     "mobile": "653229800",
     "fax": "898989898"
     },
     "commercialGroups": [
     ""
     ],
     "numSubscriptions": 0,
     "taxes": {
     "tax": [
     {
     "name": "tax1",
     "value": 100
     },
     {
     "name": "tax2",
     "value": 200
     }
     ]
     },
     "discounts": {
     "discount": [
     {
     "name": "discount1",
     "steps": [
     {
     "threshold": 20,
     "value": 300
     },
     {
     "threshold": 20,
     "value": 300
     }
     ]
     },
     {
     "name": "discount2",
     "steps": [
     {
     "threshold": 60,
     "value": 300
     },
     {
     "threshold": 70,
     "value": 300
     }
     ]
     }
     ]
     },
     "paymentMethod": "visa",
     "paymentRelatedData": "1306101600"
     }
     ]
     },
     "customFieldName_1": "custom_field_name_cust_1",
     "customFieldName_2": "custom_field_name_cust_2",
     "customFieldName_3": "custom_field_name_cust_3",
     "customFieldName_4": "custom_field_name_cust_4",
     "crmId_1": "crm1",
     "crmId_2": "crm2",
     "taxes": {
     "tax": [
     {
     "name": "tax1",
     "value": 100
     },
     {
     "name": "tax2",
     "value": 200
     }
     ]
     },
     "discounts": {
     "discount": [
     {
     "name": "discount1",
     "value": 300
     },
     {
     "name": "discount2",
     "value": 120
     }
     ]
     },
     "vpns": {
     "vpn": [
     {
     "name": "vpn1",
     "apns": [
     "2234",
     "9382"
     ],
     "staticAddressing": true,
     "network": "mask1",
     "mask": "network1"
     },
     {
     "name": "vpn2",
     "apns": [
     "3234",
     "2382"
     ],
     "staticAddressing": true,
     "network": "mask1",
     "mask": "network1"
     }
     ]
     },
     "parentId": "' . self::PROVIDER_COMMERCIAL_ORG_ID . '"
     }
     ';
     $array = Zend_Json::decode($customerData);
     $this->_customerOrg = new Model\Organization\OrgCustomerModel($array);
     $this->_customerOrg->parentId = $this->_providerOrg->getId();
     $this->_customerOrg->save();
     return $this->_customerOrg->getId();
 }