0

I've a plugin with only one controller with only one action:

class AssetsController extends Controller
{
    /**
     * Renders an asset
     * @param string $filename Asset filename
     * @param string $type Asset type (`css` or `js`)
     * @return Cake\Network\Response|null
     */
    public function asset($filename, $type)
    {
        $this->response->type($type);
        $this->response->file(ASSETS . DS . $filename);

        return $this->response;
    }
}

This only sends an asset file.

Now I'm writing a test for an asset file that does not exist.

public function testAssetNoExistingFile()
{
    $this->get('/assets/css/noexistingfile.css');

    $this->assertResponseFailure();
}

But it asks for error template:

1) Assets\Test\TestCase\Controller\AssetsControllerTest::testAssetNoExistingFile
Cake\View\Exception\MissingTemplateException: Template file "Error/error500.ctp" is missing.

The plugin does not have template and there is no app with templates. So I would expect that it uses templates from CakePHP core, but this does not happen. Where am I wrong?

1 Answer 1

1

There is no Error/error500.ctp template in the core, that's something that the application has to supply.

When testing plugins, you should register a proper test application environment, and provide the necessary templates for it. If you look at how the CakePHP core and plugins do it, they create/register a dummy application in the tests folder where such template files can then be placed.

See also

Sign up to request clarification or add additional context in comments.

2 Comments

I have an app for tests, but I did not believe that it should also integrate templates. So I have to add error templates and a default layout. Ok, thanks @ndm
Sorry: error templates and an error layout! Ok, it works now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.