Search in sources :

Example 6 with WordBlock

use of org.xwiki.rendering.block.WordBlock in project xwiki-platform by xwiki.

the class MessageToolTranslationMessageParserTest method messageWithOneParameter.

@Test
public void messageWithOneParameter() throws ComponentLookupException {
    TranslationMessage translationMessage = getMockedComponent().parse("{0}");
    Assert.assertEquals("{0}", translationMessage.getRawSource());
    Assert.assertEquals(new WordBlock("word"), translationMessage.render(null, null, "word"));
}
Also used : WordBlock(org.xwiki.rendering.block.WordBlock) TranslationMessage(org.xwiki.localization.message.TranslationMessage) Test(org.junit.Test)

Example 7 with WordBlock

use of org.xwiki.rendering.block.WordBlock in project xwiki-platform by xwiki.

the class MessageToolTranslationMessageParserTest method messageWithEscapedParameter.

@Test
public void messageWithEscapedParameter() throws ComponentLookupException {
    TranslationMessage translationMessage = getMockedComponent().parse("'{0}");
    Assert.assertEquals("'{0}", translationMessage.getRawSource());
    Assert.assertEquals(new CompositeBlock(Arrays.<Block>asList(new SpecialSymbolBlock('{'), new WordBlock("0"), new SpecialSymbolBlock('}'))), translationMessage.render(null, null, "word"));
}
Also used : SpecialSymbolBlock(org.xwiki.rendering.block.SpecialSymbolBlock) WordBlock(org.xwiki.rendering.block.WordBlock) CompositeBlock(org.xwiki.rendering.block.CompositeBlock) CompositeBlock(org.xwiki.rendering.block.CompositeBlock) WordBlock(org.xwiki.rendering.block.WordBlock) Block(org.xwiki.rendering.block.Block) SpecialSymbolBlock(org.xwiki.rendering.block.SpecialSymbolBlock) TranslationMessage(org.xwiki.localization.message.TranslationMessage) Test(org.junit.Test)

Example 8 with WordBlock

use of org.xwiki.rendering.block.WordBlock in project xwiki-platform by xwiki.

the class IntegrationTests method initialize.

@RenderingTestSuite.Initialized
public void initialize(MockingComponentManager componentManager) throws Exception {
    Mockery mockery = new JUnit4Mockery();
    final LocalizationManager localizationManager = componentManager.registerMockComponent(mockery, LocalizationManager.class);
    final LocalizationContext localizationContext = componentManager.registerMockComponent(mockery, LocalizationContext.class);
    mockery.checking(new Expectations() {

        {
            allowing(localizationManager).getTranslation("some.translation", Locale.ENGLISH);
            will(returnValue(new Translation() {

                @Override
                public Block render(Locale locale, Object... parameters) {
                    return parameters.length > 0 ? new WordBlock("entranslationmessage" + Arrays.toString(parameters)) : new WordBlock("entranslationmessage");
                }

                @Override
                public Block render(Object... parameters) {
                    return render(null, parameters);
                }

                @Override
                public String getRawSource() {
                    return "entranslationmessagesource";
                }

                @Override
                public Locale getLocale() {
                    return Locale.ENGLISH;
                }

                @Override
                public String getKey() {
                    return "some.translation";
                }

                @Override
                public TranslationBundle getBundle() {
                    return null;
                }
            }));
            allowing(localizationManager).getTranslation("some.translation", Locale.FRENCH);
            will(returnValue(new Translation() {

                @Override
                public Block render(Locale locale, Object... parameters) {
                    return parameters.length > 0 ? new WordBlock("frtranslationmessage" + Arrays.toString(parameters)) : new WordBlock("frtranslationmessage");
                }

                @Override
                public Block render(Object... parameters) {
                    return render(null, parameters);
                }

                @Override
                public String getRawSource() {
                    return "frtranslationmessagesource";
                }

                @Override
                public Locale getLocale() {
                    return Locale.FRENCH;
                }

                @Override
                public String getKey() {
                    return "some.translation";
                }

                @Override
                public TranslationBundle getBundle() {
                    return null;
                }
            }));
            allowing(localizationManager).getTranslation("unexisting.translation", Locale.ENGLISH);
            will(returnValue(null));
            allowing(localizationContext).getCurrentLocale();
            will(returnValue(Locale.ENGLISH));
        }
    });
}
Also used : Expectations(org.jmock.Expectations) Locale(java.util.Locale) Translation(org.xwiki.localization.Translation) LocalizationContext(org.xwiki.localization.LocalizationContext) WordBlock(org.xwiki.rendering.block.WordBlock) Mockery(org.jmock.Mockery) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) LocalizationManager(org.xwiki.localization.LocalizationManager) TranslationBundle(org.xwiki.localization.TranslationBundle) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) WordBlock(org.xwiki.rendering.block.WordBlock) Block(org.xwiki.rendering.block.Block)

