Mathijs den Burger pushed to branch feature/visual-editing-psp2-CHANNELMGR-1234 at cms-community / hippo-addon-channel-manager
Commits: 46a97398 by Mathijs den Burger at 2017-04-18T15:33:04+02:00 CHANNELMGR-1234 Add unit tests for rich text field choice - - - - - 1 changed file: - content-service/src/test/java/org/onehippo/cms/channelmanager/content/documenttype/field/type/ChoiceFieldUtilsTest.java Changes: ===================================== content-service/src/test/java/org/onehippo/cms/channelmanager/content/documenttype/field/type/ChoiceFieldUtilsTest.java ===================================== --- a/content-service/src/test/java/org/onehippo/cms/channelmanager/content/documenttype/field/type/ChoiceFieldUtilsTest.java +++ b/content-service/src/test/java/org/onehippo/cms/channelmanager/content/documenttype/field/type/ChoiceFieldUtilsTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Hippo B.V. (http://www.onehippo.com) + * Copyright 2016-2017 Hippo B.V. (http://www.onehippo.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -276,6 +276,47 @@ public class ChoiceFieldUtilsTest { } @Test + public void initProviderIdWithValidRichTextChoice() throws Exception { + final Node node = MockNode.root(); + final ContentTypeContext parentContext = createMock(ContentTypeContext.class); + final Map<String, NodeFieldType> choices = new HashMap<>(); + final ContentType provider = createMock(ContentType.class); + final Map<String, ContentTypeChild> choiceMap = new HashMap<>(); + final ContentTypeChild choice = createMock(ContentTypeChild.class); + final ContentType compound = createMock(ContentType.class); + final FieldTypeContext compoundContext = PowerMock.createMockAndExpectNew(FieldTypeContext.class, choice, parentContext); + final RichTextFieldType richTextField = PowerMock.createMockAndExpectNew(RichTextFieldType.class); + + PowerMock.mockStaticPartial(ContentTypeContext.class, "getContentType"); + + node.setProperty("cpItemsPath", "choice:provider"); + expect(ContentTypeContext.getContentType("choice:provider")).andReturn(Optional.of(provider)); + expect(provider.getChildren()).andReturn(choiceMap); + + choiceMap.put("choice", choice); + expect(choice.getItemType()).andReturn("choiceType").anyTimes(); + expect(ContentTypeContext.getContentType("choiceType")).andReturn(Optional.of(compound)); + expect(compound.isCompoundType()).andReturn(false).times(2); + expect(compound.isContentType("hippostd:html")).andReturn(true).times(2); + + richTextField.init(compoundContext); + expectLastCall(); + + expect(compoundContext.createContextForCompound()).andReturn(Optional.empty()); + + replay(provider, choice, compound); + PowerMock.replayAll(); + + ChoiceFieldUtils.populateProviderBasedChoices(node, parentContext, choices); + + verify(provider, choice, compound); + PowerMock.verifyAll(); + + assertThat(choices.size(), equalTo(1)); + assertThat(choices.get("choiceType"), equalTo(richTextField)); + } + + @Test public void populateListBasedChoicesWithoutCompoundList() { final Node node = MockNode.root(); final ContentTypeContext parentContext = createMock(ContentTypeContext.class); @@ -436,4 +477,40 @@ public class ChoiceFieldUtilsTest { assertThat(choices.size(), equalTo(1)); assertThat(choices.get("compound:id"), equalTo(compoundField)); } + + @Test + public void populateListBasedChoicesWithValidRichText() throws Exception { + final Node node = MockNode.root(); + final ContentTypeContext parentContext = createMock(ContentTypeContext.class); + final Map<String, NodeFieldType> choices = new HashMap<>(); + final ContentTypeContext childContext = createMock(ContentTypeContext.class); + final ContentType compound = createMock(ContentType.class); + final RichTextFieldType richTextField = PowerMock.createMockAndExpectNew(RichTextFieldType.class); + + PowerMock.mockStaticPartial(ContentTypeContext.class, "createFromParent"); + PowerMock.mockStaticPartial(FieldTypeUtils.class, "populateFields"); + + node.setProperty("compoundList", "prefixed:choice"); + expect(ContentTypeContext.createFromParent("prefixed:choice", parentContext)).andReturn(Optional.of(childContext)); + expect(childContext.getContentType()).andReturn(compound).anyTimes(); + expect(compound.isCompoundType()).andReturn(false).times(2); + expect(compound.isContentType("hippostd:html")).andReturn(true).times(2); + expect(compound.getName()).andReturn("hippostd:html"); + + richTextField.initListBasedChoice("hippostd:html"); + expectLastCall(); + + expect(richTextField.getDisplayName()).andReturn("bla"); + + replay(parentContext, childContext, compound); + PowerMock.replayAll(); + + ChoiceFieldUtils.populateListBasedChoices(node, parentContext, choices); + + verify(parentContext, childContext, compound); + PowerMock.verifyAll(); + + assertThat(choices.size(), equalTo(1)); + assertThat(choices.get("hippostd:html"), equalTo(richTextField)); + } } View it on GitLab: https://code.onehippo.org/cms-community/hippo-addon-channel-manager/commit/46a9739809d948052526bf358ea16a823b5182ba
_______________________________________________ Hippocms-svn mailing list Hippocms-svn@lists.onehippo.org https://lists.onehippo.org/mailman/listinfo/hippocms-svn