From a0b08c607308c8f4f0298f796cf53958f7f6fbe3 Mon Sep 17 00:00:00 2001 From: DemeritCowboy Date: Mon, 12 Aug 2019 17:44:57 -0400 Subject: [PATCH] demonstrate isNull --- tests/phpunit/CRM/Utils/SystemTest.php | 64 ++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/tests/phpunit/CRM/Utils/SystemTest.php b/tests/phpunit/CRM/Utils/SystemTest.php index 602184984ee9..ea129b0fbae3 100644 --- a/tests/phpunit/CRM/Utils/SystemTest.php +++ b/tests/phpunit/CRM/Utils/SystemTest.php @@ -114,4 +114,68 @@ public function getURLs() { ]; } + /** + * Demonstrate the, um, "flexibility" of isNull + */ + public function testIsNull() { + $this->assertTrue(CRM_Utils_System::isNull(NULL)); + $this->assertTrue(CRM_Utils_System::isNull('')); + $this->assertTrue(CRM_Utils_System::isNull('null')); + // Not sure how to test this one because phpunit itself throws an error. + // $this->assertTrue(CRM_Utils_System::isNull($someUnsetVariable)); + + // but... + $this->assertFalse(CRM_Utils_System::isNull('NULL')); + $this->assertFalse(CRM_Utils_System::isNull('Null')); + + // probably ok? + $this->assertTrue(CRM_Utils_System::isNull([])); + + // ok + $this->assertFalse(CRM_Utils_System::isNull(0)); + + // sure + $arr = [ + 1 => NULL, + ]; + $this->assertTrue(CRM_Utils_System::isNull($arr[1])); + $this->assertTrue(CRM_Utils_System::isNull($arr)); + + // but then a little confusing + $arr = [ + 'IN' => NULL, + ]; + $this->assertFalse(CRM_Utils_System::isNull($arr)); + + // now just guessing + $obj = new StdClass(); + $this->assertFalse(CRM_Utils_System::isNull($obj)); + $obj->anything = NULL; + $this->assertFalse(CRM_Utils_System::isNull($obj)); + + // this is ok + $arr = [ + 1 => [ + 'foo' => 'bar', + ], + 2 => [ + 'a' => NULL, + ], + ]; + $this->assertFalse(CRM_Utils_System::isNull($arr)); + + $arr = [ + 1 => $obj, + ]; + $this->assertFalse(CRM_Utils_System::isNull($arr)); + + // sure + $arr = [ + 1 => NULL, + 2 => '', + 3 => 'null', + ]; + $this->assertTrue(CRM_Utils_System::isNull($arr)); + } + }