SilverStripe 4 : FunctionalTest "get" method returns 404 status although the page is there.

I am trying to test a controller with this Test class,

<?php

use SilverStripe\Dev\FunctionalTest;

class SitePageControllerTest extends FunctionalTest
{
    protected static $fixture_file = 'site/tests/fixturesSitePage.yml';

    public function testViewSitePage()
    {
        $obj = $this->objFromFixture('SitePage', 'page1');
        $page = $this->get('page-one/');
        $this->assertEquals(200, $page->getStatusCode());
    }
}

and Fixture.

SitePage:
  page1:
    Title: Page One
    CanViewType: true

But "$this->get('page-one/');" returns a 404 page.


Pages are versioned, and this one isn't published at the point where you ask for it, so the functional test emulates a frontend web request which is served from the live (published) stage by default.

You can use the draft site by appending ?stage=Stage to your request URL, or by using protected static $use_draft_site = true in your functional test (this is deprecated in 4.2).

Note that FunctionalTest doesn't log a user in, so you may also need to log in with some level of permission i.e. $this->logInWithPermission('ADMIN')