CRM_Core_Key - Add some basic unit tests
authorTim Otten <totten@civicrm.org>
Fri, 11 Dec 2020 22:08:46 +0000 (14:08 -0800)
committerTim Otten <totten@civicrm.org>
Fri, 11 Dec 2020 22:08:46 +0000 (14:08 -0800)
tests/phpunit/CRM/Core/KeyTest.php [new file with mode: 0644]

diff --git a/tests/phpunit/CRM/Core/KeyTest.php b/tests/phpunit/CRM/Core/KeyTest.php
new file mode 100644 (file)
index 0000000..66e9504
--- /dev/null
@@ -0,0 +1,36 @@
+<?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       |
+ +--------------------------------------------------------------------+
+ */
+
+/**
+ * Class CRM_Core_KeyTest
+ * @group headless
+ */
+class CRM_Core_KeyTest extends CiviUnitTestCase {
+
+  public function testOK() {
+    $key = CRM_Core_Key::get('CRM_Bread_Butter');
+    $this->assertTrue(CRM_Core_Key::valid($key));
+    $this->assertEquals($key, CRM_Core_Key::validate($key, 'CRM_Bread_Butter'));
+  }
+
+  public function testMalformed() {
+    $key = CRM_Core_Key::get('CRM_Bread_Butter') . '<script>';
+    $this->assertFalse(CRM_Core_Key::valid($key));
+    $this->assertEquals(NULL, CRM_Core_Key::validate($key, 'CRM_Bread_Butter'));
+  }
+
+  public function testMixedUp() {
+    $key = CRM_Core_Key::get('CRM_Toast_Jam');
+    $this->assertTrue(CRM_Core_Key::valid($key));
+    $this->assertEquals(NULL, CRM_Core_Key::validate($key, 'CRM_Bread_Butter'));
+  }
+
+}