<?php require_once dirname(__FILE__) . '/../../fixtures/config/config.php'; require_once AK_LIB_DIR . DS . 'Ak.php'; class test_Ak_support_functions extends AkUnitTest { function test_for_importing_models() { $models = 'ImportTestModelA, import_test_model_b'; $this->assertFalse(class_exists('ImportTestModelA')); $this->assertFalse(class_exists('ImportTestModelB')); $this->assertEqual(Ak::import($models), array('ImportTestModelA', 'ImportTestModelB')); $this->assertTrue(class_exists('ImportTestModelA')); $this->assertTrue(class_exists('ImportTestModelB')); $models = array('ImportTestModelB', 'Import Test Model C'); $this->assertEqual(Ak::import($models), array('ImportTestModelB', 'ImportTestModelC')); $this->assertTrue(class_exists('ImportTestModelC')); } } Ak::test('test_Ak_support_functions');
<option value="April">April</option> <option value="May">May</option> <option value="June" selected="selected">June</option> <option value="July">July</option> <option value="August">August</option> <option value="September">September</option> <option value="October">October</option> <option value="November">November</option> <option value="December">December</option> </select> <select name="dateyear"> <option value="1973">1973</option> <option value="1974">1974</option> <option value="1975">1975</option> <option value="1976">1976</option> <option value="1977">1977</option> <option value="1978" selected="selected">1978</option> <option value="1979">1979</option> <option value="1980">1980</option> <option value="1981">1981</option> <option value="1982">1982</option> <option value="1983">1983</option> </select>'), array('')))); //echo DateHelper::distance_of_time_in_words('1779-12-01','1780-01-01'); } } Ak::test('DateHelperTests');
<?php defined('AK_TEST_DATABASE_ON') ? null : define('AK_TEST_DATABASE_ON', true); require_once dirname(__FILE__) . '/../../../fixtures/config/config.php'; class test_AkActionViewHelper extends UnitTestCase { } Ak::test('test_AkActionViewHelper', true);
//, 'Failed auto_link_email_addresses test'); $this->assertEqual($text->strip_selected_tags('sending <b>email</b> to <a href="mailto:salavert@example.com">salavert@example.com</a>', 'a'), 'sending <b>email</b> to salavert@example.com'); //, 'Failed auto_link_email_addresses test'); $this->assertEqual($text->auto_link('email sent to salavert@example.com from http://www.thebigmover.com', 'all'), 'email sent to <a href=\'mailto:salavert@example.com\'>salavert@example.com</a> from <a href="http://www.thebigmover.com">http://www.thebigmover.com</a>'); $this->assertEqual($text->auto_link('email sent to salavert@example.com', 'email_addresses'), 'email sent to <a href=\'mailto:salavert@example.com\'>salavert@example.com</a>'); $this->assertEqual($text->auto_link('email sent from http://www.thebigmover.com', 'urls'), 'email sent from <a href="http://www.thebigmover.com">http://www.thebigmover.com</a>'); $this->assertEqual($text->strip_tags('<a href="nowhere" onclick="javascript:alert(\'oops\');">link</a>'), 'link'); $this->assertEqual($text->markdown('> ## This is a header. > > 1. This is the first list item. > 2. This is the second list item. > > Here\'s some example code: > > return shell_exec("echo $input | $markdown_script");'), '<blockquote> <h2>This is a header.</h2> <ol> <li>This is the first list item.</li> <li>This is the second list item.</li> </ol> <p>Here\'s some example code:</p> <pre><code>return shell_exec("echo $input | $markdown_script"); </code></pre> </blockquote>'); } } Ak::test('TextHelperTests');
<?php require_once '_HelpersUnitTester.php'; require_once AK_LIB_DIR . DS . 'AkActionView' . DS . 'helpers' . DS . 'tag_helper.php'; class TagHelperTests extends HelpersUnitTester { function test_TagHelper() { $this->assertEqual(TagHelper::tag('br'), '<br />'); $this->assertEqual(TagHelper::tag('input', array('type' => 'text', 'value' => 'Insert your text >> "HERE"')), '<input type="text" value="Insert your text >> "HERE"" />'); $this->assertEqual(TagHelper::tag('hr', array('style' => '', 1234 => 'This is not possible')), '<hr />'); $this->assertEqual(TagHelper::content_tag('p', 'Have a look "HERE"'), '<p>Have a look "HERE"</p>'); $this->assertEqual(TagHelper::content_tag('textarea', 'Have a look "HERE"', array('name' => 'details')), '<textarea name="details">Have a look "HERE"</textarea>'); $this->assertEqual(TagHelper::cdata_section('Have a look "HERE"'), '<![CDATA[Have a look "HERE"]]>'); } } Ak::test('TagHelperTests');
<?php require_once '_HelpersUnitTester.php'; require_once AK_LIB_DIR . DS . 'AkActionView' . DS . 'helpers' . DS . 'capture_helper.php'; class CaptureHelperTests extends HelpersUnitTester { /** * @todo Add tests for capture helper */ function tests_pending() { } } Ak::test('CaptureHelperTests');
function test_language_change() { $this->assertEqual(array('en', 'es'), Ak::langs()); $this->addHeader('Accept-Language: es,en-us,en;q=0.5'); $this->get(AK_TESTING_URL . '/locale_detection/get_language'); $this->assertTextMatch('es'); $this->get(AK_TESTING_URL . '/locale_detection/get_param/?param=message&message=Hello'); $this->assertTextMatch('Hello'); $this->get(AK_TESTING_URL . '/locale_detection/get_param/?param=lang&lang=en'); $this->assertTextMatch('en'); $this->get(AK_TESTING_URL . '/locale_detection/get_language/?lang=en'); $this->assertTextMatch('en'); $this->get(AK_TESTING_URL . '/locale_detection/get_language'); $this->assertTextMatch('en'); $this->get(AK_TESTING_URL . '/locale_detection/get_language/?lang=invalid'); $this->assertTextMatch('en'); } function test_language_change_on_ak() { $this->assertEqual(array('en', 'es'), Ak::langs()); $this->addHeader('Accept-Language: es,en-us,en;q=0.5'); $this->get(AK_TESTING_URL . '/locale_detection/get_language'); $this->assertTextMatch('es'); $this->get(AK_TESTING_URL . '/en/locale_detection/get_language/'); $this->assertTextMatch('en'); $this->get(AK_TESTING_URL . '/locale_detection/get_language'); $this->assertTextMatch('en'); } } Ak::test('_AkActionController_locale_detection');
$input_value = array('controller' => 'blog', 'action' => 'view', 'id' => 'newest', 'format' => 'printer_friendly'); $expected = AK_URL_REWRITE_ENABLED ? '/blog/view/newest/?format=printer_friendly' : '/?ak=/blog/view/newest/&format=printer_friendly'; $this->assertEqual($this->Router->toUrl($input_value), $expected); $input_value = array('controller' => 'articles', 'action' => 'view_headlines', 'year' => '2005', 'month' => '10', 'day' => null); $expected = $this->url_prefix . '/2005/10/'; $this->assertEqual($this->Router->toUrl($input_value), $expected); $input_value = array('controller' => 'articles', 'action' => 'view_headlines', 'year' => '2006', 'month' => 'all', 'day' => null); $expected = $this->url_prefix . '/2006/'; $this->assertEqual($this->Router->toUrl($input_value), $expected); $input_value = array('controller' => 'user', 'action' => 'list', 'id' => '12'); $expected = $this->url_prefix . '/user/list/12/'; $this->assertEqual($this->Router->toUrl($input_value), $expected); $input_value = array('controller' => 'setup', 'config_settings' => array('themes', 'clone', '12')); $expected = $this->url_prefix . '/setup/themes/clone/12/'; $this->assertEqual($this->Router->toUrl($input_value), $expected); $input_value = array('controller' => 'themes', 'options' => array('blue', 'css', 'sans_serif'), 'action' => 'clone'); $expected = $this->url_prefix . '/customize/blue/css/sans_serif/clone/'; $this->assertEqual($this->Router->toUrl($input_value), $expected); } function test_url_with_optional_variables() { $input_value = array('controller' => 'topic', 'action' => 'view', 'id' => 4); $expected = $this->url_prefix . '/topic/4/'; $this->assertEqual($this->Router->toUrl($input_value), $expected); $input_value = array('controller' => 'topic', 'action' => 'unread', 'id' => 4); $expected = $this->url_prefix . '/topic/4/unread/'; $this->assertEqual($this->Router->toUrl($input_value), $expected); } } Ak::test('Test_of_AkRouter_Class');
<?php require_once '_HelpersUnitTester.php'; require_once AK_LIB_DIR . DS . 'AkActionView' . DS . 'helpers' . DS . 'pagination_helper.php'; class PaginationHelperTests extends HelpersUnitTester { /** * @todo Add tests for pagination helper */ function tests_pending() { } } Ak::test('PaginationHelperTests');
<?php require_once dirname(__FILE__) . '/../../fixtures/config/config.php'; require_once AK_LIB_DIR . DS . 'Ak.php'; class test_Ak_var_manipulation extends UnitTestCase { function test_for_to_array() { $this->assertEqual(Ak::toArray('es,en,va'), array('es', 'en', 'va')); } function test_for_string_to_array() { $this->assertEqual(Ak::stringToArray('es,en,va'), array('es', 'en', 'va')); $this->assertEqual(Ak::stringToArray('es , en , va'), array('es', 'en', 'va')); } } Ak::test('test_Ak_var_manipulation');
$this->assertTrue($AkTestField->decimal_field === 0); $this->assertTrue($AkTestField->get('decimal_field') === 0); $AkTestField->decrementAttribute('decimal_field'); $this->assertTrue($AkTestField->decimal_field === -1); $this->assertTrue($AkTestField->get('decimal_field') === -1); } function Test_of_get_and_set_DisplayField() { $AkTestField = new AkTestField(); $this->assertEqual($AkTestField->getDisplayField(), 'id'); $AkTestField->setDisplayField('text_field'); $this->assertEqual($AkTestField->getDisplayField(), 'text_field'); $AkTestUser = new AkTestUser(); $this->assertEqual($AkTestUser->getDisplayField(), 'id'); $AkTestUser->addCombinedAttributeConfiguration('name', "%s %s", 'first_name', 'last_name'); $this->assertEqual($AkTestUser->getDisplayField(), 'name'); $AkTestField->setDisplayField('invalid_field'); $this->assertEqual($AkTestUser->getDisplayField(), 'name'); } function Test_of_get_and_get_Id() { $AkTestField = new AkTestField(); $this->assertEqual($AkTestField->getId(), null); $AkTestField->setId(123); $this->assertEqual($AkTestField->getId(), 123); $AkTestField->incrementAttribute($AkTestField->getPrimaryKey()); $this->assertEqual($AkTestField->getId(), 124); } } Ak::test('test_AkActiveRecord', true);
$this->assertWantedText($expected_session_id, 'Sessions are not working correctly'); } function Test_read_write() { $expected = 'test_value'; $this->get("{$this->_test_script}?key=test_key&value={$expected}"); $this->get("{$this->_test_script}?key=test_key"); $this->assertWantedText($expected, 'Session is not storing values on database correctly when calling ' . $this->_test_script . '?key=test_key'); } function Test_destroy() { $expected = 'value not found'; $this->get("{$this->_test_script}?key=test_key&value=test_value"); $this->get("{$this->_test_script}?destroy_check=1"); $this->get("{$this->_test_script}?key=test_key"); $this->assertWantedText($expected, 'session_destroy(); is not working as expected'); } function Test_gc() { $expected = 'value not found'; $copy = $this; $copy->get("{$this->_test_script}?key=test_key&value=test_value&expire=1"); sleep(3); $this->restart(); $this->get("{$this->_test_script}?dumb_call_for_activating_gc"); $copy->get("{$this->_test_script}?key=test_key"); $this->assertWantedText($expected, 'Session garbage collection is not working correctly'); } } Ak::test('Test_of_AkDbSession_Class', true);
$Controller =& new MockAkActionController($this); $Controller->setReturnValue('urlFor', '/url/for/test'); //$Controller->setReturnValue('_getCompleteRequestUri','/url/for/test'); $url = new UrlHelper(); $url->setController($Controller); $this->assertReference($Controller, $url->_controller); $input = array('disabled' => 1, 'checked' => false, 'selected' => ''); $expected = array('disabled' => 'disabled'); $this->assertEqual($url->_convert_boolean_attributes($input, array('disabled', 'checked', 'selected')), $expected); $input = array('disabled' => true, 'id' => 'hithere'); $expected = array('disabled' => 'disabled', 'id' => 'hithere'); $this->assertEqual($url->_convert_boolean_attributes($input, 'disabled'), $expected); $this->assertEqual($url->url_for(array('action' => 'create')), '/url/for/test'); $this->assertEqual($url->button_to('Edit'), '<form method="post" action="/url/for/test" class="button-to"><div>' . '<input type="submit" value="Edit" /></div></form>'); $this->assertEqual($url->link_to('Delete this page', array('action' => 'destroy', 'id' => 3), array('confirm' => 'Are you sure?')), '<a href="/url/for/test" onclick="return confirm(\'Are you sure?\');">Delete this page</a>'); $this->assertEqual($url->link_to('Help', array('action' => 'help'), array('popup' => true)), '<a href="/url/for/test" onclick="window.open(this.href);return false;">Help</a>'); $this->assertEqual($url->link_to('Help', array('action' => 'help'), array('popup' => true, 'confirm' => 'Are you sure?')), '<a href="/url/for/test" onclick="if (confirm(\'Are you sure?\')) { window.open(this.href); };return false;">Help</a>'); $this->assertEqual($url->link_to('Help', array('action' => 'help'), array('post' => true)), '<a href="/url/for/test" onclick="var f = document.createElement(\'form\'); document.body.appendChild(f); f.method = \'POST\'; f.action = this.href; f.submit();return false;">Help</a>'); $this->assertEqual($url->link_to('Destroy account', array('action' => 'destroy'), array('confirm' => 'Are you sure?'), array('post' => true)), '<a href="/url/for/test" onclick="return confirm(\'Are you sure?\');">Destroy account</a>'); $this->assertEqual($url->link_to_unless(true, 'Destroy account', array('action' => 'destroy'), array('confirm' => 'Are you sure?'), array('post' => true)), ''); $this->assertEqual($url->link_to_unless(false, 'Destroy account', array('action' => 'destroy'), array('confirm' => 'Are you sure?'), array('post' => true)), '<a href="/url/for/test" onclick="return confirm(\'Are you sure?\');">Destroy account</a>'); $this->assertEqual($url->_popup_javascript_function('A'), 'window.open(this.href);'); $this->assertEqual($url->_popup_javascript_function(array('A', 'B', 'C')), 'window.open(this.href,\'A\',\'C\');'); $this->assertEqual($url->_confirm_javascript_function('Are you sure?'), 'confirm(\'Are you sure?\')'); $this->assertEqual($url->mail_to('*****@*****.**', 'My email', array('cc' => '*****@*****.**', 'bcc' => '*****@*****.**', 'subject' => 'This is an example email', 'body' => 'This is the body of the message.')), '<a href="mailto:me@domain.com?cc=ccaddress%40domain.com&bcc=bccaddress%40domain.com&body=This%20is%20the%20body%20of%20the%20message.&subject=This%20is%20an%20example%20email">My email</a>'); $this->assertEqual($url->mail_to('*****@*****.**', 'My email', array('encode' => 'javascript')), '<script type="text/javascript">eval(unescape(\'%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d%22%3e%4d%79%20%65%6d%61%69%6c%3c%2f%61%3e%27%29%3b\'))</script>'); $this->assertEqual($url->mail_to('*****@*****.**', 'My email', array('encode' => 'hex')), '<a href="mailto:%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d">My email</a>'); } } Ak::test('UrlHelperTests');
<?php require_once '_HelpersUnitTester.php'; require_once AK_LIB_DIR . DS . 'AkActionView' . DS . 'helpers' . DS . 'javascript_helper.php'; class JavaScriptHelperTests extends HelpersUnitTester { function test_for_JavascriptHelper() { require_once AK_LIB_DIR . DS . 'AkActionView' . DS . 'helpers' . DS . 'javascript_helper.php'; $javascript = new JavaScriptHelper(); $this->assertEqual($javascript->link_to_function('Greeting', "alert('Hello world!')"), '<a href="#" onclick="alert(\'Hello world!\'); return false;">Greeting</a>'); $this->assertEqual($javascript->link_to_function('my link', "if confirm('Really?'){ do_delete(); }", array('href' => 'http://www.akelos.com')), '<a href="http://www.akelos.com" onclick="if confirm(\'Really?\'){ do_delete(); }; return false;">my link</a>'); $this->assertEqual($javascript->button_to_function("Greeting", "alert('Hello world!')"), '<input onclick="alert(\'Hello world!\');" type="button" value="Greeting" />'); $this->assertEqual($javascript->button_to_function("Delete", "if confirm('Really?'){ do_delete(); }", array('id' => 'confirm')), '<input id="confirm" onclick="if confirm(\'Really?\'){ do_delete(); };" type="button" value="Delete" />'); $this->assertEqual($javascript->javascript_tag("alert('All is good')"), "<script type=\"text/javascript\">\n//<![CDATA[\nalert('All is good')\n//]]>\n</script>"); $input = "\n <div id='meesage'\n \n class=\"hisghtlight\" />\n "; $expected = "\\n <div id=\\'meesage\\'\\n \\n class=\\\"hisghtlight\\\" />\\n "; $this->assertEqual($javascript->escape_javascript($input), $expected); } } Ak::test('JavaScriptHelperTests');
{ $this->_deleteTestingModelDatabases(); $this->_createNewTestingModelDatabase('AkTestNestedCategory'); } function _getNestedSetList($Categories = null, $breadcrumb = false) { if (!isset($Categories)) { $Categories = new AkTestNestedCategory(); $Categories = $Categories->find('all', array('conditions' => $Categories->nested_set->getScopeCondition(), 'order' => ' lft ASC ')); } $list = array(); foreach ($Categories as $Category) { $bread_crumb = ''; if ($Parents = $Category->nested_set->getParents()) { foreach ($Parents as $Parent) { $bread_crumb .= $Parent->description . ' > '; } } if ($breadcrumb) { $list[] = $bread_crumb . "(" . $Category->id . ")" . $Category->description; // } else { $list[$Category->parent_id][$Category->id] = $Category->lft . ' <- ' . $Category->description . ' ->' . $Category->rgt; // getAttributes(); } } return $list; } } Ak::test('test_AkActiveRecord_actsAsNestedSet', true);
<?php require_once dirname(__FILE__) . '/../../../fixtures/config/config.php'; class test_AkHasOne extends UnitTestCase { } Ak::test('test_AkHasOne', true);
<?php require_once '_HelpersUnitTester.php'; require_once AK_LIB_DIR . DS . 'AkActionView' . DS . 'helpers' . DS . 'menu_helper.php'; class MenuHelperTests extends HelpersUnitTester { /** * @todo Add tests for menu helper */ function tests_pending() { } } Ak::test('MenuHelperTests');
$catAaParent = $CategoryAa->tree->getParent(); $catAbParent = $CategoryAb->tree->getParent(); $this->assertEqual($CategoryA->getId(), $catAaParent->getId()); $this->assertEqual($CategoryA->getId(), $catAbParent->getId()); } function Test_of_beforeDestroy() { $CategoryA =& new AkDependentTestCategory(); $CategoryA->description = "Cat A"; $CategoryB =& new AkTestCategory(); $CategoryB->description = "Cat B"; $CategoryAa =& new AkDependentTestCategory(); $CategoryAa->description = "Cat Aa"; $CategoryBa =& new AkTestCategory(); $CategoryBa->description = "Cat Ba"; $CategoryA->tree->addChild($CategoryAa); $CategoryB->tree->addChild($CategoryBa); $CategoryA->destroy(); $this->assertFalse($CategoryAa->reload()); $CategoryB->destroy(); $this->assertTrue($CategoryBa->reload()); $this->assertFalse($CategoryBa->tree->hasParent()); } function _resetTable() { $this->_deleteTestingModelDatabases(); $this->_createNewTestingModelDatabase('AkTestCategory'); } } Ak::test('test_AkActiveRecord_actAsTree', true);
<?php require_once '_HelpersUnitTester.php'; require_once AK_LIB_DIR . DS . 'AkActionView' . DS . 'helpers' . DS . 'prototype_helper.php'; class PrototypeHelperTests extends HelpersUnitTester { /** * @todo Add tests for prototype helper */ function tests_pending() { } } Ak::test('PrototypeHelperTests');
<?php defined('AK_ACTIVE_RECORD_PROTECT_GET_RECURSION') ? null : define('AK_ACTIVE_RECORD_PROTECT_GET_RECURSION', false); defined('AK_TEST_DATABASE_ON') ? null : define('AK_TEST_DATABASE_ON', true); require_once dirname(__FILE__) . '/../../fixtures/config/config.php'; class test_AkActiveRecord_table_inheritance extends AkUnitTest { function test_start() { //$this->resetFrameworkDatabaseTables(); $this->installAndIncludeModels(array('Event', 'Concert', 'OpenHouseMeeting')); } function test_for_table_inheritance() { $Event = new Event(array('description' => 'Uncategorized Event')); $this->assertTrue($Event->save()); $Concert = new Concert('description->', 'Madonna at Barcelona'); $this->assertTrue($Concert->save()); $OpenHouseMeeting = new OpenHouseMeeting('description->', 'Networking event at Akelos'); $this->assertTrue($OpenHouseMeeting->save()); $this->assertEqual($OpenHouseMeeting->get('type'), 'Open house meeting'); $this->assertTrue($OpenHouseMeeting = $Event->findFirstBy('description', 'Networking event at Akelos')); $this->assertEqual($OpenHouseMeeting->get('description'), 'Networking event at Akelos'); $this->assertEqual($OpenHouseMeeting->getType(), 'OpenHouseMeeting'); } } Ak::test('test_AkActiveRecord_table_inheritance', true);
ob_start(); $ObservedPerson->save(); $this->assertTrue($ObservedPerson->audited); $content = ob_get_contents(); ob_end_clean(); $this->assertEqual($content, "Bermi has been email with account details"); $notified = array(); foreach ($ObservedPerson->notified_observers as $k => $v) { $notified[strtolower($k)] = $v; } $this->assertEqual($notified, array('beforevalidation' => 1, 'beforevalidationoncreate' => 1, 'aftervalidationoncreate' => 1, 'aftervalidation' => 1, 'beforecreate' => 1, 'beforesave' => 1, 'aftersave' => 1, 'aftercreate' => 1)); $ObservedPerson->set('last_name', 'Ferrer'); $ObservedPerson->save(); $notified = array(); foreach ($ObservedPerson->notified_observers as $k => $v) { $notified[strtolower($k)] = $v; } $this->assertEqual($notified, array('beforevalidation' => 2, 'beforevalidationoncreate' => 1, 'aftervalidationoncreate' => 1, 'aftervalidation' => 2, 'beforecreate' => 1, 'beforesave' => 2, 'aftersave' => 2, 'aftercreate' => 1, 'aftervalidationonupdate' => 1)); } function Test_of_beforeSave_trigger() { $ObservedPerson =& new AkTestObservedPerson(); $ObservedPerson->city = "Carlet"; ob_start(); $ObservedPerson->save(); ob_end_clean(); $this->assertEqual($ObservedPerson->state, "Valencia"); } } Ak::test('test_AkActiveRecord_observer', true);
{ $Person = new AkTestPerson('email->', '*****@*****.**'); $Person->validateOnUpdate(); $this->assertFalse($Person->hasErrors()); $Person = new AkTestPerson('user_name->', 'hilario', 'first_name->', 'Hilario', 'last_name->', 'Herv�s', 'country->', 'ES'); $Person->validateOnUpdate(); $this->assertEqual($Person->getErrorsOn('email'), $Person->_defaultErrorMessages['blank']); } function Test_of_validate() { $Person = new AkTestPerson('first_name->', 'Alicia'); $Person->validate(); $this->assertFalse($Person->hasErrors()); $Person = new AkTestPerson('last_name->', 'Sadurn�', 'country->', 'ES'); $Person->validate(); $this->assertEqual($Person->getErrorsOn('first_name'), $Person->_defaultErrorMessages['blank']); } function Test_of_isValid() { $Person = new AkTestPerson('country->', 'ES'); $this->assertFalse($Person->isValid()); $this->assertEqual($Person->getErrors(), array('first_name' => array("can't be blank"), 'tos' => array("must be accepted"))); $Person->clearErrors(); $Person = $Person->findFirst(array('username = ?', 'bermi')); $Person->set('tos', 0); $this->assertFalse($Person->isValid()); $this->assertEqual($Person->getErrors(), array('email' => array("can't be blank"))); } } Ak::test('test_AkActiveRecord_validators', true);
$this->assertEqual($asset_tag->_compute_public_path('test', 'javascripts', 'js'), $this->testing_url_path . '/javascripts/test.js'); $this->assertEqual($asset_tag->_compute_public_path('http://www.example.com/logo.png'), 'http://www.example.com/logo.png'); $this->assertEqual($asset_tag->image_path('photo'), $this->testing_url_path . '/images/photo.png'); $this->assertEqual($asset_tag->image_path('photo.jpg'), $this->testing_url_path . '/images/photo.jpg'); $this->assertEqual($asset_tag->image_tag('summer_in_toronto', array('size' => '200x1000')), '<img alt="Summer in toronto" height="1000" src="' . $this->testing_url_path . '/images/summer_in_toronto.png" width="200" />'); $this->assertEqual($asset_tag->stylesheet_path('cool'), $this->testing_url_path . '/stylesheets/cool.css'); $this->assertEqual($asset_tag->stylesheet_path('cooler.style'), $this->testing_url_path . '/stylesheets/cooler.style'); $this->assertEqual($asset_tag->stylesheet_link_tag('cool', array('media' => 'all')), '<link href="' . $this->testing_url_path . '/stylesheets/cool.css" media="all" rel="Stylesheet" type="text/css" />' . "\n"); $this->assertEqual($asset_tag->stylesheet_link_tag('cool', 'cooler.style', array('media' => 'all')), '<link href="' . $this->testing_url_path . '/stylesheets/cool.css" media="all" rel="Stylesheet" type="text/css" />' . "\n" . '<link href="' . $this->testing_url_path . '/stylesheets/cooler.style" media="all" rel="Stylesheet" type="text/css" />' . "\n"); $this->assertEqual($asset_tag->javascript_path('ajax'), $this->testing_url_path . '/javascripts/ajax.js'); $this->assertEqual($asset_tag->javascript_path('superfx.javascript'), $this->testing_url_path . '/javascripts/superfx.javascript'); $this->assertEqual($asset_tag->javascript_include_tag('ajax'), '<script src="' . $this->testing_url_path . '/javascripts/ajax.js" type="text/javascript"></script>' . "\n"); $this->assertEqual($asset_tag->javascript_include_tag('ajax', 'superfx.javascript'), '<script src="' . $this->testing_url_path . '/javascripts/ajax.js" type="text/javascript"></script>' . "\n" . '<script src="' . $this->testing_url_path . '/javascripts/superfx.javascript" type="text/javascript"></script>' . "\n"); $this->assertEqual($asset_tag->javascript_include_tag('marquesine', array('charset' => 'iso-8859-1')), '<script charset="iso-8859-1" src="' . $this->testing_url_path . '/javascripts/marquesine.js" type="text/javascript"></script>' . "\n"); $defaults = $asset_tag->_get_javascript_included_defaults(); $defaults_count = count($defaults); $this->assertTrue($defaults_count > 0); $asset_tag->register_javascript_include_default('akelos_fx'); $new_defaults = $asset_tag->_get_javascript_included_defaults(); $new_defaults_count = count($new_defaults); $this->assertEqual('akelos_fx', array_pop($new_defaults)); $this->assertEqual($defaults_count + 1, $new_defaults_count); $asset_tag->register_javascript_include_default('another_fx'); $this->assertTrue(strstr($asset_tag->javascript_include_tag(), '<script src="' . $this->testing_url_path . '/javascripts/another_fx.js" type="text/javascript"></script>' . "\n")); $asset_tag->reset_javascript_include_default(); $this->assertEqual($defaults_count, count($asset_tag->_get_javascript_included_defaults())); $this->assertEqual($asset_tag->auto_discovery_link_tag(), '<link href="/url/for/test" rel="alternate" title="RSS" type="application/rss+xml" />'); } } Ak::test('AssetTagHelperTests');
$this->assertTrue(strstr(trim(str_replace("\n", '', $FormOptionsHelper->country_select('person', 'country', array('Spain' => 'ESP', 'Ireland' => 'IRL'), array('onclick' => 'alert(this.value)'), array('onblur' => 'alert(this.value)', 'multiple' => 'multiple')))), '<option onclick="alert(this.value)" selected="selected" value="FRA">France</option>')); $this->assertTrue(strstr(trim(str_replace("\n", '', $FormOptionsHelper->time_zone_select('person', 'timezone', array('(GMT +01:00) Madrid' => 'Madrid'), array('prompt' => true), array('style' => 'border:5px solid red;')))), '<select id="person_timezone" name="person[timezone]" style="border:5px solid red;">' . '<option value="">Please select</option>' . '<option value="Madrid">(GMT +01:00) Madrid</option>' . '<option value="">-------------</option>')); $Person->setReturnValue('get', 'Budapest', array('timezone')); $this->assertTrue(strstr(trim(str_replace("\n", '', $FormOptionsHelper->time_zone_select('person', 'timezone', array('(GMT +01:00) Madrid' => 'Madrid'), array('prompt' => true), array('style' => 'border:5px solid red;')))), '<option selected="selected" value="Budapest">(GMT+01:00) Budapest</option>')); $this->assertEqual($FormOptionsHelper->options_for_select(array('VISA', 'MasterCard'), 'MasterCard'), '<option value="VISA">VISA</option>' . "\n" . '<option selected="selected" value="MasterCard">MasterCard</option>' . "\n"); $this->assertEqual($FormOptionsHelper->options_for_select(array('Dollar' => '$', 'Kroner' => 'DKK')), '<option value="$">Dollar</option>' . "\n" . '<option value="DKK">Kroner</option>' . "\n"); $this->assertEqual($FormOptionsHelper->options_for_select(array('Basic' => '$20', 'Plus' => '$40'), '$40'), '<option value="$20">Basic</option>' . "\n" . '<option selected="selected" value="$40">Plus</option>' . "\n"); $this->assertEqual($FormOptionsHelper->options_for_select(array('VISA', 'MasterCard', 'Discover'), array('VISA', 'Discover')), '<option selected="selected" value="VISA">VISA</option>' . "\n" . '<option value="MasterCard">MasterCard</option>' . "\n" . '<option selected="selected" value="Discover">Discover</option>' . "\n"); $Project =& new MockAkActiveRecord($this); $Person =& new MockAkActiveRecord($this); $Person->setReturnValue('get', '100', array('id')); $Person->setReturnValue('get', 'Bermi', array('name')); $Person2 =& new MockAkActiveRecord($this); $Person2->setReturnValue('get', '200', array('id')); $Person2->setReturnValue('get', 'Hilario', array('name')); $Person3 =& new MockAkActiveRecord($this); $Person3->setReturnValue('get', '250', array('id')); $Person3->setReturnValue('get', 'Salavert', array('name')); $Project->People = array(&$Person, &$Person2, &$Person3); $FormOptionsHelper =& new FormOptionsHelper(); $this->assertEqual($FormOptionsHelper->options_from_collection_for_select($Project->People, 'id', 'name'), '<option value="100">Bermi</option>' . "\n" . '<option value="200">Hilario</option>' . "\n" . '<option value="250">Salavert</option>' . "\n"); $this->assertEqual($FormOptionsHelper->options_from_collection_for_select($Project->People, 'id', 'name', array(100, 200)), '<option selected="selected" value="100">Bermi</option>' . "\n" . '<option selected="selected" value="200">Hilario</option>' . "\n" . '<option value="250">Salavert</option>' . "\n"); $AkTestContinentsGroup = array(new AkTestContinent('Africa', array(new AkTestCountry('EGP', 'Egipt'), new AkTestCountry('RWD', 'Rwanda'))), new AkTestContinent('Asia', array(new AkTestCountry('ZHN', 'China'), new AkTestCountry('IND', 'India'), new AkTestCountry('JPN', 'Japan')))); $this->assertEqual(str_replace("\n", '', $FormOptionsHelper->option_groups_from_collection_for_select($AkTestContinentsGroup, 'getCountriesCollection', 'getContinentName', 'getCountryId', 'getCountryName', 'JPN')), '<optgroup label="Africa">' . '<option value="EGP">Egipt</option>' . '<option value="RWD">Rwanda</option>' . '</optgroup>' . '<optgroup label="Asia">' . '<option value="ZHN">China</option>' . '<option value="IND">India</option>' . '<option selected="selected" value="JPN">Japan</option>' . '</optgroup>'); /** * @todo add tests for AkFormOptionsHelperBuilder */ } } Ak::test('FormOptionsHelperTests', true);
$file = Ak::file_get_contents(__FILE__); $ecripted = Ak::encrypt($file, $key); $this->assertEqual(Ak::decrypt($ecripted, $key), $file); } function Test_of_compress_decompress() { $original = Ak::file_get_contents(__FILE__); $compressed = Ak::compress($original); Ak::file_put_contents(AK_TEST_DIR . DS . 'tmp' . DS . 'gzip_test.gz', $compressed); $this->assertTrue(strlen($compressed) < strlen($original)); $compressed_file = Ak::file_get_contents(AK_TEST_DIR . DS . 'tmp' . DS . 'gzip_test.gz'); $this->assertEqual($compressed_file, $compressed); $uncompressed_from_file = Ak::uncompress($compressed_file); $uncompressed_from_string = Ak::uncompress($compressed); $this->assertEqual($uncompressed_from_file, $uncompressed_from_string); } /**/ function Test_for_StatusKeys() { $Object = new Ak(); $this->assertFalse(Ak::objectHasBeenModified($Object)); $this->assertEqual(Ak::getStatusKey($Object), Ak::getStatusKey($Object)); $Object->name = 'Bermi'; $this->assertTrue(Ak::objectHasBeenModified($Object)); $this->assertTrue(Ak::objectHasBeenModified($Object)); Ak::resetObjectModificationsWacther($Object); $this->assertFalse(Ak::objectHasBeenModified($Object)); } } Ak::test('test_of_Ak_object_inspection', true);
$this->assertEqual($number->number_to_phone(1235551234, array('delimiter' => ' ')), '123 555 1234'); $this->assertEqual($number->number_to_phone(1235551234, array('area_code' => true, 'extension' => 555)), '(123) 555-1234 x 555'); $this->assertEqual($number->number_to_currency("1234567890.50"), '$1,234,567,890.50'); $this->assertEqual($number->number_to_currency(123456789.123456, array('precision' => 2, 'unit' => ' Skk', 'unit_position' => 'right', 'separator' => ',', 'delimiter' => ' ')), '123 456 789,12 Skk'); $this->assertEqual($number->number_to_currency("1234567890.50"), '$1,234,567,890.50'); $this->assertEqual($number->number_to_currency(1234567890.506), '$1,234,567,890.51'); $this->assertEqual($number->number_to_currency(1234567890.5, array('unit' => "£", 'separator' => ",", 'delimiter' => "")), '£1234567890,50'); $this->assertEqual($number->number_to_currency(1234567890.5, array('unit' => " €", 'separator' => ",", 'delimiter' => ".", 'unit_position' => 'right')), '1.234.567.890,50 €'); $this->assertEqual($number->number_to_percentage(100), '100.00%'); $this->assertEqual($number->number_to_percentage(100, array('precision' => 0)), '100%'); $this->assertEqual($number->number_to_percentage(302.0576, array('precision' => 3)), '302.058%'); $this->assertEqual($number->number_with_delimiter(12345678), '12,345,678'); $this->assertEqual($number->number_with_delimiter(12345678.2), '12,345,678.2'); $this->assertEqual($number->human_size(123), '123 Bytes'); $this->assertEqual($number->human_size(1234), '1.2 KB'); $this->assertEqual($number->human_size(12345), '12.1 KB'); $this->assertEqual($number->human_size(1234567), '1.2 MB'); $this->assertEqual($number->human_size(1234567890), '1.1 GB'); $this->assertEqual($number->human_size_to_bytes('123 Bytes'), 123); $this->assertEqual($number->human_size_to_bytes('1.2 KB'), 1229); $this->assertEqual($number->human_size_to_bytes('12.1 KB'), 12391); $this->assertEqual($number->human_size_to_bytes('1.2 MB'), 1258292); $this->assertEqual($number->human_size_to_bytes('1.1 GB'), 1181116007); $this->assertEqual($number->number_with_precision(111.2345), '111.235'); $this->assertEqual($number->zeropad(123, 6), '000123'); $this->assertEqual($number->zeropad('0123', 6), '000123'); $this->assertEqual($number->zeropad(12345, 2), '12345'); } } Ak::test('NumberHelperTests');
<?php require_once '_HelpersUnitTester.php'; require_once AK_LIB_DIR . DS . 'AkActionView' . DS . 'helpers' . DS . 'active_record_helper.php'; class ActiveRecordHelperTests extends HelpersUnitTester { /** * @todo Add tests for active record helper */ function tests_pending() { } } Ak::test('ActiveRecordHelperTests');
$this->assertEqual($Request->_request['ak'], 'post/es_es'); $this->assertEqual($Request->ak, 'post/es_es'); $Request->ak = 'es/post'; $Request->_request['ak'] = 'es/post'; unset($Request->lang); $result = $this->LocaleManager->getLangFromUrl($Request); $this->assertFalse($result); $this->assertEqual($Request->_request['ak'], 'es/post'); $this->assertEqual($Request->ak, 'es/post'); $Request->ak = 'spain/people'; $Request->_request['ak'] = 'spain/people'; unset($Request->lang); $result = $this->LocaleManager->getLangFromUrl($Request); $expected = 'spain'; $this->assertEqual($result, $expected); $this->assertEqual($Request->_request['ak'], 'people'); $this->assertEqual($Request->ak, 'people'); //Falta devolver IDIOMA y no alias y cargar $request->lang } function Test_of_getLocaleFromAlias() { $this->LocaleManager->available_locales = $this->LocaleManager->_parseLocaleConfigString('es, en, fr (france)'); $result = $this->LocaleManager->getLocaleFromAlias('france'); $expected = 'fr'; $this->assertEqual($result, $expected); $result = $this->LocaleManager->getLocaleFromAlias('spain'); $this->assertFalse($result); } } Ak::test('Test_of_AkLocaleManager_Class');
$this->assertEqual($this->Object->message, 'filtered:AB'); } function test_of_around_filters() { $this->Object->aroundFilter(new TestingFiltersUtitlityClassWithFilterMethod('A'), new TestingFiltersUtitlityClassWithFilterMethod('B')); $this->Object->performAction(); $this->assertEqual($this->Object->message, 'before-B:before-A::A-after:B-after'); } function test_of_appendAroundFilter() { $this->Object->appendAroundFilter(new TestingFiltersUtitlityClassWithFilterMethod('A'), new TestingFiltersUtitlityClassWithFilterMethod('B')); $this->Object->performAction(); $this->assertEqual($this->Object->message, 'before-B:before-A::A-after:B-after'); } function test_of_prependAroundFilter() { $this->Object->prependAroundFilter(new TestingFiltersUtitlityClassWithFilterMethod('A'), new TestingFiltersUtitlityClassWithFilterMethod('B')); $this->Object->performAction(); $this->assertEqual($this->Object->message, 'before-A:before-B::B-after:A-after'); $this->Object->message = ''; $this->Object->beforeFilter('X'); $this->Object->afterFilter('Z'); $this->Object->performAction(); $this->assertEqual($this->Object->message, 'before-A:before-B:X:B-after:A-afterZ'); } } if (!defined('ALL_TESTS_CALL')) { ob_start(); Ak::test('Test_of_AkActionControllerFilters'); ob_end_flush(); }
$this->assertTrue(AkFtp::delete('new_dir_2')); $this->assertTrue(AkFtp::delete('../new_dir_3')); $this->assertTrue(AkFtp::delete('./new_dir_4')); $this->assertTrue(AkFtp::delete('./new_dir_5/')); $this->assertTrue(AkFtp::delete('new_dir_6/')); $this->assertTrue(AkFtp::delete('/new_dir_7')); $this->assertTrue(AkFtp::delete('/new_dir_8/')); } function Test_is_dir() { $path = 'invalid path'; $this->assertFalse(AkFtp::is_dir($path)); $path = 'this_is_a_file.txt'; Ak::file_put_contents('this_is_a_file.txt', ''); $this->assertFalse(AkFtp::is_dir($path)); AkFtp::make_dir('tmp_test_dir'); Ak::file_put_contents('tmp_test_dir/file_inside.txt', ''); $path = 'tmp_test_dir/file_inside.txt'; $this->assertFalse(AkFtp::is_dir($path)); AkFtp::make_dir('real_dir/another/dir'); $path = 'real_dir'; $this->assertTrue(AkFtp::is_dir($path)); $path = 'real_dir/another/dir'; $this->assertTrue(AkFtp::is_dir($path)); AkFtp::delete('real_dir'); AkFtp::delete('this_is_a_file.txt'); AkFtp::delete('tmp_test_dir'); } } Ak::test('test_AkFileFunctionsUsingFtp');