Add extra test, comment how it could be used to fix bug
authorEileen McNaughton <emcnaughton@wikimedia.org>
Mon, 6 Feb 2023 03:49:26 +0000 (16:49 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Mon, 6 Feb 2023 08:03:17 +0000 (21:03 +1300)
I was working on fixing the ongoing log noise in the tested scenario - but
the first PR https://github.com/civicrm/civicrm-core/pull/25392 is still
pending so I decided just to put up the test with the sign posts
so at least that part is done for the next time someone tries
(I know that people have tried in the past)

CRM/Contact/Selector.php
tests/phpunit/CRM/Contact/Form/Search/BasicTest.php [new file with mode: 0644]
tests/phpunit/CiviTest/CiviUnitTestCase.php

index cb85daa4f27ba774f6f6927cc8c59f0294c256ff..54282ce74bb086029a596691b02826a9da95f5ac 100644 (file)
@@ -1025,6 +1025,12 @@ class CRM_Contact_Selector extends CRM_Core_Selector_Base implements CRM_Core_Se
    * @param int $start
    * @param int $end
    *
+   * @todo - use test cover in CRM_Contact_Form_Search_BasicTest to
+   * to remove the extraneous logging that happens in the tested
+   * scenario (It does the catch & then write to the log - I was
+   * going to fix but got stalled on getting https://github.com/civicrm/civicrm-core/pull/25392
+   * merged - this comment won't conflict with that PR :-)
+   *
    * @throws \CRM_Core_Exception
    */
   public function fillupPrevNextCache($sort, $cacheKey, $start = 0, $end = self::CACHE_SIZE) {
diff --git a/tests/phpunit/CRM/Contact/Form/Search/BasicTest.php b/tests/phpunit/CRM/Contact/Form/Search/BasicTest.php
new file mode 100644 (file)
index 0000000..ee7953f
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+
+/*
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC. All rights reserved.                        |
+ |                                                                    |
+ | This work is published under the GNU AGPLv3 license with some      |
+ | permitted exceptions and without any warranty. For full license    |
+ | and copyright information, see https://civicrm.org/licensing       |
+ +--------------------------------------------------------------------+
+ */
+
+/**
+ * Test class for CRM_Contact_Form_Basic
+ *
+ * @package CiviCRM
+ * @group headless
+ */
+class CRM_Contact_Form_Search_BasicTest extends CiviUnitTestCase {
+
+  /**
+   * Test the BasicSearch form.
+   *
+   * @todo - this test passes but it tests a scenario we would
+   * ideally deprecate - ie coming up with a search that won't work,
+   * trying it, logging an error, and then trying something that does work.
+   */
+  public function testBasicSearch(): void {
+    /* @var CRM_Contact_Form_Search_Basic $form */
+    $form = $this->getFormObject('CRM_Contact_Form_Search_Basic');
+    $form->setAction(CRM_Core_Action::BASIC);
+    // Order by the 5th field (ie country) descending.
+    $_GET['crmSID'] = '5_d';
+    $form->preProcess();
+    $form->buildQuickForm();
+    $form->postProcess();
+  }
+
+}
index 21115e2c0380d98537fdbfaecd0066406940fbb7..0d458f10ac1a9dd030683d8120d6cf41dc93cab6 100644 (file)
@@ -3226,6 +3226,10 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase {
         $_SESSION['_' . $form->controller->_name . '_container']['values']['Preview'] = $formValues;
         return $form;
 
+      case strpos($class, 'Search') !== FALSE:
+        $form->controller = new CRM_Contact_Controller_Search();
+        break;
+
       case strpos($class, '_Form_') !== FALSE:
         $form->controller = new CRM_Core_Controller_Simple($class, $pageName);
         break;