SalesForce Apex コードで、理解できない動作が見られます。コードのセキュリティ規則に違反しているようです。次のようなコントローラーがあります。
public with sharing class CaseController {
//Properties
public Case TheCase { get; private set; }
//
//Constructor
public CaseController(ApexPages.StandardController controller) {
//Some unimportant stuff
}
//
//Validates all data coming in from the view and saves the case
public PageReference Save() {
//Some other unimportant stuff
}
}
そして、次のようなテスト:
private static testMethod void Save_WithCompleteCase_SavesCase()
{
//Given
User user = GetTestUser('Standard User');
Product2 theProduct = GetTestProduct();
Case theCase = GetTestCase(user, theProduct);
System.runAs(user) {
//When
CaseController controller = new CaseController(new ApexPages.StandardController(theCase));
controller.TheCase.Subject = 'Test Case'; //Making a change to test it saved
PageReference page = controller.Save();
//Then
}
}
私のコントローラーには「TheCase」のプライベートセッターがありますが、テストクラスでその値を変更できることに注意してください。このコードは動作し、SalesForce によって処理されます。なんで?他のクラスのプライベート メンバーにアクセスできるようにするテスト クラスに何か特別なことはありますか?
ありがとう!!