/** * Asserts correct field access grants for a field. */ public function assertFieldAccess($field, $viewer, $target, $view, $edit) { $field_definition = $this->getMock('Drupal\\Core\\Field\\FieldDefinitionInterface'); $field_definition->expects($this->any())->method('getName')->will($this->returnValue($field)); $this->items->expects($this->any())->method('getEntity')->will($this->returnValue($this->{$target})); foreach (array('view' => $view, 'edit' => $edit) as $operation => $result) { $message = SafeMarkup::format("User @field field access returns @result with operation '@op' for @account accessing @target", array('@field' => $field, '@result' => !isset($result) ? 'null' : ($result ? 'true' : 'false'), '@op' => $operation, '@account' => $viewer, '@target' => $target)); $this->assertSame($result, $this->accessControlHandler->fieldAccess($operation, $field_definition, $this->{$viewer}, $this->items), $message); } }
/** * Asserts correct field access grants for a field. */ public function assertFieldAccess($field, $viewer, $target, $view, $edit) { $field_definition = $this->getMock('Drupal\\Core\\Field\\FieldDefinitionInterface'); $field_definition->expects($this->any())->method('getName')->will($this->returnValue($field)); $this->items->expects($this->any())->method('getEntity')->will($this->returnValue($this->{$target})); foreach (array('view' => $view, 'edit' => $edit) as $operation => $result) { $result_text = !isset($result) ? 'null' : ($result ? 'true' : 'false'); $message = "User '{$field}' field access returns '{$result_text}' with operation '{$operation}' for '{$viewer}' accessing '{$target}'"; $this->assertSame($result, $this->accessControlHandler->fieldAccess($operation, $field_definition, $this->{$viewer}, $this->items), $message); } }