Bolt\Tests\Controller\Backend\LogTest::testChangeRecordListing PHP Метод

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

    public function testChangeRecordListing()
    {
        $this->getService('config')->set('general/changelog/enabled', true);
        // First test tests without any changelogs available
        $this->setRequest(Request::create('/bolt/changelog/pages'));
        $response = $this->controller()->changeRecordListing($this->getRequest(), 'pages', null);
        $context = $response->getContext();
        $this->assertEmpty($context['context']['entries']);
        $this->assertNull($context['context']['content']);
        $this->assertEquals('Pages', $context['context']['title']);
        $this->assertEquals('pages', $context['context']['contenttype']['slug']);
        // Search for a specific record where the content object doesn't exist
        $this->setRequest(Request::create('/bolt/changelog/pages/1'));
        $response = $this->controller()->changeRecordListing($this->getRequest(), 'pages', 200);
        $context = $response->getContext();
        $this->assertEquals('Page #200', $context['context']['title']);
        // This block generates a changelog on the page in question so we have something to test.
        $this->setRequest(Request::create('/'));
        /** @var \Bolt\Legacy\Content $content */
        $content = $this->getService('storage')->getContent('pages/1');
        $content->setValues(['status' => 'draft', 'ownerid' => 99]);
        $this->getService('storage')->saveContent($content, 'Test Suite Update');
        // Now handle all the other request variations
        $this->setRequest(Request::create('/bolt/changelog'));
        $response = $this->controller()->changeRecordListing($this->getRequest(), null, null);
        $context = $response->getContext();
        $this->assertEquals('All ContentTypes', $context['context']['title']);
        $this->assertEquals(1, count($context['context']['entries']));
        $this->assertEquals(1, $context['context']['pagecount']);
        $this->setRequest(Request::create('/bolt/changelog/pages'));
        $response = $this->controller()->changeRecordListing($this->getRequest(), 'pages', null);
        $context = $response->getContext();
        $this->assertEquals('Pages', $context['context']['title']);
        $this->assertEquals(1, count($context['context']['entries']));
        $this->assertEquals(1, $context['context']['pagecount']);
        $this->setRequest(Request::create('/bolt/changelog/pages/1'));
        $response = $this->controller()->changeRecordListing($this->getRequest(), 'pages', '1');
        $context = $response->getContext();
        $this->assertEquals($content['title'], $context['context']['title']);
        $this->assertEquals(1, count($context['context']['entries']));
        $this->assertEquals(1, $context['context']['pagecount']);
        // Test pagination
        $this->setRequest(Request::create('/bolt/changelog/pages', 'GET', ['page' => 'all']));
        $response = $this->controller()->changeRecordListing($this->getRequest(), 'pages', null);
        $context = $response->getContext();
        $this->assertNull($context['context']['currentpage']);
        $this->assertNull($context['context']['pagecount']);
        $this->setRequest(Request::create('/bolt/changelog/pages', 'GET', ['page' => '1']));
        $response = $this->controller()->changeRecordListing($this->getRequest(), 'pages', null);
        $context = $response->getContext();
        $this->assertEquals(1, $context['context']['currentpage']);
        // Finally we delete the original content record, but make sure the logs still show
        $originalTitle = $content['title'];
        $this->getService('storage')->deleteContent('pages', 1);
        $this->setRequest(Request::create('/bolt/changelog/pages/1'));
        $response = $this->controller()->changeRecordListing($this->getRequest(), 'pages', '1');
        $context = $response->getContext();
        $this->assertEquals($originalTitle, $context['context']['title']);
        // Note the delete generates an extra log, hence the extra count
        $this->assertEquals(2, count($context['context']['entries']));
    }