public function testMultiArrayAccessMethodChain() { $node = new Document(); $model = new ContentModel(); $node->setData('foo', [1 => [2 => $model]]); $this->assertEquals($model->getCssClass(), ExpressionEvaluator::evaluate($node, 'foo[1]->bar[2]->getCssClass()')); }
public function testThisModelExpression() { $expected = new Document(); $expected->setAttribute('foo', 'bar'); $expression = new ModelEvaluationExpression('this', $expected); /* @var $result DomNode */ $result = $expression->getResult(); $this->assertEquals($expected, $result); $this->assertEquals($expected->getAttribute('foo'), $result->getAttribute('foo')); }
public function onParseTime() { $name = $this->getRequiredAttribute('name'); $group = $this->getAttribute('group'); if ($group === null || $group == '') { $group = 'message'; } $show = false; if ($this->getAttribute('show') == 'true') { $show = true; } // analyze the message sub tag and make them feel to be in a "normal" environment $this->extractTagLibTags(); // add message that is the essence of the tag's transformed content /* @var $forwardMessageMgr ForwardMessageManager */ $forwardMessageMgr = $this->getServiceObject(ForwardMessageManager::class, [], APFService::SERVICE_TYPE_SESSION_SINGLETON); $forwardMessageMgr->addMessage($name, parent::transform(), $show, $group); }
public function transform() { /* @var $header HtmlHeaderManager */ $header = $this->getServiceObject(HtmlHeaderManager::class); $content = trim(parent::transformChildrenAndPreserveContent()); if (!empty($content)) { if ($this->getAttribute('append') === 'true') { $title = $header->getTitle(); /* @var $title SimpleTitleNode */ if ($title !== null) { $titleContent = $title->getContent() . $content; } else { $titleContent = $content; } } else { $titleContent = $content; } $header->addNode(new SimpleTitleNode($titleContent)); } return ''; }
public function testViewModelContent() { $name = 'foo'; $tag = $this->getPlaceHolder('<a href="${content->getUrl()}">${content->getLabel()}</a>', ['name' => $name]); $parent = new Document(); $model = new LinkModel(); $parent->setPlaceHolder($name, $model); $tag->setParentObject($parent); $this->assertEquals('<a href="' . $model->getUrl() . '">' . $model->getLabel() . '</a>', $tag->transform()); }
public function testAddAttribute() { $doc = new Document(); $name = 'foo'; $glue = '-'; $this->assertEquals(null, $doc->getAttribute($name)); $doc->addAttribute($name, '', $glue); $this->assertEquals('', $doc->getAttribute($name)); $doc->addAttribute($name, 'foo', $glue); $this->assertEquals('foo', $doc->getAttribute($name)); $result = $doc->addAttribute($name, 'foo', $glue); $this->assertEquals('foo-foo', $doc->getAttribute($name)); $this->assertEquals($doc, $result); }
Document::addTagLib(TimeSelectorTag::class, 'form', 'time'); Document::addTagLib(ValidationListenerTag::class, 'form', 'listener'); Document::addTagLib(FormGroupTag::class, 'form', 'group'); Document::addTagLib(HtmlIteratorTag::class, 'html', 'iterator'); Document::addTagLib(TemplateTag::class, 'iterator', 'fallback'); Document::addTagLib(HtmlIteratorItemTag::class, 'iterator', 'item'); Document::addTagLib(FillHtmlIteratorTag::class, 'item', 'fill-iterator'); Document::addTagLib(ButtonLanguageLabelTag::class, 'button', 'getstring'); Document::addTagLib(LabelLanguageLabelTag::class, 'label', 'getstring'); Document::addTagLib(SelectBoxGroupTag::class, 'select', 'group'); Document::addTagLib(SelectBoxOptionTag::class, 'select', 'option'); Document::addTagLib(SelectBoxOptionTag::class, 'group', 'option'); Document::addTagLib(LinkLanguageLabelActiveTag::class, 'aActive', 'getstring'); Document::addTagLib(LinkLanguageLabelTag::class, 'a', 'getstring'); Document::addTagLib(LinkLanguageTitleActiveTag::class, 'titleActive', 'getstring'); Document::addTagLib(LinkLanguageTitleTag::class, 'title', 'getstring'); Document::addTagLib(MediaInclusionTag::class, 'html', 'mediastream'); // APF\modules Document::addTagLib(UmgtMediaInclusionLanguageLabelTag::class, 'media', 'getstring'); Document::addTagLib(SimpleCaptchaTag::class, 'form', 'captcha'); Document::addTagLib(ReCaptchaTag::class, 'form', 'recaptcha'); // APF\extensions Document::addTagLib(DefinitionListDefinitionTag::class, 'list', 'elem_defdef'); Document::addTagLib(DefinitionListTermTag::class, 'list', 'elem_defterm'); Document::addTagLib(ListElementTag::class, 'list', 'elem_list'); // The 2.2/3.0 APF parser allows to globally register template expressions. This allows to register custom "short cuts" // for template syntax (e.g. place holders, language labels). The following section registers the default APF expressions // shipped with the release to have them available for all templates. Document::addTemplateExpression(PlaceHolderTemplateExpression::class); Document::addTemplateExpression(DynamicTemplateExpression::class);
public static function getDocument($token) { $doc = new Document(); $doc->setAttribute('expression', static::class); return $doc; }
/** * Checks whether form control creation complies with APF DomNode creation. */ public function testCreateFormElement() { $name = 'foo'; $context = 'bar'; $language = 'en'; $form = new HtmlFormTag(); $form->setContext($context); $form->setLanguage($language); // register mock implementation to allow check of method execution Document::addTagLib(TextFieldTagMock::class, 'test', 'text'); $method = new ReflectionMethod(HtmlFormTag::class, 'createFormElement'); $method->setAccessible(true); // note: arguments to be passed ad reference MUST be explicitly referenced with & $actual = $method->invokeArgs($form, [&$form, 'test:text', ['name' => $name, 'class' => 'text-field']]); /* @var $field TextFieldTagMock */ $field = $form->getFormElementByName($name); $objectId = $field->getObjectId(); // check identity to ensure references are returned $this->assertEquals(spl_object_hash($actual), spl_object_hash($field)); // test element creation as part of the applied DomNode instance $this->assertInstanceOf(TextFieldTag::class, $field); // test object id, attributes, context language, $this->assertNotNull($objectId); $this->assertEquals($name, $field->getAttribute('name')); $this->assertEquals($context, $field->getContext()); $this->assertEquals($language, $field->getLanguage()); // check whether parent object is initialized (form) $this->assertEquals($form, $field->getParentObject()); // check whether onParseTime() and onAfterAppend() are called $this->assertTrue($field->onParseTimeExecuted); $this->assertTrue($field->onAfterAppendExecuted); // check if internal array structure is valid $children = $form->getChildren(); $this->assertNotEmpty($children); $this->assertContains($objectId, array_keys($children)); }