{ $AkTestUser = new AkTestUser(); $AkTestUser->getColumns(); // Loads settings $AkTestUser->resetColumnInformation(); $this->assertTrue(empty($AkTestUser->_columnNames) && empty($AkTestUser->_columns) && empty($AkTestUser->_columnsSettings) && empty($AkTestUser->_contentColumns)); } function Test_of_freeze_and_isFrozen() { $AkTestMember = new AkTestMember(); $this->assertFalse($AkTestMember->isFrozen()); $AkTestMember->freeze(); $this->assertTrue($AkTestMember->isFrozen()); } function Test_of_count() { $AkTestUser = new AkTestUser(); $this->assertEqual($AkTestUser->count(), count($AkTestUser->find())); $this->assertEqual($AkTestUser->count("first_name = 'Tim'"), count($AkTestUser->findAll("first_name = 'Tim'"))); } function Test_of_countBySql() { $AkTestUser = new AkTestUser(); $this->assertEqual($AkTestUser->countBySql("SELECT COUNT(*) FROM ak_test_users"), count($AkTestUser->find())); $this->assertEqual($AkTestUser->countBySql("SELECT COUNT(*) FROM ak_test_users WHERE first_name = 'Tim'"), count($AkTestUser->findAll("first_name = 'Tim'"))); } } require_once '_AkActiveRecord_1.php'; require_once '_AkActiveRecord_2.php'; ak_test('test_AkActiveRecord_3', true);
}'; $class = new AkReflectionClass($string); $array = $class->_definition; $class = new AkReflectionClass($array); $this->assertEqual('Test', $class->getName()); $methods = $class->getMethods(); $this->assertEqual(2, count($methods)); $this->assertEqual('method1', $methods[0]->getName()); $this->assertFalse($methods[0]->returnByReference()); $this->assertEqual('method2', $methods[1]->getName()); $this->assertTrue($methods[1]->returnByReference()); $docBlock = $methods[1]->getDocBlock(); $this->assertTrue(is_a($docBlock, 'AkReflectionDocBlock')); $this->assertEqual('comment', $docBlock->getComment()); $params = $docBlock->getParams(); $this->assertEqual(2, count($params)); $this->assertEqual('void', $docBlock->getTag('return')); $voidMethods = $class->getMethods(array('tags' => array('return' => 'void'))); $this->assertEqual(1, count($voidMethods)); } function test_get_methods_filtered() { $file = AK_TEST_DIR . DS . 'fixtures' . DS . 'data' . DS . 'reflection_test_class.php'; $class = new AkReflectionClass(file_get_contents($file)); $filteredMethods = $class->getMethods(array('tags' => array('WingsPluginInstallAs' => '.*'))); $this->assertEqual(1, count($filteredMethods)); $this->assertEqual('testFunction2', $filteredMethods[0]->getName()); } } ak_test('AkReflectionClass_TestCase', true);
} function test_strip_tags() { $this->assertEqual($this->text->strip_tags('<a href="nowhere" onclick="javascript:alert(\'oops\');">link</a>'), 'link'); } function test_markdown() { $this->assertEqual($this->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');
$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');
$this->assertEqual('This Is A Test', $string->titleize()); $string =& AkT("ThisIsATest"); $this->assertEqual('This Is A Test', $string->titleize()); } public function test_length() { $text = "this_is_a_test"; $string =& AkT($text); $this->assertEqual(strlen($text), $string->length()); } public function test_pluralize() { $text = "Comment"; $string =& AkT($text); $this->assertEqual('Comments', $string->pluralize()); $string =& AkT($text, 'pluralize'); $this->assertEqual('Comments', $string); $string = AkT('inglés', 'pluralize(es)'); $this->assertEqual('ingleses', $string); } public function test_singularize() { $text = "Comments"; $string =& AkT($text); $this->assertEqual('Comment', $string->singularize()); $string =& AkT($text, 'singularize'); $this->assertEqual('Comment', $string); } } ak_test('Test_AkString');
} function test_begin_without_label() { $str = "test CaptureHelper #1"; $this->capture_helper->begin(); echo $str; $this->assertEqual($this->capture_helper->end(), $str); $globals = AkActionView::_getGlobals(); $this->assertEqual(isset($globals['content_for_']) ? $globals['content_for_'] : null, null); } function test_begin_with_label() { $str = "test CaptureHelper #2"; $this->capture_helper->begin('test_2'); echo $str; $this->assertEqual($this->capture_helper->end(), $str); $globals = AkActionView::_getGlobals(); $this->assertEqual($globals['content_for_test_2'], $str); } function test_content_for() { $str = "test CaptureHelper content_for"; $this->capture_helper->content_for('content_for'); echo $str; $this->assertEqual($this->capture_helper->end(), $str); $globals = AkActionView::_getGlobals(); $this->assertEqual($globals['content_for_content_for'], $str); } } ak_test('CaptureHelperTests');
$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_TMP_DIR . DS . 'gzip_test.gz', $compressed, array('base_path' => AK_TMP_DIR)); $this->assertTrue(strlen($compressed) < strlen($original)); $compressed_file = Ak::file_get_contents(AK_TMP_DIR . DS . 'gzip_test.gz', array('base_path' => AK_TMP_DIR)); $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);
public function _getNestedSetList($Categories = null, $breadcrumb = false) { if(!isset($Categories)){ $Categories = new NestedCategory(); $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 '_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); } function test_javascript_tag() { $javascript = new JavaScriptHelper(); //static call $this->AssertEqual(JavascriptHelper::javascript_tag("alert('test akelos');"), "<script type=\"text/javascript\">\n//<![CDATA[\nalert('test akelos');\n//]]>\n</script>"); //object call $this->AssertEqual($javascript->javascript_tag("alert('test akelos');"), "<script type=\"text/javascript\">\n//<![CDATA[\nalert('test akelos');\n//]]>\n</script>"); } } ak_test('JavaScriptHelperTests');
{ $this->assertFalse($this->cross_meridian->contains($this->east_of_cm)); $this->assertFalse($this->cross_meridian->contains($this->west_of_cm)); } function test_center() { $latlng = $this->bounds->center(); $this->assertWithinMargin(32.939828, $latlng->get('lat'), 5.0E-5); $this->assertWithinMargin(-96.9511763, $latlng->get('lng'), 5.0E-5); } function xtest_center_cross_meridian() { $latlng = $this->cross_meridian->center(); $this->assertWithinMargin(35.4116, $latlng->get('lat'), 5.0E-5); $this->assertWithinMargin(179.38112, $latlng->get('lng'), 5.0E-5); } function test_creation_from_circle() { $bounds = Bounds::from_point_and_radius(array(32.939829, -96.951176), 2.5); $inside = new LatLng(32.969527, -96.99015900000001); $outside = new LatLng(32.895155, -96.958444); $this->assertTrue($bounds->contains($inside)); $this->assertFalse($bounds->contains($outside)); } } // class BoundsTestCase $use_sessions = true; ak_test('BoundsTestCase', $use_sessions); ?>
$this->assertEqual($this->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($this->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($this->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($this->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($this->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($this->url->link_to_unless(true,'Destroy account', array('action' => 'destroy'), array('confirm' => 'Are you sure?'), array('post' => true)),''); $this->assertEqual($this->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($this->url->_popup_javascript_function('A'),'window.open(this.href);'); $this->assertEqual($this->url->_popup_javascript_function(array('A','B','C')),'window.open(this.href,\'A\',\'C\');'); $this->assertEqual($this->url->_confirm_javascript_function('Are you sure?'),'confirm(\'Are you sure?\')'); $this->assertEqual($this->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($this->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($this->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>'); } function test_should_encode_utf8_characters_as_entities_when_encoding_mail_to_links() { $escaped_iacute = '%26%69%61%63%75%74%65%3b'; $this->assertTrue(strstr($this->url->mail_to('*****@*****.**', 'mounstro de pulsa aquí', array('encode' => 'javascript')), $escaped_iacute)); } } ak_test('UrlHelperTests'); ?>
$Mary->friend->add($this->Friend->create(array('name' => 'James'))); //$db = new AkDbAdapter(array()); // no conection details, we're using a Mock Mock::generate('ADOConnection'); $connection = new MockADOConnection(); $result = new ADORecordSet_array(-1); $result->InitArray(array(array('id' => 1, 'name' => 'James')), array('id' => 'I', 'name' => 'C')); $connection->setReturnValue('Execute', $result); if ($Mary->_db->type() == 'sqlite') { $connection->expectAt(0, 'Execute', array('SELECT friends.* FROM friends LEFT OUTER JOIN friends_friends AS _FriendFriend ON _FriendFriend.related_id = friends.id LEFT OUTER JOIN friends AS _Friend ON _FriendFriend.friend_id = _Friend.id WHERE (friends.name = ?) AND (_FriendFriend.friend_id LIKE 1) AND 1', array('James'))); } else { $connection->expectAt(0, 'Execute', array('SELECT friends.* FROM friends LEFT OUTER JOIN friends_friends AS _FriendFriend ON _FriendFriend.related_id = friends.id LEFT OUTER JOIN friends AS _Friend ON _FriendFriend.friend_id = _Friend.id WHERE (friends.name = ?) AND (_FriendFriend.friend_id = 1)', array('James'))); } $oldConnection = $Mary->_db->connection; $Mary->_db->connection =& $connection; //$Mary->_db = $db; $Mary->friend->find(array('conditions' => array('name = ?', 'James'))); $Mary->_db->connection = $oldConnection; } public function test_find_on_association_with_conditions_array() { $this->installAndIncludeModels(array('Friend' => 'id,name')); $Mary =& $this->Friend->create(array('name' => 'Mary')); $Mary->friend->add($this->Friend->create(array('name' => 'James'))); $Mary->save(); $result = $Mary->friend->find(array('conditions' => array('name = ?', 'James'))); $James = $result[0]; $this->assertEqual($Mary->friends[0]->name, $James->name); } } ak_test('HasAndBelongsToManyTestCase');
} public function test_find_aa_include_bbs_with_custom_handler_name_return_array() { $aa =& $this->Aa->create(array('name' => 'first aa')); $this->assertTrue($aa); $bb1 =& $this->Bb->create(array('name' => 'first bb')); $bb2 =& $this->Bb->create(array('name' => 'second bb')); $babies = array($bb1, $bb2); $aa->babies->set($babies); $this->assertEqual(2, count($aa->bbs)); /** * now find them back in order */ $found_first_aa = $this->Aa->findFirstBy('name', 'first aa', array('returns' => 'array', 'include' => array('bbs' => array('order' => 'id ASC')))); $this->assertTrue($found_first_aa); $this->assertTrue($found_first_aa['bbs']); $this->assertEqual(2, count($found_first_aa['bbs'])); $this->assertEqual('first bb', $found_first_aa['bbs'][0]['name']); $this->assertEqual('second bb', $found_first_aa['bbs'][1]['name']); /** * now find them back in order and add a condition for the bbs */ $found_first_aa = $this->Aa->findFirstBy('name', 'first aa', array('returns' => 'array', 'include' => array('bbs' => array('order' => 'id ASC', 'conditions' => 'name LIKE ?', 'bind' => '%second%')))); $this->assertTrue($found_first_aa); $this->assertTrue($found_first_aa['bbs']); $this->assertEqual(1, count($found_first_aa['bbs'])); $this->assertEqual('second bb', $found_first_aa['bbs'][0]['name']); } } ak_test('test_AkActiveRecord_return_types', true);
$this->failure->city = "(Private Address)"; $this->failure->success = false; $this->controller = new LocationAwareController(); $this->request = new TestRequest(); # ActionController::TestRequest $this->response = new TestResponse(); # ActionController::TestResponse } // function test_setup function test_no_location_in_cookie_or_session() { # GeoKit::Geocoders::IpGeocoder.expects(:geocode).with("good ip").returns(@success) # @request.remote_ip = "good ip" # get :index # verify $good_ip = "12.215.42.19"; $ip_geocoder = new IpGeocoder(); $address = $ip_geocoder->geocode($good_ip); $this->request->remote_ip = $good_ip; # $response = $this->request->get('body'); #print_r($response); # $this->assertEqual($response['body'],$this->success); # $this->verify(); } } // class IpGeocodeLookupTestCase $use_sessions = true; ak_test('IpGeocodeLookupTestCase', $use_sessions); ?>
} function test_should_show_login_with_realm() { $this->setMaximumRedirects(0); $this->get(AK_TESTING_URL . '/authentication/edit'); $this->assertRealm('App name'); $this->assertNoText("I'm only accessible if you know the password"); } function test_should_fail_login() { $this->setMaximumRedirects(0); $this->get(AK_TESTING_URL . '/authentication/edit'); $this->authenticate('bermi', 'badpass'); $this->assertResponse(401); $this->assertNoText("I'm only accessible if you know the password"); } function test_should_login() { $this->setMaximumRedirects(0); $this->get(AK_TESTING_URL . '/authentication/edit'); $this->authenticate('bermi', 'secret'); $this->assertResponse(200); $this->assertText("I'm only accessible if you know the password"); // still logged in? $this->get(AK_TESTING_URL . '/authentication/edit'); $this->assertResponse(200); $this->assertText("I'm only accessible if you know the password"); } } ak_test('_AkActionController_http_authentication');
function test($test_case_name, $use_sessions = false) { ak_test($test_case_name, $use_sessions); }
} /** * Creates an ExtendedPost with type value 'ExtendedPost' * */ public function test_has_many_inheritance() { $this->installAndIncludeModels(array('ExtendedPost', 'ExtendedComment')); $Post = new ExtendedPost(array('title' => 'Post for unit testing', 'body' => 'This is a post for testing the model','type' => 'Extended post')); $Post->extended_comment->create(array('body' => 'hello', 'name' => 'Aditya')); $Post->save(); $Post->reload(); $expected_id = $Post->getId(); $Result =& $Post->find($expected_id, array('include' => array('extended_comments'), 'conditions' => "name = 'Aditya'")); $this->assertTrue($Result); if ($Result) { $this->assertEqual($Result->extended_comments[0]->get('name'), 'Aditya'); } } } ak_test('test_AkHasMany_table_inheritance',true); ?>
$this->assertEqual($this->Client->getResponseHeader('x-test-header'), 'akelos'); } function test_should_get_response_code() { $this->Client->get($this->url . '/code/201'); $this->assertEqual($this->Client->getResponseCode(), 201); } function test_should_set_user_agent() { $this->assertEqual($this->Client->get($this->url . '/get_user_agent'), 'Akelos PHP Framework AkHttpClient (http://akelos.org)'); $this->assertEqual(Ak::url_get_contents($this->url . '/get_user_agent'), 'Akelos PHP Framework AkHttpClient (http://akelos.org)'); $this->assertEqual(Ak::url_get_contents($this->url . '/get_user_agent', array('header' => array('user-agent' => 'Testing agent'))), 'Testing agent'); } function test_should_send_params() { $params = array('testing' => array('user' => 'bermi', 'nested' => array('one', 'two'))); $expected = Ak::toJson($params['testing']); Ak::compat('http_build_query'); $query = http_build_query($params); foreach ($this->verbs as $verb) { $this->assertEqual($this->Client->{$verb}($this->url . '/json/?' . $query), $expected, "{$verb} passing params via url"); $this->assertEqual($this->Client->{$verb}($this->url . '/json', array('params' => $params)), $expected, "{$verb} passing params via params option"); } } function should_accept_redirects() { $this->assertEqual(Ak::url_get_contents($this->url . '/redirect_1'), 3); } } ak_test('Test_of_AkHttpClient', true);
foreach ($File->tags as $Tag) { $this->assertEqual($Tag->name, $LogTag->name); $Tag->tagging->load(); foreach ($Tag->taggings as $Tagging) { $this->assertEqual($Tagging->tag_id, $LogTag->id); } } } $File =& new File(); $Files =& $File->find('all', array('include' => array('tags'))); $tag_ids = array(); foreach ($Files as $File) { foreach ($File->tags as $Tag) { $tag_ids[] = $Tag->getId(); } } $Tag =& new Tag(); $Tags =& $Tag->find($tag_ids, array('include' => 'taggings')); foreach (array_keys($Files) as $k) { foreach (array_keys($Files[$k]->tags) as $m) { foreach (array_keys($Tags) as $n) { if ($Tags[$n]->id == $Files[$k]->tags[$m]->id) { $Files[$k]->tags[$m]->taggings =& $Tags[$n]->taggings; } } } } } } ak_test('test_AkActiveRecord_multiple_inclussion', true);
{ $this->assertEqual($this->javascript_macros_helper->in_place_editor('field_id', array('url' => array('controller' => 'foo', 'action' => 'bar', 'id' => 'beer'))), "<script type=\"text/javascript\">\n//<![CDATA[\nnew Ajax.InPlaceEditor('field_id', '/foo/bar/beer')\n//]]>\n</script>"); } // To implement when in_place_editor_field will be updated function test_in_place_editor_field() { } function test_in_auto_complete_field() { $this->assertEqual($this->javascript_macros_helper->auto_complete_field('field_id', array('url' => array('controller' => 'foo', 'action' => 'bar'))), "<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>"); } function test_in_auto_complete_result() { $objects = array(); for ($i = 0; $i < 10; $i++) { $object = array(); $object['test'] = $i; $objects[] = $object; } $this->assertEqual($this->javascript_macros_helper->auto_complete_result($objects, 'test'), "<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>"); } function test_text_field_with_auto_complete() { $style = file_get_contents(AK_TEST_HELPERS_DIR . DS . 'javascript_macros_helper_style.txt'); $code = file_get_contents(AK_TEST_HELPERS_DIR . DS . 'javascript_macros_helper_code.txt'); $this->assertEqual($this->javascript_macros_helper->text_field_with_auto_complete('user', 'login', array(), array('url' => array('controller' => 'foo', 'action' => 'bar'))), $style . $code); $this->assertEqual($this->javascript_macros_helper->text_field_with_auto_complete('user', 'login', array(), array('url' => array('controller' => 'foo', 'action' => 'bar'), 'skip_style' => true)), $code); } } ak_test('JavaScriptMacrosHelperTests');
$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'); ?>
{ public function test_single_class() { $filename = AK_TEST_DIR . DS . 'fixtures' . DS . 'data' . DS . 'reflection_test_class.php'; $file = new AkReflectionFile($filename); $this->assertEqual(1, count($file->getClasses())); $classes = $file->getClasses(); $this->assertEqual('ReflectionTestClass1', $classes[0]->getName()); } public function test_multiple_classes() { $filename = AK_TEST_DIR . DS . 'fixtures' . DS . 'data' . DS . 'reflection_test_classes.php'; $file = new AkReflectionFile($filename); $this->assertEqual(2, count($file->getClasses())); $classes = $file->getClasses(); $this->assertEqual('ReflectionTestClass1', $classes[0]->getName()); $this->assertEqual('ReflectionTestClass2', $classes[1]->getName()); } public function test_special1() { $filename = AK_TEST_DIR . DS . 'fixtures' . DS . 'data' . DS . 'reflection_doc_block_test_class.php'; $file = new AkReflectionFile($filename); $this->assertEqual(1, count($file->getClasses())); $classes = $file->getClasses(); $this->assertEqual('ReflectionDocBlockTestClass', $classes[0]->getName()); $class = $classes[0]; $this->assertEqual('BaseActiveRecord', $class->getTag('ExtensionPoint')); } } ak_test('AkReflectionFile_TestCase', true);
$development_connection =& $Model->establishConnection('development'); $available_tables_on_development = $development_connection->availableTables(); $this->assertFalse($development_connection===$default_connection); $this->assertFalse($Model->establishConnection('not_specified_profile')); $this->assertError("The environment not_specified_profile is not allowed. Allowed environments: setup,testing,development,production"); $this->assertError("Could not find the database profile 'not_specified_profile' in config/database.yml."); $check_default_connection =& AkDbAdapter::getInstance(); $this->assertReference($default_connection,$check_default_connection); $this->assertReference($default_connection->connection,$check_default_connection->connection); //because we dont get two different connections at the same time on PHP if user and password is identical //thus: !$this->assertEqual($available_tables_on_default,$check_default_connection->availableTables()); //we have to: $check_default_connection->connect(); //now we get: $this->assertEqual($available_tables_on_default,$check_default_connection->availableTables()); //BUT again: !! //$this->assertNotEqual($available_tables_on_development,$development_connection->availableTables()); //$this->assertEqual($available_tables_on_default,$development_connection->availableTables()); } } ak_test('AkActiveRecord_connection_handling_TestCase',true); ?>
<?php defined('AK_TEST_DATABASE_ON') ? null : define('AK_TEST_DATABASE_ON', true); require_once dirname(__FILE__) . '/../../../fixtures/config/config.php'; class _AkActionController_model_instantiation extends AkWebTestCase { public function test_setup() { $TestSetup = new AkUnitTest(); $TestSetup->installAndIncludeModels(array('Post', 'Comment', 'Tag')); $Post =& $TestSetup->Post->create(array('title' => 'One', 'body' => 'First post')); foreach (range(1, 5) as $n) { $Post->comment->add(new Comment(array('body' => AkInflector::ordinalize($n) . ' post'))); } $Post->save(); $Post->reload(); $Post->comment->load(); $this->assertEqual($Post->comment->count(), 5); $this->post_id = $Post->id; } public function test_should_access_public_action() { $this->setMaximumRedirects(0); $this->get(AK_TESTING_URL . '/post/comments/' . $this->post_id); $this->assertResponse(200); $this->assertTextMatch('1st post2nd post3rd post4th post5th post'); } } ak_test('_AkActionController_model_instantiation', true);
$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(); }
'<div class="nameError">before is invalid after</div>' ); } function test_error_messages_for() { $this->LuckyLuke->addError('birthday'); $this->assertEqual( $this->active_record_helper->error_messages_for('ProtectedPerson'), file_get_contents(AK_TEST_HELPERS_DIR.DS.'active_record_errors.txt') ); $this->assertEqual( $this->active_record_helper->error_messages_for('ProtectedPerson', array('header_tag'=>'h3','id'=>'LuckyLukeErrors','class'=>'errors')), file_get_contents(AK_TEST_HELPERS_DIR.DS.'active_record_errors_2.txt') ); } function test_textarea_should_escape_characters_correctly() { $this->assertEqual( $this->active_record_helper->form('Property'), file_get_contents(AK_TEST_HELPERS_DIR.DS.'active_record_textarea_should_escape_characters_correctly.txt') ); } } ak_test('ActiveRecordHelperTests'); ?>
return; } $retrieved = $this->memcache->get('test_id_10','strings'); $this->assertTrue($retrieved!=null); $this->memcache->clean('strings'); $retrieved = $this->memcache->get('test_id_10','strings'); $this->assertTrue($retrieved==null); $retrieved = $this->memcache->get('test_id_9','strings'); $this->assertTrue($retrieved==null); $retrieved = $this->memcache->get('test_id_8','strings'); $this->assertTrue($retrieved==null); $retrieved = $this->memcache->get('test_id_2','integers'); $this->assertTrue($retrieved!=null); } function _generateLargeString($size) { $string = ''; while(strlen($string)<$size) { $string .= md5(time()); } return $string; } } ak_test('Test_AkMemcache'); ?>
{ $result = false; if (!empty($meta_details) && is_array($meta_details)) { foreach ($meta_details as $k => $meta_detail) { if (empty($search) && strstr($k, 'idx')) { $result = true; } elseif (strstr($k, $search)) { $result = true; } } } return $result; } function test_should_create_default_values_correctly() { $this->installAndIncludeModels(array('Thumbnail')); $Thumbnail =& new Thumbnail(); $this->assertEqual($Thumbnail->get('owner'), 'Picture'); } // see AkDbAdapter_schema for the tests; this is only a wrapper function test_should_rename_columns() { $this->Installer->renameColumn('test_defaults', 'screen_name', 'real_name'); if ($this->Installer->db->type() == 'sqlite') { $this->assertError(); } $this->Installer->dropTable('test_defaults'); } } ak_test('Test_of_AkInstaller', true);
$this->assertTrue($found_first_aa->bbs[1]->ccs[0]->dd); $this->assertEqual('third dd',$found_first_aa->bbs[1]->ccs[0]->dd->name); $this->assertTrue($found_first_aa->bbs[1]->ccs[0]->dd->easy); $this->assertEqual(1,$found_first_aa->bbs[1]->ccs[0]->dd->easy->count()); if ($this->Aa->_db->type()=='postgre') { /** * from postgres docs: * * A value of type name is a string of 63 or fewer characters. * A name must start with a letter or an underscore; * the rest of the string can contain letters, digits, and underscores. * * IF a column name here is over 63 characters long, the assoc finder will fail */ } else { $this->assertTrue($found_first_aa->bbs[1]->ccs[0]->dd->ees[0]->somethings); $this->assertEqual($aa->name,$found_first_aa->bbs[1]->ccs[0]->dd->ees[0]->somethings[0]->name); } } } ak_test('AkActiveRecord_nested_finders_TestCase',true); ?>
} function test_remove_existing_associates_before_setting_by_id() { $this->installAndIncludeModels(array('Post', 'Comment')); foreach (range(1, 10) as $i) { $Post =& new Post(array('title' => 'Post ' . $i)); $Post->comment->create(array('name' => 'Comment ' . $i)); $Post->save(); } $Post11 =& new Post(array('name' => 'Post 11')); $this->assertTrue($Post11->save()); $Post->comment->setByIds(1, 2, 3, 4, 5); $this->assertTrue($Post =& $Post->find(10, array('include' => 'comments'))); // order cannot be guaranteed! $expected_ids = array(1, 2, 3, 4, 5); // on my postgreSQL $Post->comment->associated_ids = array(5,4,3,2,1); foreach (array_keys($Post->comments) as $k) { $this->assertTrue(in_array($Post->comments[$k]->getId(), $expected_ids)); unset($expected_ids[$Post->comments[$k]->getId() - 1]); } $this->assertTrue(empty($expected_ids)); // Comment 10 should exist but unrelated to a post $this->assertTrue($Comment =& $Post->comments[$k]->find(10)); $this->assertNull($Comment->get('post_id')); $Post11->comment->setByIds(array(10, 1)); $this->assertTrue($Comment =& $Comment->find(10)); $this->assertEqual($Comment->get('post_id'), 11); } } ak_test('HasManyTestCase', true);