Skip to content

Instantly share code, notes, and snippets.

View mguillermin's full-sized avatar

Matthieu Guillermin mguillermin

  • Swappie
  • Helsinki, Finlande
View GitHub Profile
<?php
/**
* Replaces tokens in distribution files.
*/
class CI_Task_ConfigureDistTask extends sfBaseTask
{
/**
* @see sfTask
*/
@Test
public void save() {
running(fakeApplication(), new Runnable() {
public void run() {
// Here is your real test code
Company company = new Company("My Company");
company.save();
assertThat(company.id).isNotNull();
}
});
public class BaseModelTest {
public static FakeApplication app;
@BeforeClass
public static void startApp() {
app = Helpers.fakeApplication(Helpers.inMemoryDatabase());
Helpers.start(app);
}
@AfterClass
public class BaseModelTest {
public static FakeApplication app;
public static String createDdl = "";
public static String dropDdl = "";
@BeforeClass
public static void startApp() throws IOException {
app = Helpers.fakeApplication(Helpers.inMemoryDatabase());
Helpers.start(app);
@mguillermin
mguillermin / Application.java
Created March 14, 2012 09:19
Play 2.0 Java Controller Sample
public class Application extends Controller {
public static Result testText() {
return ok("Hello world !");
}
public static Result testTemplate() {
return ok(index.render("Your new application is ready."));
}
@mguillermin
mguillermin / index.scala.html
Created March 14, 2012 09:35
Play 2.0 Scala Template Sample
@(user: User, links : List[link])
@main("User links") {
<p>Welcome @user.name !</p>
<ul>
@for(link <- links) {
<li><a href="@link.url">@link.title</a></li>
}
</ul>
}
@mguillermin
mguillermin / Company.java
Created March 14, 2012 09:38
Play 2.0 Ebean Sample
@Entity
public class Company extends Model {
@Id
public Long id;
@Constraints.Required
public String name;
public Company(String name) {
@mguillermin
mguillermin / User.scala
Created March 14, 2012 09:44
Play 2.0 Anorm Sample
case class User(email: String, name: String, password: String)
object User {
// -- Parsers
/**
* Parse a User from a ResultSet
*/
val simple = {
@mguillermin
mguillermin / Menu.java
Created March 21, 2012 06:32
Play 2.0 Template inclusion with "backed" logic
package controllers;
import play.api.templates.Html;
import models.MenuItem;
public class Menu {
public static Html render(String parent) {
List<MenuItem> menuItems = MenuItem.findByParent(parent);
// more business logic...
return views.html.menu.render(menuItems);
@mguillermin
mguillermin / gist:2145559
Created March 21, 2012 08:13
Drupal - Utiliser Workbench pour filtrer les menus dispos lors de la création de contenu
<?php
function my_module_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'page_node_form' && !user_access('administer content')) {
// Alter node edit form
$menu_items = $form['menu']['link']['parent']['#options'];
$menu_items_to_delete = array();
$workbench_access_menus = workbench_access_get_user_tree();
foreach ($menu_items as $menu_key => $menu_value) {
$ok = false;
foreach ($workbench_access_menus as $id => $workbench_access_menu) {