use of com.enonic.xp.region.TextComponent in project xp by enonic.
the class HtmlAreaContentProcessorTest method text_component_value.
@Test
public void text_component_value() throws IOException {
// final PropertyTree data = new PropertyTree();
// data.addProperty( "htmlData", ValueFactory.newString( "<img data-src=\"image://image-id\"/>" ) );
// final Form form = Form.create().addFormItem(
// Input.create().name( "htmlData" ).label( "htmlData" ).inputType( InputTypeName.HTML_AREA ).build() ).build();
// final PartDescriptor partDescriptor = PartDescriptor.create().key( DescriptorKey.from( "app:part" ) ).config( form ).build();
// Mockito.when( partDescriptorService.getByKey( partDescriptor.getKey() ) ).thenReturn( partDescriptor );
final TextComponent textComponent = TextComponent.create().text("<img data-src=\"image://image-id\"/>").build();
final PageDescriptor pageDescriptor = PageDescriptor.create().regions(RegionDescriptors.create().add(RegionDescriptor.create().name("region").build()).build()).key(DescriptorKey.from("app:page")).config(Form.create().build()).build();
Mockito.when(pageDescriptorService.getByKey(pageDescriptor.getKey())).thenReturn(pageDescriptor);
final Page page = Page.create().config(new PropertyTree()).descriptor(pageDescriptor.getKey()).regions(PageRegions.create().add(Region.create().name("region").add(textComponent).build()).build()).build();
final EditableContent editableContent = new EditableContent(Media.create().name("myContentName").type(contentTypeName).page(page).parentPath(ContentPath.ROOT).data(new PropertyTree()).build());
result.getEditor().edit(editableContent);
assertEquals(1, editableContent.processedReferences.build().getSize());
assertTrue(editableContent.processedReferences.build().contains(ContentId.from("image-id")));
}
use of com.enonic.xp.region.TextComponent in project xp by enonic.
the class TextComponentDataSerializerTest method toData.
@Test
public void toData() {
// setup
final String text = "some text";
final TextComponent textComponent = TextComponent.create().text(text).build();
final PropertyTree tree = new PropertyTree();
// exercise
new TextComponentDataSerializer().toData(textComponent, tree.getRoot());
// verify
final PropertySet set = tree.getSet(COMPONENTS);
assertEquals(TextComponentType.INSTANCE.toString(), set.getString(TYPE));
assertEquals(text, set.getSet(TextComponentType.INSTANCE.toString()).getString("value"));
}
use of com.enonic.xp.region.TextComponent in project xp by enonic.
the class TextComponentDataSerializerTest method fromData.
@Test
public void fromData() {
// setup
final String text = "some text";
final PropertySet data = new PropertyTree().addSet(COMPONENTS);
data.setString(TYPE, TextComponentType.INSTANCE.toString());
final PropertySet specBlock = data.addSet(TextComponentType.INSTANCE.toString());
specBlock.addString("value", text);
// exercise
final TextComponent textComponent = new TextComponentDataSerializer().fromData(data);
// verify
assertEquals("Text", textComponent.getName().toString());
assertEquals(text, textComponent.getText());
}
use of com.enonic.xp.region.TextComponent in project xp by enonic.
the class TextComponentDataSerializer method fromData.
@Override
public TextComponent fromData(final PropertySet data) {
final TextComponent.Builder component = TextComponent.create();
final PropertySet specialBlockSet = data.getSet(TextComponentType.INSTANCE.toString());
if (specialBlockSet != null && specialBlockSet.isNotNull(VALUE)) {
component.text(specialBlockSet.getString(VALUE));
}
return component.build();
}
Aggregations