public function testUpdatesResourceType() { $unchanged = new AttributeValue(1, 'value'); $toChange = new AttributeValue(2, 'value'); $toAdd = new AttributeValue(3, 'value'); $id = 11; $type = new ResourceType($id, 'name', 'desc'); $type->WithAttribute($unchanged); $type->WithAttribute(new AttributeValue(100, 'should be removed')); $type->WithAttribute(new AttributeValue(2, 'new value')); $attributes = array($unchanged, $toChange, $toAdd); $type->ChangeAttributes($attributes); $this->repository->UpdateResourceType($type); $addNewCommand = new AddAttributeValueCommand($toAdd->AttributeId, $toAdd->Value, $id, CustomAttributeCategory::RESOURCE_TYPE); $removeOldCommand = new RemoveAttributeValueCommand(100, $id); $removeUpdated = new RemoveAttributeValueCommand($toChange->AttributeId, $id); $addUpdated = new AddAttributeValueCommand($toChange->AttributeId, $toChange->Value, $id, CustomAttributeCategory::RESOURCE_TYPE); $expectedCommand = new UpdateResourceTypeCommand($type->Id(), $type->Name(), $type->Description()); $this->assertEquals($expectedCommand, $this->db->_Commands[0]); $this->assertEquals($removeOldCommand, $this->db->_Commands[1]); $this->assertEquals($removeUpdated, $this->db->_Commands[2], "need to remove before adding to make sure changed values are not immediately deleted"); $this->assertEquals($addUpdated, $this->db->_Commands[3]); $this->assertEquals($addNewCommand, $this->db->_Commands[4]); }
public function testChangesAttributes() { $id = 1232; $name = 'name'; $description = 'description'; $resourceType = new ResourceType($id, $name, $description); $resourceType->ChangeAttributes(array(new AttributeValue(1, 'val'))); $attributeVals = array(new AttributeValue(1, 'val')); $this->page->expects($this->once())->method('GetId')->will($this->returnValue($id)); $this->page->expects($this->once())->method('GetAttributes')->will($this->returnValue($attributeVals)); $this->resourceRepository->expects($this->once())->method('LoadResourceType')->with($this->equalTo($id))->will($this->returnValue($resourceType)); $this->resourceRepository->expects($this->once())->method('UpdateResourceType')->with($this->equalTo($resourceType)); $this->presenter->ChangeAttributes(); }