Search in sources :

Example 1 with TextComponent

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")));
}
Also used : TextComponent(com.enonic.xp.region.TextComponent) PageDescriptor(com.enonic.xp.page.PageDescriptor) PropertyTree(com.enonic.xp.data.PropertyTree) EditableContent(com.enonic.xp.content.EditableContent) Page(com.enonic.xp.page.Page) Test(org.junit.jupiter.api.Test)

Example 2 with TextComponent

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"));
}
Also used : TextComponent(com.enonic.xp.region.TextComponent) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) Test(org.junit.jupiter.api.Test)

Example 3 with TextComponent

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());
}
Also used : TextComponent(com.enonic.xp.region.TextComponent) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) Test(org.junit.jupiter.api.Test)

Example 4 with TextComponent

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();
}
Also used : TextComponent(com.enonic.xp.region.TextComponent) PropertySet(com.enonic.xp.data.PropertySet)

Aggregations

TextComponent (com.enonic.xp.region.TextComponent)4 PropertySet (com.enonic.xp.data.PropertySet)3 PropertyTree (com.enonic.xp.data.PropertyTree)3 Test (org.junit.jupiter.api.Test)3 EditableContent (com.enonic.xp.content.EditableContent)1 Page (com.enonic.xp.page.Page)1 PageDescriptor (com.enonic.xp.page.PageDescriptor)1