Search in sources :

Example 1 with RecordNameManager

use of org.orcid.core.manager.RecordNameManager in project ORCID-Source by ORCID.

the class ManageProfileControllerTest method testStripHtmlFromNames.

@Test
public void testStripHtmlFromNames() throws NoSuchRequestHandlingMethodException {
    RecordNameManager mockRecordNameManager = Mockito.mock(RecordNameManager.class);
    SecurityContextHolder.getContext().setAuthentication(getAuthentication(USER_ORCID));
    TargetProxyHelper.injectIntoProxy(controller, "recordNameManager", mockRecordNameManager);
    when(mockRecordNameManager.exists(Mockito.anyString())).thenReturn(true);
    NamesForm nf = new NamesForm();
    nf.setCreditName(Text.valueOf("<button onclick=\"alert('hello')\">Credit Name</button>"));
    nf.setGivenNames(Text.valueOf("<button onclick=\"alert('hello')\">Given Names</button>"));
    nf.setFamilyName(Text.valueOf("<button onclick=\"alert('hello')\">Family Name</button>"));
    nf = controller.setNameFormJson(nf);
    assertEquals("Credit Name", nf.getCreditName().getValue());
    assertEquals("Given Names", nf.getGivenNames().getValue());
    assertEquals("Family Name", nf.getFamilyName().getValue());
    Name name = new Name();
    name.setCreditName(new CreditName("Credit Name"));
    name.setFamilyName(new FamilyName("Family Name"));
    name.setGivenNames(new GivenNames("Given Names"));
    name.setVisibility(Visibility.PUBLIC);
    verify(mockRecordNameManager, times(1)).updateRecordName(Mockito.eq(USER_ORCID), Mockito.eq(name));
}
Also used : RecordNameManager(org.orcid.core.manager.RecordNameManager) FamilyName(org.orcid.jaxb.model.record_v2.FamilyName) GivenNames(org.orcid.jaxb.model.record_v2.GivenNames) CreditName(org.orcid.jaxb.model.common_v2.CreditName) NamesForm(org.orcid.pojo.ajaxForm.NamesForm) FamilyName(org.orcid.jaxb.model.record_v2.FamilyName) CreditName(org.orcid.jaxb.model.common_v2.CreditName) Name(org.orcid.jaxb.model.record_v2.Name) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 RecordNameManager (org.orcid.core.manager.RecordNameManager)1 CreditName (org.orcid.jaxb.model.common_v2.CreditName)1 FamilyName (org.orcid.jaxb.model.record_v2.FamilyName)1 GivenNames (org.orcid.jaxb.model.record_v2.GivenNames)1 Name (org.orcid.jaxb.model.record_v2.Name)1 NamesForm (org.orcid.pojo.ajaxForm.NamesForm)1