/**
  * @depends testList
  */
 public function testDelete()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $authenticationData = $this->login();
     $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
     $testModels = ApiTestModelItem::getByName('Michael6');
     $this->assertEquals(1, count($testModels));
     $response = $this->createApiCallWithRelativeUrl('delete/' . $testModels[0]->id, 'DELETE', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $response = $this->createApiCallWithRelativeUrl('read/' . $testModels[0]->id, 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']);
 }
 public function testGetDataWithHasOneRelatedModel()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $currencies = Currency::getAll();
     $currencyValue = new CurrencyValue();
     $currencyValue->value = 100;
     $currencyValue->currency = $currencies[0];
     $this->assertEquals('USD', $currencyValue->currency->code);
     $testItem2 = new ApiTestModelItem2();
     $testItem2->name = 'John';
     $this->assertTrue($testItem2->save());
     $testItem4 = new ApiTestModelItem4();
     $testItem4->name = 'John';
     $this->assertTrue($testItem4->save());
     //HAS_MANY and MANY_MANY relationships should be ignored.
     $testItem3_1 = new ApiTestModelItem3();
     $testItem3_1->name = 'Kevin';
     $this->assertTrue($testItem3_1->save());
     $testItem3_2 = new ApiTestModelItem3();
     $testItem3_2->name = 'Jim';
     $this->assertTrue($testItem3_2->save());
     $testItem = new ApiTestModelItem();
     $testItem->firstName = 'Bob3';
     $testItem->lastName = 'Bob3';
     $testItem->boolean = true;
     $testItem->date = '2002-04-03';
     $testItem->dateTime = '2002-04-03 02:00:43';
     $testItem->float = 54.22;
     $testItem->integer = 10;
     $testItem->phone = '21313213';
     $testItem->string = 'aString';
     $testItem->textArea = 'Some Text Area';
     $testItem->url = 'http://www.asite.com';
     $testItem->owner = $super;
     $testItem->currencyValue = $currencyValue;
     $testItem->modelItem2 = $testItem2;
     $testItem->modelItems3->add($testItem3_1);
     $testItem->modelItems3->add($testItem3_2);
     $testItem->modelItems4->add($testItem4);
     $createStamp = strtotime(DateTimeUtil::convertTimestampToDbFormatDateTime(time()));
     $this->assertTrue($testItem->save());
     $id = $testItem->id;
     $testItem->forget();
     unset($testItem);
     $testItem = ApiTestModelItem::getById($id);
     $adapter = new RedBeanModelToApiDataUtil($testItem);
     $data = $adapter->getData();
     $compareData = array('id' => $id, 'firstName' => 'Bob3', 'lastName' => 'Bob3', 'boolean' => '1', 'date' => '2002-04-03', 'dateTime' => '2002-04-03 02:00:43', 'float' => '54.22', 'integer' => '10', 'phone' => '21313213', 'string' => 'aString', 'textArea' => 'Some Text Area', 'url' => 'http://www.asite.com', 'currencyValue' => array('id' => $currencyValue->id, 'value' => 100, 'rateToBase' => 1, 'currency' => array('id' => $currencies[0]->id)), 'dropDown' => null, 'radioDropDown' => null, 'multiDropDown' => array('values' => null), 'tagCloud' => array('values' => null), 'modelItem2' => array('id' => $testItem2->id), 'primaryEmail' => null, 'primaryAddress' => null, 'secondaryEmail' => null, 'language' => null, 'owner' => array('id' => $super->id, 'username' => 'super'), 'createdByUser' => array('id' => $super->id, 'username' => 'super'), 'modifiedByUser' => array('id' => $super->id, 'username' => 'super'));
     // Because small delay in IO operation, allow tresholds
     $this->assertEquals($createStamp, strtotime($data['createdDateTime']), '', 2);
     $this->assertEquals($createStamp, strtotime($data['modifiedDateTime']), '', 2);
     unset($data['createdDateTime']);
     unset($data['modifiedDateTime']);
     $this->assertEquals($compareData, $data);
 }