Fixing #138
[akelos.git] / test / unit / lib / AkActionView / helpers / javascript_macros_helper.php
blob414bc5bca102df007e8c82eb2b32983aa34bb53f
1 <?php
3 require_once('_HelpersUnitTester.php');
4 require_once(AK_LIB_DIR.DS.'AkActionView'.DS.'helpers'.DS.'javascript_macros_helper.php');
5 require_once(AK_LIB_DIR.DS.'AkActionController.php');
6 require_once(AK_LIB_DIR.DS.'AkRequest.php');
8 ak_generate_mock('AkRequest');
11 class JavaScriptMacrosHelperTests extends HelpersUnitTester
13 function test_setup()
15 $this->controller = &new AkActionController();
16 $this->controller->Request =& new MockAkRequest($this);
17 $this->controller->controller_name = 'test';
18 $this->controller->instantiateHelpers();
20 $this->javascript_macros_helper =& $this->controller->javascript_macros_helper;
23 function test_in_place_editor()
25 $this->assertEqual(
26 $this->javascript_macros_helper->in_place_editor('field_id', array('url' => array('controller' => 'foo', 'action' => 'bar', 'id' => 'beer'))),
27 "<script type=\"text/javascript\">\n//<![CDATA[\nnew Ajax.InPlaceEditor('field_id', '/foo/bar/beer/')\n//]]>\n</script>"
31 // To implement when in_place_editor_field will be updated
32 function test_in_place_editor_field()
36 function test_in_auto_complete_field()
38 $this->assertEqual(
39 $this->javascript_macros_helper->auto_complete_field('field_id', array('url' => array('controller' => 'foo', 'action' => 'bar'))),
40 "<script type=\"text/javascript\">\n//<![CDATA[\nvar field_id_auto_completer = new Ajax.Autocompleter('field_id', 'field_id_auto_complete', '/foo/bar/', {})\n//]]>\n</script>"
44 function test_in_auto_complete_result()
46 $objects = array();
47 for($i=0; $i<10; $i++)
49 $object = array();
50 $object['test'] = $i;
51 $objects[] = $object;
53 $this->assertEqual(
54 $this->javascript_macros_helper->auto_complete_result($objects, 'test'),
55 "<ul><li>0</li><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li></ul>"
59 function test_text_field_with_auto_complete()
61 $style = file_get_contents(AK_TEST_HELPERS_DIR.DS.'javascript_macros_helper_style.txt');
62 $code = file_get_contents(AK_TEST_HELPERS_DIR.DS.'javascript_macros_helper_code.txt');
64 $this->assertEqual(
65 $this->javascript_macros_helper->text_field_with_auto_complete('user', 'login', array(), array('url' => array('controller' => 'foo', 'action' => 'bar'))),
66 $style.$code
68 $this->assertEqual(
69 $this->javascript_macros_helper->text_field_with_auto_complete('user', 'login', array(), array('url' => array('controller' => 'foo', 'action' => 'bar'), 'skip_style' => true)),
70 $code
76 ak_test('JavaScriptMacrosHelperTests');