如何设置控制器测试以测试是否在$ entity上调用了library(DT)
iris$Sepal.Width <- 'Verrrrrrrrry Looooooooooooooong Commmmmmment'
iris_upd <- cbind(' ' = '<img src=\"https://raw.githubusercontent.com/DataTables/DataTables/master/examples/resources/details_open.png\"/>', iris)
datatable(
iris_upd,
escape = -2,
options = list(
columnDefs = list(
list(visible = FALSE, targets = c(0)),
list(orderable = FALSE, className = 'details-control', targets = 1),
list(
targets = 3,
render = JS(
"function(data, type, row, meta) {",
"return type === 'display' && data.length > 6 ?",
"'<span title=\"' + data + '\">' + data.substr(0, 6) + '...</span>' : data;",
"}")
)
)
),
callback = JS("
table.column(1).nodes().to$().css({cursor: 'pointer'});
var format = function(d) {
return'<p>' + d[3] + '</p>';
};
table.on('click', 'td.details-control', function() {
var td = $(this), row = table.row(td.closest('tr'));
if (row.child.isShown()) {
row.child.hide();
td.html('<img src=\"https://raw.githubusercontent.com/DataTables/DataTables/master/examples/resources/details_open.png\"/>');
} else {
row.child(format(row.data())).show();
td.html('<img src=\"https://raw.githubusercontent.com/DataTables/DataTables/master/examples/resources/details_close.png\"/>');
}
});"
))
方法
JS("
table.column(1).nodes().to$().css({cursor: 'pointer'});
var format = function(d, ind, tit) {
out = '';
for(i=0; i<ind.length; i++){
out += tit[ind[i]] + ':' + ' ' + d[ind[i]] + '<br>';
}
return out;
};
table.on('click', 'td.details-control', function() {
var td = $(this), row = table.row(td.closest('tr'));
var title = table.columns().header(); //Getting all column names 'headers'
title_names = [];
for (i = 0; len = title.length, i < len; i++) {
title_names.push(title[i].innerText);
}
nms = ['Species','Sepal.Width']; //Define column names here
indices = [];
for (i=0; i<nms.length; i++){
indices.push(title_names.indexOf(nms[i]))
}
if (row.child.isShown()) {
row.child.hide();
td.html('<img src=\"https://raw.githubusercontent.com/DataTables/DataTables/master/examples/resources/details_open.png\"/>');
} else {
row.child(format(row.data(), indices, title_names)).show();
td.html('<img src=\"https://raw.githubusercontent.com/DataTables/DataTables/master/examples/resources/details_close.png\"/>');
}
});"
)
我的doSomething
看起来像这样:
public function doSomething($id)
{
$entity = $this->Entities->get($id);
$entity->doSomething();
}
我想我必须使用实体的模拟对象,但是我该怎么做,控制器要做的第一件事就是写EntitesControllerTest
变量?