/** * This class contains unit tests for validating the behavior of Apex classes * and triggers. * * Unit tests are class methods that verify whether a particular piece * of code is working properly. Unit test methods take no arguments, * commit no data to the database, and are flagged with the testMethod * keyword in the method definition. * * All test methods in an organization are executed whenever Apex code is deployed * to a production organization to confirm correctness, ensure code * coverage, and prevent regressions. All Apex classes are * required to have at least 75% code coverage in order to be deployed * to a production organization. In addition, all triggers must have some code coverage. * * The @isTest class annotation indicates this class only contains test * methods. Classes defined with the @isTest annotation do not count against * the organization size limit for all Apex scripts. * * See the Apex Language Reference for more information about Testing and Code Coverage. */ @isTest private class SearchVistorControllerTest { private static String loginId{get;set;} private static User u1{get;set;} private static User u2{get;set;} private static User u3{get;set;} private static Account accHP{get;set;} private static Account accDepClass{get;set;} private static Account accDep{get;set;} private static Contact con1{get;set;} private static Contact con2{get;set;} private static Contact con3{get;set;} private static Contact con4{get;set;} private static Contact con5{get;set;} private static String accDepId{get;set;} private static String accDepName{get;set;} /** * 初期処理. */ @TestSetup static void makeData(){ TestDataUtility.CreatePIPolicyConfiguration('Contact'); } private static void init() { loginId = UserInfo.getUserId(); Profile p = [select id from Profile where id =:System.Label.ProfileId_SystemAdmin]; u3 = new User(Test_staff__c = true); u3.LastName = '_サンブリッジ'; u3.FirstName = 'う'; u3.Alias = 'うFF'; u3.Email = 'olympusTest03@sunbridge.com'; u3.Username = 'olympusTest03@sunbridge.com'; u3.CommunityNickname = 'う'; u3.IsActive = true; u3.EmailEncodingKey = 'ISO-2022-JP'; u3.TimeZoneSidKey = 'Asia/Tokyo'; u3.LocaleSidKey = 'ja_JP'; u3.LanguageLocaleKey = 'ja'; u3.ProfileId = p.id; u3.Job_Category__c = '支援'; u3.Province__c = '東京'; insert u3; u1 = new User(Test_staff__c = true); u1.LastName = '_サンブリッジ'; u1.FirstName = 'あZZ'; u1.Alias = 'あ'; u1.Email = 'olympusTest01@sunbridge.com'; u1.Username = 'olympusTest01@sunbridge.com'; u1.CommunityNickname = 'あ'; u1.IsActive = true; u1.EmailEncodingKey = 'ISO-2022-JP'; u1.TimeZoneSidKey = 'Asia/Tokyo'; u1.LocaleSidKey = 'ja_JP'; u1.LanguageLocaleKey = 'ja'; u1.ProfileId = p.id; u1.Job_Category__c = '销售服务'; u1.Province__c = '東京'; u1.ManagerId = u3.id; insert u1; u2 = new User(Test_staff__c = true); u2.LastName = '_サンブリッジ'; u2.FirstName = 'いDD'; u2.Alias = 'い'; u2.Email = 'olympusTest02@sunbridge.com'; u2.Username = 'olympusTest02@sunbridge.com'; u2.CommunityNickname = 'い'; u2.IsActive = true; u2.EmailEncodingKey = 'ISO-2022-JP'; u2.TimeZoneSidKey = 'Asia/Tokyo'; u2.LocaleSidKey = 'ja_JP'; u2.LanguageLocaleKey = 'ja'; u2.ProfileId = p.id; u2.Job_Category__c = '销售推广'; u2.Province__c = '東京'; insert u2; RecordType rtHP = [select id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName =:'HP']; RecordType rtDepClass = [select id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName =:'Department_Class_ENT']; // 耳鼻喉科 RecordType rtDep = [select id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName =:'Department_ENT']; RecordType rtDoc = [select id from RecordType where IsActive = true and SobjectType = 'Contact' and DeveloperName =:'Doctor']; //Address_Level__c al = [select id from Address_Level__c where Level1_Code__c =:'CN-01']; //Address_Level2__c al2 = [select id from Address_Level2__c where Name =:'延庆县']; Address_Level__c al = new Address_Level__c(); al.Name = '東京'; al.Level1_Code__c = 'CN-99'; al.Level1_Sys_No__c = '999999'; insert al; Address_Level2__c al2 = new Address_Level2__c(); al2.Level1_Code__c = 'CN-99'; al2.Level1_Sys_No__c = '999999'; al2.Level1_Name__c = '東京'; al2.Name = '渋谷区'; al2.Level2_Code__c = 'CN-9999'; al2.Level2_Sys_No__c = '9999999'; al2.Address_Level__c = al.id; insert al2; accHP = new Account(); accHP.Name = '病院1'; accHP.Grade__c = '一般'; accHP.OCM_Category__c = '一般'; accHP.Attribute_Type__c = '保険省'; accHP.Speciality_Type__c = '総合病院'; accHP.Is_Active__c = '有効'; accHP.State_Master__c = al.id; accHP.City_Master__c = al2.id; accHP.RecordTypeId = rtHP.id; insert accHP; accDepClass = new Account(); accDepClass.Name = '戦略科室分類1'; accDepClass.Department_Class_Label__c = '耳鼻喉科'; accDepClass.Hospital_Department_Class__c = accHP.id; accDepClass.ParentId = accHP.id; accDepClass.RecordTypeId = rtDepClass.id; insert accDepClass; accDep = new Account(); accDep.Name = '診療科1'; accDep.Department_Class_Label__c = '診療科1'; accDep.Hospital__c = accHP.id; accDep.ParentId = accDepClass.id; accDep.Department_Class__c = accDepClass.id; accDep.Department_Name__c = '診療科1'; accDep.CurrencyIsoCode = 'CNY'; accDep.RecordTypeId = rtDep.id; insert accDep; accDepId = accDep.Id; accDep = [select Name from Account where Id = :accDep.Id]; accDepName = accDep.Name; // 取引先責任者の住所を数式項目に変更の為、当該項目を削除 // 省の参照先は病院の住所になったため、カバレッジテストを行うには // 所属する病院の賞を変更して実施してください。by 宗像(真) List conList = new List(); con1 = new Contact(); con1.LastName = '取引先責任者1'; con1.FirstName = 'zz1'; con1.RecordTypeId = rtDoc.id; con1.AccountId = accDep.id; con1.AWS_Data_Id__c = '1231'; // con1.State__c = '北京市'; con2 = new Contact(); con2.FirstName = 'zz2'; con2.LastName = '取引先責任者2'; con2.RecordTypeId = rtDoc.id; con2.AccountId = accDep.id; con2.AWS_Data_Id__c = '1232'; // con2.State__c = '北京市'; con3 = new Contact(); con3.FirstName = 'zz3'; con3.LastName = '取引先責任者3'; con3.RecordTypeId = rtDoc.id; con3.AccountId = accDep.id; con3.AWS_Data_Id__c = '1233'; // con3.State__c = '北京市'; con4 = new Contact(); con4.FirstName = 'zz4'; con4.LastName = '取引先責任者4'; con4.RecordTypeId = rtDoc.id; con4.AccountId = accDep.id; con4.AWS_Data_Id__c = '1234'; // con4.State__c = '北京市'; con5 = new Contact(); con5.FirstName = 'zz5'; con5.LastName = '取引先責任者5'; con5.RecordTypeId = rtDoc.id; con5.AccountId = accDep.id; con5.AWS_Data_Id__c = '1235'; // con5.State__c = '北京市'; conList.add(con1); conList.add(con2); conList.add(con3); conList.add(con4); conList.add(con5); insert conList; } static testMethod void test01_01() { init(); Apexpages.currentPage().getParameters().put('vp', accDep.id); Apexpages.currentPage().getParameters().put('idVa1',con1.Id); Apexpages.currentPage().getParameters().put('idVa2',con2.Id); Apexpages.currentPage().getParameters().put('idVa3',con3.Id); Apexpages.currentPage().getParameters().put('idVa4',con4.Id); Apexpages.currentPage().getParameters().put('idVa5',con5.Id); System.runAs(u1) { SearchVisitorController svc = new SearchVisitorController(); svc.rc.MyDr_Flg__c = true; svc.rc.Search_LastName__c = 'testLastName'; svc.rc.FirstName = 'testFirstName'; svc.rc.Account_Visitor_Search__c = accDep.id; svc.rc.Type__c = 'test'; svc.rc.Doctor_Division1__c = 'test'; svc.regContact(); svc.sc.Search_LastName__c = 'testLastName'; svc.sc.Search_FirstName__c = 'testFirstName'; svc.sc.Type__c = 'test'; svc.sc.Doctor_Division1__c = 'test'; svc.sc.MyDr_Flg__c = true; svc.serContact(); } } static testMethod void test01_02() { init(); Apexpages.currentPage().getParameters().put('vp', accDep.id); Apexpages.currentPage().getParameters().put('idVa1',con1.Id); Apexpages.currentPage().getParameters().put('idVa2',con2.Id); Apexpages.currentPage().getParameters().put('idVa3',con3.Id); Apexpages.currentPage().getParameters().put('idVa4',con4.Id); Apexpages.currentPage().getParameters().put('idVa5',con5.Id); System.runAs(u1) { SearchVisitorController svc = new SearchVisitorController(); svc.index = '1'; svc.editVistor(); svc.rc.MyDr_Flg__c = true; svc.rc.Search_LastName__c = 'testLastName'; svc.rc.FirstName = 'testFirstName'; svc.rc.Account_Visitor_Search__c = accDep.id; svc.rc.Type__c = 'test'; svc.rc.Doctor_Division1__c = 'test'; svc.regContact(); svc.sc.Search_LastName__c = 'testLastName'; svc.sc.Search_FirstName__c = 'testFirstName'; svc.sc.Type__c = 'test'; svc.sc.Doctor_Division1__c = 'test'; svc.sc.MyDr_Flg__c = true; svc.serContact(); } } static testMethod void test01_03() { init(); Apexpages.currentPage().getParameters().put('vp', accDep.id); Apexpages.currentPage().getParameters().put('idVa1',con1.Id); Apexpages.currentPage().getParameters().put('idVa2',con2.Id); Apexpages.currentPage().getParameters().put('idVa3',con3.Id); Apexpages.currentPage().getParameters().put('idVa4',con4.Id); Apexpages.currentPage().getParameters().put('idVa5',con5.Id); System.runAs(u1) { SearchVisitorController svc = new SearchVisitorController(); svc.index = '1'; svc.updContactP(); svc.updContactM(); svc.rc.MyDr_Flg__c = true; svc.rc.Search_LastName__c = 'testLastName'; svc.rc.FirstName = 'testFirstName'; svc.rc.Account_Visitor_Search__c = accDep.id; svc.rc.Type__c = 'test'; svc.rc.Doctor_Division1__c = 'test'; svc.regContact(); svc.clearRC(); svc.sc.Search_LastName__c = 'testLastName'; svc.sc.Search_FirstName__c = 'testFirstName'; svc.sc.Type__c = 'test'; svc.sc.Doctor_Division1__c = 'test'; svc.sc.MyDr_Flg__c = true; svc.serContact(); } } }