Example 9 with WordBlock

use of org.xwiki.rendering.block.WordBlock in project xwiki-platform by xwiki.

the class InternalTemplateManager method generateError.

private XDOM generateError(Throwable throwable) {
    List<Block> errorBlocks = new ArrayList<Block>();
    // Add short message
    Map<String, String> errorBlockParams = Collections.singletonMap("class", "xwikirenderingerror");
    errorBlocks.add(new GroupBlock(Arrays.<Block>asList(new WordBlock("Failed to render step content")), errorBlockParams));
    // Add complete error
    StringWriter writer = new StringWriter();
    throwable.printStackTrace(new PrintWriter(writer));
    Block descriptionBlock = new VerbatimBlock(writer.toString(), false);
    Map<String, String> errorDescriptionBlockParams = Collections.singletonMap("class", "xwikirenderingerrordescription hidden");
    errorBlocks.add(new GroupBlock(Arrays.asList(descriptionBlock), errorDescriptionBlockParams));
    return new XDOM(errorBlocks);
}
Also used : XDOM(org.xwiki.rendering.block.XDOM) StringWriter(java.io.StringWriter) WordBlock(org.xwiki.rendering.block.WordBlock) ArrayList(java.util.ArrayList) GroupBlock(org.xwiki.rendering.block.GroupBlock) RawBlock(org.xwiki.rendering.block.RawBlock) VerbatimBlock(org.xwiki.rendering.block.VerbatimBlock) Block(org.xwiki.rendering.block.Block) WordBlock(org.xwiki.rendering.block.WordBlock) GroupBlock(org.xwiki.rendering.block.GroupBlock) VerbatimBlock(org.xwiki.rendering.block.VerbatimBlock) PrintWriter(java.io.PrintWriter)

Example 10 with WordBlock

use of org.xwiki.rendering.block.WordBlock in project xwiki-platform by xwiki.

the class MacroBlockDumperTest method testIllegalArgumentException.

@Test
public void testIllegalArgumentException() throws Exception {
    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage("Unsupported block [org.xwiki.rendering.block.WordBlock].");
    dumper.dump(new WordBlock("macro"));
}
Also used : WordBlock(org.xwiki.rendering.block.WordBlock) Test(org.junit.Test)

Aggregations

WordBlock (org.xwiki.rendering.block.WordBlock)24 Test (org.junit.Test)13 Block (org.xwiki.rendering.block.Block)13 XDOM (org.xwiki.rendering.block.XDOM)8 DocumentReference (org.xwiki.model.reference.DocumentReference)6 TranslationMessage (org.xwiki.localization.message.TranslationMessage)5 ArrayList (java.util.ArrayList)4 HeaderBlock (org.xwiki.rendering.block.HeaderBlock)4 LinkBlock (org.xwiki.rendering.block.LinkBlock)4 ParagraphBlock (org.xwiki.rendering.block.ParagraphBlock)4 SpecialSymbolBlock (org.xwiki.rendering.block.SpecialSymbolBlock)4 EntityReference (org.xwiki.model.reference.EntityReference)3 IdBlock (org.xwiki.rendering.block.IdBlock)3 SectionBlock (org.xwiki.rendering.block.SectionBlock)3 WikiPrinter (org.xwiki.rendering.renderer.printer.WikiPrinter)3 Reader (java.io.Reader)2 StringReader (java.io.StringReader)2 List (java.util.List)2 Expectations (org.jmock.Expectations)2 Mockery (org.jmock.Mockery)2