Skip to content
Permalink
Browse files

Updating tests to be more specific. Adding tests for confirm.

  • Loading branch information...
markstory committed Jul 12, 2009
1 parent 04fa46f commit 04b151edc9b5ca95e57ab40199c43e91fb4ca6e4
Showing with 37 additions and 6 deletions.
  1. +37 −6 cake/tests/cases/libs/view/helpers/js.test.php
@@ -106,7 +106,7 @@ function endTest() {
**/
function _useMock() {
$this->Js =& new JsHelper(array('TestJs'));
$this->Js->TestJsEngine =& new TestJsEngineHelper();
$this->Js->TestJsEngine =& new TestJsEngineHelper($this);
$this->Js->Html =& new HtmlHelper();
}
/**
@@ -248,19 +248,50 @@ function testWriteScriptsInFile() {
*
* @return void
**/
function testLink() {
function testLinkWithMock() {
$this->_useMock();
$this->Js->TestJsEngine->setReturnValue('request', 'ajax code');
$this->Js->TestJsEngine->expectAt(0, 'request', array('/posts/view/1', '*'));
$this->Js->TestJsEngine->expectAt(0, 'event', array('click', 'ajax code'));
$options = array('update' => '#content');
$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(
'a' => array('id' => 'preg:/link-\d+/', 'href' => '/posts/view/1'),
'test link',
'/a'
);
$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);
}
}

0 comments on commit 04b151e

Please sign in to comment.
You can’t perform that action at this time.