cfRendering = self::$kernel->getContainer() ->get('chill.custom_field.twig.custom_fields_rendering'); $this->cfProvider = self::$kernel->getContainer() ->get('chill.custom_field.provider'); // set locale to fr $prophet = new \Prophecy\Prophet(); $request = $prophet->prophesize(); $request->willExtend(\Symfony\Component\HttpFoundation\Request::class); $request->getLocale()->willReturn('fr'); self::$kernel->getContainer()->get('request_stack') ->push($request->reveal()); } public function testIsEmpty() { $cf = $this->getSimpleCustomFieldText(); // value is not empty $fields = [ 'test' => 'My tailor is rich', ]; $result = $this->cfRendering->isEmptyValue($fields, $cf); $this->assertFalse($result); // value is empty $fields = [ 'text' => '', ]; $result = $this->cfRendering->isEmptyValue($fields, $cf); $this->assertTrue($result); } public function testLabelRendering() { $cf = $this->getSimpleCustomFieldText(); $text = $this->cfRendering->renderLabel($cf); $this->assertContains( 'Test', $text, "The rendering text should contains the 'test' text" ); } public function testWidgetRendering() { $cf = $this->getSimpleCustomFieldText(); $fields = [ 'test' => 'My tailor is rich', ]; $text = $this->cfRendering->renderWidget($fields, $cf); $this->assertContains( 'My tailor is rich', $text, "The rendering text should contains the 'test' text" ); } /** * @return CustomField */ private function getSimpleCustomFieldText() { return (new CustomField()) ->setSlug('test') ->setName(['fr' => 'Test']) ->setType('text') ->setOrdering(10) ->setOptions(['maxLength' => 255]) ->setActive(true); } }