diff --git a/services/Record/RecordUtils.php b/services/Record/RecordUtils.php index 115c990..cb8eb9f 100644 --- a/services/Record/RecordUtils.php +++ b/services/Record/RecordUtils.php @@ -147,7 +147,16 @@ function ht_link_data_from_json($e) { $rv['has_activated_role'] = $htstatus->has_activated_role && (!$rv['is_fullview'] && (!$open_to_no_one)); - $rv['role_name'] = $htstatus->has_activated_role ? array_keys($htstatus->r)[0] : NULL; + # has_activated_role can be true if sssduser, and r will not be set in that case. + # Hence the check on $htstatus->r + $rv['role_name'] = NULL; # default + if ( + $htstatus->has_activated_role + && $htstatus->r + && count(array_keys($htstatus->r)) > 0 + ) { + $rv['role_name'] = array_keys($htstatus->r)[0]; + } return $rv; } diff --git a/test/RecordUtilsTest.php b/test/RecordUtilsTest.php index 15d0e22..9f2234d 100644 --- a/test/RecordUtilsTest.php +++ b/test/RecordUtilsTest.php @@ -152,6 +152,34 @@ public function test_ht_link_data_from_json_activated_role(): void { $this->assertEquals('resourceSharing', $data['role_name']); } + /** + * @covers RecordUtils::ht_link_data_from_json + * @runInSeparateProcess + + ssduser results in activated role set to true but no role name, because ping + Clearly this is not optimal + */ + public function test_ht_link_data_from_json_ssduser(): void { + global $htstatus; + # Setup for VFSession.php and DSession.php + $_SERVER['HTTP_HOST'] = 'localhost'; + $_SERVER['SERVER_ADDR'] = '127.0.0.1'; + $sample_json = array( + 'rights' => 'ic', + 'htid' => 'mdp.001', + 'collection_code' => 'miu', + 'enumcron' => 'v.1', + 'heldby' => array('umich'), + ); + $utils = new RecordUtils(); + $htstatus->r = NULL; + $htstatus->u = true; + $htstatus->has_activated_role = true; + $data = $utils->ht_link_data_from_json($sample_json); + $this->assertEquals(true, $data['has_activated_role']); + $this->assertEquals(NULL, $data['role_name']); + } + /** * @covers RecordUtils::is_fullview */