Bolt\Tests\Controller\Backend\GeneralTest::testTranslation PHP Method

testTranslation() public method

public testTranslation ( )
    public function testTranslation()
    {
        $this->removeCSRF($this->getApp());
        // Render new translation file
        $this->setRequest(Request::create('/bolt/tr/contenttypes/en_CY'));
        $response = $this->controller()->translation($this->getRequest(), 'contenttypes', 'en_CY');
        $this->assertTrue($response instanceof TemplateResponse, 'Response is not instance of TemplateResponse');
        $this->assertEquals('@bolt/editlocale/editlocale.twig', $response->getTemplate()->getTemplateName());
        $context = $response->getContext();
        $this->assertEquals('contenttypes.en_CY.yml', $context['context']['basename']);
        // Save updated content and redirect back to page
        $this->setRequest(Request::create('/bolt/tr/contenttypes/en_CY', 'POST', ['form' => ['contents' => 'test content at least 10 chars', '_token' => 'xyz']]));
        $response = $this->controller()->translation($this->getRequest(), 'contenttypes', 'en_CY');
        $this->assertTrue($response instanceof RedirectResponse);
        $this->assertTrue($response->isRedirect('/bolt/tr/contenttypes/en_CY'));
        $this->rmdir($this->getService('resources')->getPath('app/resources/translations/en_CY'));
        // Check that YML parse errors get caught
        $this->setRequest(Request::create('/bolt/tr/contenttypes/en_CY', 'POST', ['form' => ['contents' => '- this is invalid yaml markup: *thisref', '_token' => 'xyz']]));
        $flash = $this->prophesize(FlashLogger::class);
        $flash->keys()->shouldBeCalled();
        $flash->get('info')->shouldBeCalled();
        $flash->get('success')->shouldBeCalled();
        $flash->get('error')->shouldBeCalled();
        $flash->error(new StringContainsToken('could not be saved'))->shouldBeCalled();
        $this->setService('logger.flash', $flash->reveal());
        $this->controller()->translation($this->getRequest(), 'contenttypes', 'en_CY');
        $this->assertTrue($response instanceof RedirectResponse, 'Response is not instance of RedirectResponse');
    }