mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Updating tests to be more specific. Adding tests for confirm.
This commit is contained in:
parent
04fa46f228
commit
04b151edc9
1 changed files with 37 additions and 6 deletions
|
@ -106,7 +106,7 @@ class JsHelperTestCase extends CakeTestCase {
|
||||||
**/
|
**/
|
||||||
function _useMock() {
|
function _useMock() {
|
||||||
$this->Js =& new JsHelper(array('TestJs'));
|
$this->Js =& new JsHelper(array('TestJs'));
|
||||||
$this->Js->TestJsEngine =& new TestJsEngineHelper();
|
$this->Js->TestJsEngine =& new TestJsEngineHelper($this);
|
||||||
$this->Js->Html =& new HtmlHelper();
|
$this->Js->Html =& new HtmlHelper();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -248,19 +248,50 @@ class JsHelperTestCase extends CakeTestCase {
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
**/
|
**/
|
||||||
function testLink() {
|
function testLinkWithMock() {
|
||||||
$this->_useMock();
|
$this->_useMock();
|
||||||
$this->Js->TestJsEngine->setReturnValue('request', 'ajax code');
|
$options = array('update' => '#content');
|
||||||
$this->Js->TestJsEngine->expectAt(0, 'request', array('/posts/view/1', '*'));
|
|
||||||
$this->Js->TestJsEngine->expectAt(0, 'event', array('click', 'ajax code'));
|
|
||||||
|
|
||||||
$result = $this->Js->link('test link', '/posts/view/1', array('update' => '#content'));
|
$this->Js->TestJsEngine->setReturnValue('dispatchMethod', 'ajax code', array('request', '*'));
|
||||||
|
$this->Js->TestJsEngine->expectAt(0, 'dispatchMethod', array('get', new AnythingExpectation()));
|
||||||
|
$this->Js->TestJsEngine->expectAt(1, 'dispatchMethod', array(
|
||||||
|
'request', array('/posts/view/1', $options)
|
||||||
|
));
|
||||||
|
$this->Js->TestJsEngine->expectAt(2, 'dispatchMethod', array(
|
||||||
|
'event', array('click', 'ajax code', $options)
|
||||||
|
));
|
||||||
|
|
||||||
|
$result = $this->Js->link('test link', '/posts/view/1', $options);
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'a' => array('id' => 'preg:/link-\d+/', 'href' => '/posts/view/1'),
|
'a' => array('id' => 'preg:/link-\d+/', 'href' => '/posts/view/1'),
|
||||||
'test link',
|
'test link',
|
||||||
'/a'
|
'/a'
|
||||||
);
|
);
|
||||||
$this->assertTags($result, $expected);
|
$this->assertTags($result, $expected);
|
||||||
|
|
||||||
|
$options = array(
|
||||||
|
'confirm' => 'Are you sure?',
|
||||||
|
'update' => '#content',
|
||||||
|
'class' => 'my-class',
|
||||||
|
'id' => 'custom-id',
|
||||||
|
'escape' => false
|
||||||
|
);
|
||||||
|
$this->Js->TestJsEngine->expectAt(0, 'confirm', array($options['confirm']));
|
||||||
|
$this->Js->TestJsEngine->expectAt(1, 'request', array('/posts/view/1', '*'));
|
||||||
|
$code = <<<CODE
|
||||||
|
var _confirm = confirm("Are you sure?");
|
||||||
|
if (!_confirm) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
CODE;
|
||||||
|
$this->Js->TestJsEngine->expectAt(1, 'event', array('click', $code));
|
||||||
|
$result = $this->Js->link('test link »', '/posts/view/1', $options);
|
||||||
|
$expected = array(
|
||||||
|
'a' => array('id' => $options['id'], 'class' => $options['class'], 'href' => '/posts/view/1'),
|
||||||
|
'test link »',
|
||||||
|
'/a'
|
||||||
|
);
|
||||||
|
$this->assertTags($result, $expected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue