From ca54382924f5a27063eabbc5b2a81b3d44496b58 Mon Sep 17 00:00:00 2001
From: buli <137736985@qq.com>
Date: 星期四, 14 四月 2022 15:30:59 +0800
Subject: [PATCH] PIPLController0414

---
 force-app/main/default/classes/SearchProductControllerTest.cls |  255 ++++++++++++++++++++++++++++----------------------
 1 files changed, 143 insertions(+), 112 deletions(-)

diff --git a/force-app/main/default/classes/SearchProductControllerTest.cls b/force-app/main/default/classes/SearchProductControllerTest.cls
index 35b5e98..30cf9dd 100644
--- a/force-app/main/default/classes/SearchProductControllerTest.cls
+++ b/force-app/main/default/classes/SearchProductControllerTest.cls
@@ -1,120 +1,151 @@
-/**
- * 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 SearchProductControllerTest {
 
-    static testMethod void myUnitTest() {
-        Product2 p2 = new Product2();
-        Apexpages.currentPage().getParameters().put('val', 'aaa');
-        Apexpages.Standardcontroller scon = new Apexpages.Standardcontroller(p2);
-        SearchProductController controller = new SearchProductController(scon);
-        controller.trade = 'CNY';
-        controller.serContact();
-        controller.trade = 'USD';
-        controller.serContact();
-        controller.trade = '';
-        controller.serContact();
-        
-    }
-    
-    static testMethod void initTest() {
-    	Id pricebookId = ControllerUtil.getStandardPricebook().Id;
-        // 浜у搧
-        Product2 pro1 = new Product2(
-            Name='name01',
-            IsActive=true,
-            Asset_Model_No__c='n01',
-            MDM_Model_No__c='n01',
-            ProductCode_Ext__c='pc01',
-            ProductCode = 'pc01',
-            Manual_Entry__c=false,
-            SFDA_Status__c='鏈夊姽',
-            Intra_Trade_List_RMB_Date1__c=Date.today().addDays(-1),
-            Intra_Trade_List_RMB_Date2__c=Date.today().addDays(-1),
-            Intra_Trade_List_RMB_End_Date1__c=Date.today().addDays(1),
-            Intra_Trade_List_RMB_End_Date2__c=Date.today().addDays(1),
-            Intra_Trade_List_RMB_1__c=100,
-            Intra_Trade_List_RMB_2__c=200,
-            Intra_Trade_Cost_RMB_Date1__c=Date.today().addDays(-1),
-            Intra_Trade_Cost_RMB_Date2__c=Date.today().addDays(-1),
-            Intra_Trade_Cost_RMB_End_Date1__c=Date.today().addDays(1),
-            Intra_Trade_Cost_RMB_End_Date2__c=Date.today().addDays(1),
-            Intra_Trade_Cost_RMB_1__c=10,
-            Intra_Trade_Cost_RMB_2__c=20
+	@isTest static void test_init1() {
+		Id pricebookId = Test.getStandardPricebookId();
+
+        Pricebook2 pricebook = new Pricebook2(
+            Name = 'IE',
+            ProductSegment__c = 'IE',
+            TradeType__c = 'Taxation',
+            SalesChannel__c = 'direct',
+            MachineParts__c = 'Machine',
+            isActive = true
         );
-        Product2 pro2 = new Product2(
-	        Name='name02',
-	        IsActive=true,
-	        Asset_Model_No__c='n02',
-            MDM_Model_No__c='n02',
-	        ProductCode_Ext__c='pc02',
-            ProductCode = 'pc02',
-	        Manual_Entry__c=false,
-	        SFDA_Status__c='鏈夊姽',
-	        Intra_Trade_List_RMB_Date1__c=Date.today().addDays(-1),
-            Intra_Trade_List_RMB_Date2__c=Date.today().addDays(-1),
-	        Intra_Trade_List_RMB_End_Date1__c=Date.today().addDays(1),
-            Intra_Trade_List_RMB_End_Date2__c=Date.today().addDays(1),
-            Intra_Trade_List_RMB_1__c=100,
-            Intra_Trade_List_RMB_2__c=200,
-            Intra_Trade_Cost_RMB_Date1__c=Date.today().addDays(-1),
-            Intra_Trade_Cost_RMB_Date2__c=Date.today().addDays(-1),
-            Intra_Trade_Cost_RMB_End_Date1__c=Date.today().addDays(1),
-            Intra_Trade_Cost_RMB_End_Date2__c=Date.today().addDays(1),
-            Intra_Trade_Cost_RMB_1__c=10,
-            Intra_Trade_Cost_RMB_2__c=20
+        insert pricebook;
+
+        Product2 product1 = new Product2();
+        product1.Name = 'product1';
+        product1.ProductCode = 'product1';
+        product1.Product_ECCode__c = 'product1';
+        product1.ProductModels__c = true;
+        product1.ProductStatus__c = '1';
+        product1.MaterialStatus_one_Start__c = Date.today().addDays(-22);
+        product1.MaterialStatus_one_End__c = Date.today().addDays(22);
+        product1.NMPAStatus_one__c = 'Z1';
+        insert product1;
+
+        PricebookEntry standardPrice1 = new PricebookEntry(
+            Pricebook2Id = pricebookId,
+            Product2Id = product1.Id,
+            UnitPrice = 0,
+            IsActive = true
         );
-        insert new Product2[] {pro1, pro2};
-        
-        // 渚℃牸琛ㄣ偍銉炽儓銉倰浣滄垚銇欍倠        
-        PricebookEntry entry = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=pro1.Id);
-        entry.UnitPrice = 0;
-        entry.IsActive = true;
-        entry.UseStandardPrice = false;
-        entry.CurrencyIsoCode = 'CNY';
-        PricebookEntry entry2 = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=pro2.Id);
-        entry2.UnitPrice = 0;
-        entry2.IsActive = true;
-        entry2.UseStandardPrice = false;
-        entry2.CurrencyIsoCode = 'CNY';
-        
-        insert new PricebookEntry[] {entry, entry2};
-        
-        Apexpages.currentPage().getParameters().put('val', 'name');
-        Apexpages.Standardcontroller scon = new Apexpages.Standardcontroller(pro1);
-        SearchProductController controller = new SearchProductController(scon);
-        
+        insert standardPrice1;
+
+        PricebookEntry entry1 = new PricebookEntry(Pricebook2Id = pricebook.Id, Product2Id = product1.Id);
+        entry1.UnitPrice = 0;
+        entry1.IsActive = true;
+        entry1.UseStandardPrice = false;
+        insert entry1;
+
+        Product_Search__c ps = new Product_Search__c(Product__c = product1.Id);
+
+        List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];
+        Account user = new Account(
+            Name = '*',
+            FacilityName__c = 'user',
+            PostCode__c = '123456',
+            RecordTypeId = rectIE[0].Id
+        );
+        insert user;
+
+        Opportunity opp = new Opportunity(
+            Name = 'test opp',
+            AccountId = user.Id,
+            StageName = 'Prospect Created',
+            CurrencyIsoCode = 'CNY',
+            ProductSegment__c = 'IE',
+            CloseDate = Date.today(),
+            NewInquiryDate__c = Date.today().addDays(-2),
+            ExpectedOrderDate__c = Date.today().addDays(2),
+            TradeType__c = 'Taxation',
+            SalesChannel__c = 'direct',
+            Machine_Parts__c = 'Machine',
+            Pricebook2Id = pricebook.Id
+        );
+        insert opp;
+
+        PageReference page = new PageReference('/apex/SearchProduct?oppId=' + opp.Id + '&val=product1');
+        System.Test.setCurrentPage(page);
+        SearchProductController controller = new SearchProductController();
+
+        controller.init();
         controller.getHascl();
-        
-        controller.trade = 'CNY';
-        controller.serContact();
-        controller.trade = 'USD';
-        controller.serContact();
-        controller.trade = '';
-        controller.serContact();
-        
-        controller.cl = new List<SearchProductController.ProductLine>();
-		controller.cl.add(new SearchProductController.ProductLine(0,entry));        
-        
+	}
+
+    @isTest static void test_init2() {
+        NewReplacementOpportunityController.a();
+        Id pricebookId = Test.getStandardPricebookId();
+
+        Pricebook2 pricebook = new Pricebook2(
+            Name = 'IE',
+            ProductSegment__c = 'IE',
+            TradeType__c = 'Taxation',
+            SalesChannel__c = 'direct',
+            MachineParts__c = 'Machine',
+            isActive = true
+        );
+        insert pricebook;
+
+        Product2 product1 = new Product2();
+        product1.Name = 'product1';
+        product1.ProductCode = 'product1';
+        product1.Product_ECCode__c = 'product1';
+        product1.ProductModels__c = true;
+        product1.ProductStatus__c = '1';
+        product1.MaterialStatus_one_Start__c = Date.today().addDays(-22);
+        product1.MaterialStatus_one_End__c = Date.today().addDays(22);
+        product1.NMPAStatus_one__c = 'Z1';
+        insert product1;
+
+        PricebookEntry standardPrice1 = new PricebookEntry(
+            Pricebook2Id = pricebookId,
+            Product2Id = product1.Id,
+            UnitPrice = 0,
+            IsActive = true
+        );
+        insert standardPrice1;
+
+        PricebookEntry entry1 = new PricebookEntry(Pricebook2Id = pricebook.Id, Product2Id = product1.Id);
+        entry1.UnitPrice = 0;
+        entry1.IsActive = true;
+        entry1.UseStandardPrice = false;
+        insert entry1;
+
+        Product_Search__c ps = new Product_Search__c(Product__c = product1.Id);
+
+        List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];
+        Account user = new Account(
+            Name = '*',
+            FacilityName__c = 'user',
+            PostCode__c = '123456',
+            RecordTypeId = rectIE[0].Id
+        );
+        insert user;
+
+        Opportunity opp = new Opportunity(
+            Name = 'test opp',
+            AccountId = user.Id,
+            StageName = 'Prospect Created',
+            CurrencyIsoCode = 'CNY',
+            ProductSegment__c = 'IE',
+            CloseDate = Date.today(),
+            NewInquiryDate__c = Date.today().addDays(-2),
+            ExpectedOrderDate__c = Date.today().addDays(2),
+            TradeType__c = 'Taxation',
+            SalesChannel__c = 'direct',
+            Machine_Parts__c = 'Machine',
+            Pricebook2Id = pricebook.Id
+        );
+        insert opp;
+
+        PageReference page = new PageReference('/apex/SearchProduct?oppId=' + opp.Id + '&val=product1&openType=service&openFlag=opp');
+        System.Test.setCurrentPage(page);
+        SearchProductController controller = new SearchProductController();
+
+        controller.init();
+        controller.getHascl();
     }
-    
+
 }
\ No newline at end of file

--
Gitblit v1.9.1