/** * @test */ public function testAddCompiledNamespacesDoesNothing() { $instance = $this->getMockForAbstractClass(AbstractCompiledTemplate::class); $context = new RenderingContextFixture(); $before = $context->getViewHelperResolver()->getNamespaces(); $instance->addCompiledNamespaces($context); $after = $context->getViewHelperResolver()->getNamespaces(); $this->assertEquals($before, $after); }
/** * @test */ public function testHasAsksCache() { $cache = $this->getMock(SimpleFileCache::class, array('get')); $cache->expects($this->once())->method('get')->with('test')->willReturn(TRUE); $renderingContext = new RenderingContextFixture(); $renderingContext->setCache($cache); $instance = $this->getMock(TemplateCompiler::class, array('sanitizeIdentifier')); $instance->expects($this->once())->method('sanitizeIdentifier')->willReturnArgument(0); $instance->setRenderingContext($renderingContext); $result = $instance->has('test'); $this->assertTrue($result); }
/** * @param \RuntimeException $error * @dataProvider getWarmSingleFileExceptionTestValues * @test */ public function testWarmuSingleFileHandlesException(\RuntimeException $error) { $subject = new StandardCacheWarmer(); $context = new RenderingContextFixture(); $parser = $this->getMock(TemplateParser::class, ['getOrParseAndStoreTemplate']); $parser->expects($this->once())->method('getOrParseAndStoreTemplate')->willThrowException($error); $variableProvider = new StandardVariableProvider(['foo' => 'bar']); $context->setVariableProvider($variableProvider); $context->setTemplateParser($parser); $method = new \ReflectionMethod($subject, 'warmSingleFile'); $method->setAccessible(true); $result = $method->invokeArgs($subject, ['/some/file', 'some_file', $context]); $this->assertInstanceOf(ParsedTemplateInterface::class, $result); $this->assertAttributeNotEmpty('failureReason', $result); $this->assertAttributeNotEmpty('mitigations', $result); }
/** * @test */ public function testCompileThrowsStopCompilingChildrenException() { $subject = new WarmupViewHelper(); $subject->initializeArguments(); $subject->setRenderChildrenClosure(function () { return 'test'; }); $subject->setArguments(['variables' => ['foo' => 'bar']]); $renderingContext = new RenderingContextFixture(); $renderingContext->setVariableProvider(new StandardVariableProvider()); $subject->setRenderingContext($renderingContext); $viewHelperNode = $this->getMock(ViewHelperNode::class, ['dummy'], [], '', false); $initializationCode = ''; $this->setExpectedException(StopCompilingChildrenException::class); $subject->compile('argumentName', 'closureName', $initializationCode, $viewHelperNode, new TemplateCompiler()); }
/** * @test */ public function retrieveContentFromChildNodesReturnsBreaksOnBreak() { $instance = $this->getAccessibleMock(SwitchViewHelper::class, array('dummy')); $context = new RenderingContextFixture(); $context->getViewHelperVariableContainer()->addOrUpdate(SwitchViewHelper::class, 'switchExpression', 'foo'); $context->getViewHelperVariableContainer()->addOrUpdate(SwitchViewHelper::class, 'break', FALSE); $instance->_set('viewHelperVariableContainer', $context->getViewHelperVariableContainer()); $instance->_set('renderingContext', $context); $matchingCaseViewHelper = new CaseViewHelper(); $matchingCaseViewHelper->setRenderChildrenClosure(function () { return 'foo-childcontent'; }); $breakingMatchingCaseNode = $this->getAccessibleMock(ViewHelperNode::class, array('getViewHelperClassName', 'getUninitializedViewHelper'), array(), '', FALSE); $breakingMatchingCaseNode->_set('arguments', array('value' => 'foo')); $breakingMatchingCaseNode->_set('uninitializedViewHelper', $matchingCaseViewHelper); $breakingMatchingCaseNode->method('getViewHelperClassName')->willReturn(CaseViewHelper::class); $defaultCaseNode = $this->getMock(ViewHelperNode::class, array('getViewHelperClassName', 'evaluate'), array(), '', FALSE); $defaultCaseNode->method('getViewHelperClassName')->willReturn(DefaultCaseViewHelper::class); $defaultCaseNode->expects($this->never())->method('evaluate'); $method = new \ReflectionMethod(SwitchViewHelper::class, 'retrieveContentFromChildNodes'); $method->setAccessible(TRUE); $result = $method->invokeArgs($instance, array(array($breakingMatchingCaseNode, $defaultCaseNode))); $this->assertEquals('foo-childcontent', $result); }
/** * @test */ public function buildObjectTreeDelegatesHandlingOfTemplateElements() { $templateParser = $this->getAccessibleMock(TemplateParser::class, array('textHandler', 'openingViewHelperTagHandler', 'closingViewHelperTagHandler', 'textAndShorthandSyntaxHandler')); $context = new RenderingContextFixture(); $context->setVariableProvider(new StandardVariableProvider()); $templateParser->setRenderingContext($context); $splitTemplate = $templateParser->_call('splitTemplateAtDynamicTags', 'The first part is simple<![CDATA[<f:for each="{a: {a: 0, b: 2, c: 4}}" as="array"><f:for each="{array}" as="value">{value} </f:for>]]><f:format.printf arguments="{number : 362525200}">%.3e</f:format.printf>and here goes some {text} that could have {shorthand}'); $result = $templateParser->_call('buildObjectTree', $splitTemplate, TemplateParser::CONTEXT_OUTSIDE_VIEWHELPER_ARGUMENTS); $this->assertInstanceOf(ParsingState::class, $result); }