/**
  * Test active record array deleteFull() where canDelete has been set to false
  *
  * @expectedException        \fangface\db\Exception
  * @expectedExceptionMessage Attempting to delete Item(s) model flagged as not deletable
  */
 function testActiveRecordDeleteFullOnNonCanDeleteArrayFails()
 {
     $client = Client::findOne(1);
     $this->assertInstanceOf(Client::className(), $client);
     $this->setService('client', $client);
     $customerId = $this->createTestCustomerAndOrder($client->clientCode);
     $this->assertTrue($customerId !== false && $customerId > 0);
     $this->checkBaseCounts('full', $client->clientCode);
     $customer = Customer::findOne($customerId);
     $this->assertInstanceOf(Customer::className(), $customer);
     $customer->orders[1]->items->setCanDelete(false);
     $customer->orders[1]->items->deleteFull();
 }
 /**
  * Test setValuesByArray method
  */
 public function testSetValuesByArray()
 {
     $client = Client::findOne(1);
     $this->assertInstanceOf(Client::className(), $client);
     $this->setService('client', $client);
     $customerAttributes = new CustomerAttributes();
     $customerAttributes->setValuesByArray(array('field1' => 'a', 'field2' => 'b'), array('modifiedBy' => 54));
     $this->assertEquals('a', $customerAttributes->field1);
     $this->assertEquals('b', $customerAttributes->field2);
     $this->assertEquals(54, $customerAttributes->modifiedBy);
 }
 /**
  * Test creating a non empty active record is a success
  * this model has a mixture of field types with default values
  * including a long text which has no default value and does not allow nulls
  */
 function testNonEmptyActiveRecordSaveAll3Success()
 {
     $client = Client::findOne(1);
     $this->assertInstanceOf(Client::className(), $client);
     $this->setService('client', $client);
     $note = new Pick();
     $note->loadDefaultValues();
     $note->anotherString = 'B';
     $success = $note->saveAll();
     $this->assertTrue($success);
     $note->refresh();
     $this->assertEquals('B', $note->anotherString);
     $this->assertEquals('', $note->anotherText);
 }
 /**
  * Amend customer id at top level of a relation and test that a push()
  * request forces relations that have customerId set are updated even though
  * no other changes have been made
  */
 function testActiveRecordChangeTopLevelIdFeedsDownToRelations()
 {
     $client = Client::findOne(1);
     $this->assertInstanceOf(Client::className(), $client);
     $this->setService('client', $client);
     $customerId = $this->createTestCustomerAndOrder($client->clientCode);
     $this->assertTrue($customerId !== false && $customerId > 0);
     $this->checkBaseCounts('full', $client->clientCode);
     $customer = Customer::findOne($customerId);
     $this->assertInstanceOf(Customer::className(), $customer);
     $customer->id = 95;
     $customerPreChangeWithNewId = $this->updateCustomerIdForComparison($this->cleanDatesForComparison($customer->toArray()), 95);
     $customer->push();
     $customer = Customer::findOne(95);
     $this->assertInstanceOf(Customer::className(), $customer);
     $customerReloaded = $this->cleanDatesForComparison($customer->toArray());
     $this->assertEquals($customerPreChangeWithNewId, $customerReloaded, 'Failed to push new customerId into relations after reload');
 }