In this example we will create a simple blog plugin, intelligently called "dmSimpleBlogPlugin".
First, enable it in
config/ProjectConfiguration.class.php
class ProjectConfiguration extends dmProjectConfiguration { public function setup() { parent::setup(); $this->enablePlugins(array( 'dmSimpleBlogPlugin' )); // ...
Let's create a minimal plugin structure in our project:
DmSimpleBlogPost:
actAs: [ Timestampable, DmSortable, DmVersionable ]
columns:
name: { type: string(255), notnull: true }
resume: { type: string(255) }
text: { type: clob, extra: markdown }
is_active: { type: boolean, notnull: true, default: true }
created_by: { type: integer }
relations:
Author:
class: DmUser
local: created_by
foreignAlias: DmSimpleBlogPosts
onDelete: SET NULL
DmSimpleBlogComment:
actAs: [ Timestampable ]
columns:
post_id: { type: integer, notnull: true }
name: { type: string(255), notnull: true }
text: { type: clob }
is_active: { type: boolean, notnull: true, default: true }
relations:
Post:
class: DmSimpleBlogPost
local: post_id
foreignAlias: Comments
onDelete: CASCADE
It's a good pratice to prefix the plugin models with Dm%PluginName%.
Content:
"Simple Blog":
dmSimpleBlogPost:
name: Blog Post
page: true
components:
list:
show:
dmSimpleBlogComment:
name: Blog Comment
components:
listByBlogPost:
filters: [ dmSimpleBlogPost ]
form:
It's a good pratice to prefix the plugin modules with dm%PluginName%.
php symfony doctrine:generate-migrations-diff
php symfony doctrine:migrate
php symfony dm:setup
Now the plugin is ready.
Admin and front modules have been created in the plugin dir. Customize them as you do for a normal project.
The first thing to do is to connect your plugin tests to your project by using the setupPlugins method in your ProjectConfiguration.class.php file.
public function setupPlugins() { $this->pluginConfigurations['dmSimpleBlogPlugin']->connectTests(); }
Then create a test/unit directory into your plugin directory. In this directory, you will create a dmSimpleBlogTest.php file.
require_once(dirname(__FILE__).'/helper/dmSimpleBlogUnitTestHelper.php'); $helper = new dmSimpleBlogUnitTestHelper(); $helper->boot(); $t = new lime_test(); $t->comment('Testing dmSimpleBlog plugin');
You've certainly noticed that we include a file (dmSimpleBlogUnitTestHelper.php) under a directory called helper. This file will be used to bootstrap the unit test.
So let's create a helper directory under your test/unit directory, and put the dmSimpleBlogUnitTestHelper.php in it.
require_once(getcwd() .'/config/ProjectConfiguration.class.php'); require_once(dm::getDir().'/dmCorePlugin/test/unit/helper/dmUnitTestHelper.php'); class dmNewsUnitTestHelper extends dmUnitTestHelper { protected $limeTest; public function setLimeTest(lime_test $t) { $this->limeTest = $t; } }
Quite simple isn't it ? It just extends the Diem unit test base class. You can use this class for whatever you want. For example, it can be a good place
to create the objects needed for your test. Then you just have do like usual for writing your unit tests the symfony way.
Questions and Feedback
If you need support or have a technical question, you can
The documentation is hosted on GitHub. Feel free to submit issues and patches!