public function test_accounts_manage()
 {
     // Create user
     $account = new pybilling\Account(array('name' => 'Dmitry'));
     $account->save();
     # Create
     $aContact = new pybilling\AccountContact(array('name' => 'home', 'address' => '*****@*****.**', 'type' => 'email', 'account' => $account->id));
     $aContact->save();
     $this->assertEquals('home', $aContact->name);
     $this->assertEquals('email', $aContact->type);
     $this->assertEquals('*****@*****.**', $aContact->address);
     $this->assertEquals($account->id, $aContact->account);
     # Update
     $aContact->address = '*****@*****.**';
     $aContact->name = 'work';
     $aContact->save();
     $aContact_upd = pybilling\AccountContact::get($aContact->id);
     $this->assertEquals($aContact->id, $aContact_upd->id);
     $this->assertEquals('work', $aContact_upd->name);
     $this->assertEquals('email', $aContact_upd->type);
     $this->assertEquals('*****@*****.**', $aContact_upd->address);
     $this->assertEquals($account->id, $aContact_upd->account);
     // Delete contacts
     $aContact_upd->delete();
     try {
         pybilling\AccountContact::get($aContact_upd->id);
         $this->fail("Waiting for the exception.");
     } catch (Exception $ex) {
         $this->assertEquals(404, $ex->getCode());
     }
 }
 public function test_accounts_with_contacts_and_personal_data()
 {
     $account = new pybilling\Account(array('name' => 'Dmitry'));
     $account->save();
     # Create
     $personal_data = new pybilling\PersonalData(array('fio' => "Zbignev Bj Жезинский", 'birth' => '1983-09-05', 'postal_index' => 610001, 'postal_address' => 'Address Postal', 'phone' => '+7 495 6680903', 'passport' => '8734 238764234 239874', 'email' => '*****@*****.**', 'account' => $account->id, 'type' => 'PersonalDataPerson'));
     $personal_data->save();
     $aContact = new pybilling\AccountContact(array('name' => 'home', 'address' => '*****@*****.**', 'type' => 'email', 'account' => $account->id));
     $aContact->save();
     //  Checks
     $updated_account = pybilling\Account::get($account->id);
     $this->assertEquals(1, count($updated_account->contacts));
     $this->assertEquals(1, count($updated_account->personal_data));
     // check contacts
     $contact = $updated_account->contacts[0];
     $this->assertEquals('home', $contact->name);
     $this->assertEquals('email', $contact->type);
     $this->assertEquals('*****@*****.**', $contact->address);
     $this->assertEquals($account->id, $contact->account);
     // check personal data
     $pdata = $updated_account->personal_data[0];
     $this->assertEquals('610001', $pdata->postal_index);
     $this->assertEquals('Zbignev Bj Zhezinskij', $pdata->fio_lat);
     $this->assertEquals('Zbignev Bj Жезинский', $pdata->fio);
     $this->assertEquals('PersonalDataPerson', $pdata->type);
     $this->assertEquals('+7 495 6680903', $pdata->phone);
     $this->assertEquals($account->id, $pdata->account);
 }