Bolt\Tests\Controller\Backend\RecordsTest::testEditPostAjax PHP Method

testEditPostAjax() public method

public testEditPostAjax ( )
    public function testEditPostAjax()
    {
        $csrf = $this->getMockCsrfTokenManager();
        $csrf->expects($this->any())->method('isTokenValid')->will($this->returnValue(true));
        $this->setService('csrf', $csrf);
        $users = $this->getMockUsers(['checkAntiCSRFToken']);
        $users->expects($this->any())->method('checkAntiCSRFToken')->will($this->returnValue(true));
        $this->setService('users', $users);
        // Since we're the test user we won't automatically have permission to edit.
        $permissions = $this->getMockPermissions();
        $permissions->expects($this->any())->method('isAllowed')->will($this->returnValue(true));
        $this->setService('permissions', $permissions);
        // We use ?returnto=test here as that is handled exactly the same as
        // ?returnto=ajax except that it doesn't flush output buffers which we
        // require to ensure the JSON response is clean from debug or error
        // output, but PHPUnit marks the test "Risky"
        $this->setRequest(Request::create('/bolt/editcontent/pages/4?returnto=test', 'POST'));
        $original = $this->getService('storage')->getContent('pages/4');
        $response = $this->controller()->edit($this->getRequest(), 'pages', 4);
        $returned = json_decode($response->getContent());
        $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\JsonResponse', $response);
        $this->assertEquals($original['title'], $returned->title);
    }