22
33namespace Asciisd \Zoho \Tests \Integration ;
44
5- use Asciisd \Zoho \Facades \ZohoManager ;
65use Asciisd \Zoho \ZohoModule ;
76use zcrmsdk \crm \crud \ZCRMModule ;
87use zcrmsdk \crm \crud \ZCRMRecord ;
8+ use Asciisd \Zoho \CriteriaBuilder ;
9+ use Asciisd \Zoho \Facades \ZohoManager ;
910use zcrmsdk \crm \exception \ZCRMException ;
1011
1112class ZohoModuleTest extends IntegrationTestCase
@@ -15,123 +16,123 @@ class ZohoModuleTest extends IntegrationTestCase
1516 private $ client ;
1617 private $ module ;
1718
18- protected function setUp (): void
19- {
20- parent ::setUp ();
21-
22- $ this ->client = $ this ->getClient ();
23- $ this ->module = $ this ->client ->useModule ('Leads ' );
24- }
25-
2619 /** @test */
27- public function it_can_get_all_modules ()
28- {
20+ public function it_can_get_all_modules () {
2921 $ leads = $ this ->client ->getAllModules ();
3022
3123 self ::assertInstanceOf (ZCRMModule::class, $ leads [0 ]);
3224 }
3325
3426 /** @test */
35- public function is_can_get_module_by_name ()
36- {
27+ public function is_can_get_module_by_name () {
3728 $ leads = $ this ->client ->useModule ();
3829
3930 self ::assertInstanceOf (ZohoModule::class, $ leads );
4031 }
4132
4233 /** @test */
43- public function it_can_instantiate_a_record_with_id ()
44- {
34+ public function it_can_instantiate_a_record_with_id () {
4535 $ record = $ this ->module ->getRecordInstance (self ::LEAD_ID_FOR_TEST );
4636 self ::assertInstanceOf (ZCRMRecord::class, $ record );
4737 self ::assertEquals ('Leads ' , $ record ->getModuleApiName ());
4838 self ::assertEquals (self ::LEAD_ID_FOR_TEST , $ record ->getEntityId ());
4939 }
5040
5141 /** @test */
52- public function it_can_instantiate_a_module_with_api_name ()
53- {
42+ public function it_can_instantiate_a_module_with_api_name () {
5443 $ module = $ this ->module ->getModuleInstance ();
5544 self ::assertInstanceOf (ZCRMModule::class, $ module );
5645 self ::assertEquals ('Leads ' , $ module ->getAPIName ());
5746 }
5847
5948 /** @test */
60- public function it_can_get_records_for_given_module_api_name ()
61- {
49+ public function it_can_get_records_for_given_module_api_name () {
6250 $ records = $ this ->module ->getRecords ();
6351 self ::assertInstanceOf (ZCRMRecord::class, $ records [0 ]);
6452 }
6553
6654 /** @test */
67- public function it_can_get_record_by_module_api_name_and_record_id ()
68- {
55+ public function it_can_get_record_by_module_api_name_and_record_id () {
6956 $ record = $ this ->module ->getRecord (self ::LEAD_ID_FOR_TEST );
7057 self ::assertInstanceOf (ZCRMRecord::class, $ record );
7158 }
7259
7360 /** @test */
74- public function it_can_search_for_word_on_specific_module ()
75- {
61+ public function it_can_search_for_word_on_specific_module () {
7662 $ records = $ this ->module ->searchRecordsByWord ('Amr Ahmed ' );
7763
7864 self ::assertInstanceOf (ZCRMRecord::class, end ($ records ));
79- self ::assertEquals (self ::LEAD_ID_FOR_TEST , end ($ records )->getEntityId ());
65+ self ::assertEquals (self ::LEAD_ID_FOR_TEST ,
66+ end ($ records )->getEntityId ());
8067 }
8168
8269 /** @test */
83- public function it_can_search_for_phone_on_specific_module ()
84- {
70+ public function it_can_search_for_phone_on_specific_module () {
8571 $ records = $ this ->module ->searchRecordsByPhone ('01011441444 ' );
8672
73+ dump ($ records ->getData ());
74+
8775 self ::assertInstanceOf (ZCRMRecord::class, $ records [0 ]);
8876 self ::assertEquals ('01011441444 ' , $ records [0 ]->getFieldValue ('Phone ' ));
8977 }
9078
9179 /** @test */
92- public function it_can_search_for_email_on_specific_module ()
93- {
80+ public function it_can_search_for_email_on_specific_module () {
9481 $ records = $ this ->module ->searchRecordsByEmail ('aemaddin@gmail.com ' );
9582
9683 self ::assertInstanceOf (ZCRMRecord::class, $ records [0 ]);
97- self ::assertEquals ('aemaddin@gmail.com ' , $ records [0 ]->getFieldValue ('Email ' ));
84+ self ::assertEquals ('aemaddin@gmail.com ' ,
85+ $ records [0 ]->getFieldValue ('Email ' ));
86+ }
87+
88+ /** @test */
89+ public function it_can_search_by_criteria () {
90+ $ records =
91+ $ this ->module ->searchRecordsByCriteria ("(City:equals:Al Wasitah) and (State:equals:Al Fayyum) " );
92+
93+ self ::assertInstanceOf (ZCRMRecord::class, $ records [0 ]);
94+ self ::assertEquals ('falah.alhajeri6999@hotmail.com ' ,
95+ $ records [0 ]->getFieldValue ('Email ' ));
9896 }
9997
10098 /** @test */
101- public function it_can_search_by_criteria ()
102- {
103- $ records = $ this ->module ->searchRecordsByCriteria ("(City:equals:Al Wasitah) and (State:equals:Al Fayyum) " );
99+ function it_can_search_by_criteria_builder () {
100+ $ records =
101+ ZohoManager::useModule ('Contacts ' )->search (
102+ CriteriaBuilder::where ('City ' , 'Al Wasitah ' )
103+ ->andWhere ('State ' , 'Al Fayyum ' )
104+ );
104105
105106 self ::assertInstanceOf (ZCRMRecord::class, $ records [0 ]);
106- self ::assertEquals ('falah.alhajeri6999@hotmail.com ' , $ records [0 ]->getFieldValue ('Email ' ));
107+ self ::assertEquals ('falah.alhajeri6999@hotmail.com ' ,
108+ $ records [0 ]->getFieldValue ('Email ' ));
107109 }
108110
109111 /** @test */
110- public function it_can_search_by_field_name ()
111- {
112+ public function it_can_search_by_field_name () {
112113 $ records = $ this ->module ->where ('City ' , 'Al Wasitah ' )->search ();
113114
114115 self ::assertInstanceOf (ZCRMRecord::class, $ records [0 ]);
115- self ::assertEquals ('falah.alhajeri6999@hotmail.com ' , $ records [0 ]->getFieldValue ('Email ' ));
116+ self ::assertEquals ('falah.alhajeri6999@hotmail.com ' ,
117+ $ records [0 ]->getFieldValue ('Email ' ));
116118 }
117119
118120 /** @test */
119- public function it_can_search_with_multiple_criteria ()
120- {
121+ public function it_can_search_with_multiple_criteria () {
121122 $ records = $ this ->module
122123 ->where ('City ' , 'Al Wasitah ' )
123124 ->andWhere ('State ' , 'Al Fayyum ' )
124125 ->search ();
125126
126127 self ::assertInstanceOf (ZCRMRecord::class, $ records [0 ]);
127- self ::assertEquals ('falah.alhajeri6999@hotmail.com ' , $ records [0 ]->getFieldValue ('Email ' ));
128+ self ::assertEquals ('falah.alhajeri6999@hotmail.com ' ,
129+ $ records [0 ]->getFieldValue ('Email ' ));
128130 }
129131
130132 /** @test
131133 * @throws ZCRMException
132134 */
133- public function it_can_create_new_record ()
134- {
135+ public function it_can_create_new_record () {
135136 $ lead = $ this ->module ->getRecordInstance ();
136137
137138 $ lead ->setFieldValue ('First_Name ' , 'Amr ' );
@@ -152,8 +153,7 @@ public function it_can_create_new_record()
152153 /** @test
153154 * @throws ZCRMException
154155 */
155- public function it_can_update_records ()
156- {
156+ public function it_can_update_records () {
157157 $ lead = $ this ->module ->getRecord ('3582074000002383003 ' );
158158
159159 $ lead ->setFieldValue ('Last_Name ' , 'Ahmed ' );
@@ -167,4 +167,11 @@ public function it_can_fetch_nested_data_with_module() {
167167 $ contacts = ZohoManager::useModule ('Contacts ' );
168168 $ contacts ->getAllModules ();
169169 }
170+
171+ protected function setUp (): void {
172+ parent ::setUp ();
173+
174+ $ this ->client = $ this ->getClient ();
175+ $ this ->module = $ this ->client ->useModule ('Leads ' );
176+ }
170177}
0 commit comments