Bolt\Tests\Controller\Backend\RecordsTest::testEditGet PHP Метод

testEditGet() публичный Метод

public testEditGet ( )
    public function testEditGet()
    {
        // First test will fail permission so we check we are kicked back to the dashboard
        $this->setRequest(Request::create('/bolt/editcontent/pages/4'));
        $response = $this->controller()->edit($this->getRequest(), 'pages', 4);
        $this->assertEquals('/bolt', $response->getTargetUrl());
        // 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);
        $this->setRequest(Request::create('/bolt/editcontent/pages/4'));
        $response = $this->controller()->edit($this->getRequest(), 'pages', 4);
        $context = $response->getContext();
        $this->assertEquals('Pages', $context['context']['contenttype']['name']);
        $this->assertInstanceOf('Bolt\\Storage\\Entity\\Content', $context['context']['content']);
        // Test creation
        $this->setRequest(Request::create('/bolt/editcontent/pages'));
        $response = $this->controller()->edit($this->getRequest(), 'pages', null);
        $context = $response->getContext();
        $this->assertEquals('Pages', $context['context']['contenttype']['name']);
        $this->assertInstanceOf('Bolt\\Storage\\Entity\\Content', $context['context']['content']);
        $this->assertNull($context['context']['content']->id);
        // Test that non-existent throws a redirect
        $this->setRequest(Request::create('/bolt/editcontent/pages/310'));
        $response = $this->controller()->edit($this->getRequest(), 'pages', 310);
        $this->assertEquals(302, $response->getStatusCode());
    }