{ public function test_single_class() { $filename = AkConfig::getDir('fixtures') . 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 = AkConfig::getDir('fixtures') . 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 = AkConfig::getDir('fixtures') . 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_case('ReflectionFile_TestCase');
$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'); } public function test_find_should_return_appropriate_models() { $Events = $this->Event->find('all'); $expected = array(1 => 'Event', 2 => 'Concert', 3 => 'OpenHouseMeeting'); foreach ($Events as $event) { $this->assertEqual($event->getType(), $expected[$event->getId()]); } } public function test_inheritance_should_lazy_load_right_model() { $this->installAndIncludeModels(array('Schedule' => 'id,name,event_id')); $this->Schedule->create(array('name' => 'to OpenHouseMeeting', 'event_id' => 3)); $this->Schedule->create(array('name' => 'to Event', 'event_id' => 1)); $this->Schedule->create(array('name' => 'to Concert', 'event_id' => 2)); $scheds = $this->Schedule->find('all'); foreach ($scheds as $schedule) { $schedule->event->load(); } $expected = array(1 => 'OpenHouseMeeting', 2 => 'Event', 3 => 'Concert'); foreach ($scheds as $schedule) { $this->assertEqual($schedule->event->getType(), $expected[$schedule->getId()]); } } } ak_test_case('TableInheritance_TestCase');
require_once dirname(__FILE__) . '/../config.php'; class Controller_forbidden_actions_TestCase extends AkWebTestCase { public $webserver_enabled; public function __construct() { $this->webserver_enabled = AkConfig::getOption('webserver_enabled', false); parent::__construct(); $this->_test_script = AkConfig::getOption('testing_url') . '/action_pack/public/index.php?ak='; } public function skip() { $this->skipIf(!$this->webserver_enabled, '[' . get_class($this) . '] Web server not enabled'); } public function test_should_ignore_underscored_methods() { $this->setMaximumRedirects(0); $this->get($this->_test_script . 'intranet/_forbidden'); $this->assertText('No action was specified'); } public function test_should_not_allow_calling_action_controller_methods() { $this->setMaximumRedirects(0); $this->get($this->_test_script . 'intranet/render'); $this->assertResponse(404); $this->assertText('Forbidden action render called'); } } ak_test_case('Controller_forbidden_actions_TestCase');
$func = new AkReflectionFunction($string); $func = new AkReflectionFunction($func->getDefinition()); $this->assertEqual('method2', $func->getName()); $this->assertEqual(array('test' => 1, 'test2' => 3, 'test3' => '$this->value'), $func->getDefaultOptions()); $this->assertEqual(array('test', 'test2', 'test3', 'test4'), $func->getAvailableOptions()); } public function test_add_doc_block_tag() { $string = ' /** * comment * @return void * @param $param1 * @param $param2 */ public function &method2($param1,$param2) { $default_options = array("test"=>1, "test2"=>3, "test3"=>$this->value); $available_options = array("test","test2","test3","test4"); echo $default_options; exit(); } }'; $func = new AkReflectionFunction($string); $func->setTag('WingsPluginInstaller', 'test'); //var_dump($func->toString()); } } ak_test_case('ReflectionFunction_TestCase');
} public function test_first_level_serialization() { $bb1 = $this->Bb->create(array('name' => 'first bb', 'languages' => array('en', 'es', 'de'))); $cc1 = $this->Cc->create(array('name' => 'first cc')); $cc2 = $this->Cc->create(array('name' => 'second cc')); $first_cc_group = array($cc1, $cc2); $bb1->cc->set($first_cc_group); $bb1->save(); $this->assertFalse($bb1->isNewRecord()); $bb1retrieved = $this->Bb->find($bb1->id); $this->assertFalse($bb1retrieved->isNewRecord()); $this->assertEqual(array('en', 'es', 'de'), $bb1retrieved->languages); } public function test_first_level_serialization_with_association_finder() { $bb1 = $this->Bb->create(array('name' => 'first bb', 'languages' => array('en', 'es', 'de'))); $cc1 = $this->Cc->create(array('name' => 'first cc')); $cc2 = $this->Cc->create(array('name' => 'second cc')); $first_cc_group = array($cc1, $cc2); $bb1->cc->set($first_cc_group); $bb1->save(); $this->assertFalse($bb1->isNewRecord()); $bb1retrieved = $this->Bb->find($bb1->id, array('include' => 'ccs')); $this->assertFalse($bb1retrieved->isNewRecord()); $this->assertTrue(is_array($bb1retrieved->ccs)); $this->assertEqual(array('en', 'es', 'de'), $bb1retrieved->languages); } } ak_test_case('Serialize_TestCase');
<?php require_once dirname(__FILE__) . '/../router.php'; class RouteUrlencodesParameters_TestCase extends AkRouteUnitTest { public function testParametrizeDecodesReturnedParameters() { $this->withRoute('/author/:name')->get('/author/Martin+L.+Degree')->matches(array('name' => 'Martin L. Degree')); } public function testUrlizeEncodesGivenParameters() { $this->withRoute('/author/:name')->urlize(array('name' => 'Martin L. Degree'))->returns('/author/Martin+L.+Degree'); } public function testParametrizeDecodesReturnedParametersWithFormat() { $this->withRoute('/author/:name.:format', array('format' => COMPULSORY))->get('/author/Martin+L.+Degree.pdf')->matches(array('name' => 'Martin L. Degree', 'format' => 'pdf')); } public function testUrlizeEncodesGivenParametersWithFormat() { $this->withRoute('/author/:name.:format', array('format' => COMPULSORY))->urlize(array('name' => 'Martin L. Degree', 'format' => 'pdf'))->returns('/author/Martin+L.+Degree.pdf'); } } ak_test_case('RouteUrlencodesParameters_TestCase');
$controller = $this->createControllerFor('index'); $controller->setLayout('application', array('only' => 'index')); $this->expectRender(array('index.html', AkConfig::getDir('views') . DS . 'layouts/application.tpl')); $controller->defaultRender(); } public function testPickLayoutUnlessActionameMatches() { $this->createViewTemplate('index.html'); $this->createTemplate('layouts/application.tpl'); $controller = $this->createControllerFor('index'); $controller->setLayout('application', array('except' => 'index')); $this->expectRender(array('index.html')); $controller->defaultRender(); } public function testPickFormatAccordingToRespondTo() { $this->createViewTemplate('index.xml'); $controller = $this->createControllerFor('index', 'xml'); $this->expectRender(array('index.xml')); $controller->defaultRender(); } public function testPickAlternativeHtmlTemplateFileWithoutTheHtmlExtension() { $this->createViewTemplate('index'); $controller = $this->createControllerFor('index'); $this->expectRender(array('index.html')); $controller->defaultRender(); } } ak_test_case('TemplatePaths_TestCase');
require_once dirname(__FILE__) . '/../config.php'; class Controller_model_instantiation_TestCase extends AkWebTestCase { public function test_setup() { $TestSetup = new AkUnitTest(); $TestSetup->rebaseAppPaths(); $TestSetup->installAndIncludeModels(array('DummyPost' => 'id, title, body, hip_factor int, comments_count, posted_on, expires_at', 'DummyComment' => 'id,name,body,dummy_post_id,created_at')); $this->webserver_enabled = AkConfig::getOption('webserver_enabled', false); $this->_test_script = AkConfig::getOption('testing_url') . '/action_pack/public/index.php?ak='; } public function __destruct() { $TestSetup = new AkUnitTest(); $TestSetup->dropTables('all'); } public function skip() { $this->skipIf(!AkConfig::getOption('webserver_enabled', false), '[' . get_class($this) . '] Web server not enabled'); } public function test_should_access_public_action() { $this->setMaximumRedirects(0); $this->get($this->_test_script . 'dummy_post/comments/1'); $this->assertResponse(200); $this->assertTextMatch("1st post2nd post3rd post4th post5th post", 'Did not get expected result when calling ' . $this->_test_script . 'dummy_post/comments/1'); } } ak_test_case('Controller_model_instantiation_TestCase');
$Request = $this->partialMock('AkRequest', array('getRelativeUrlRoot')); $Request->returnsByValue('getRelativeUrlRoot', '/subfolder'); $url = new AkUrl('/author/martin'); $url->setOptions(array('skip_relative_url_root' => false, 'relative_url_root' => '/subfolder')); $this->assertEqual('/subfolder/author/martin', $url->path()); } public function testUrl() { $url = $this->createUrl('/author'); $this->assertEqual('http://localhost/author', $url->url()); } public function testToStringMethodDecidesIfOnlyThePathWillBeReturned() { $url = $this->createUrl('/author'); $this->assertEqual('http://localhost/author', "{$url}"); $url->setOptions(array('only_path' => true)); $this->assertEqual('/author', "{$url}"); } /** * @return AkUrl */ public function createUrl($path, $query = '') { $Request = $this->partialMock('AkRequest', array('getRelativeUrlRoot', 'getProtocol', 'getHostWithPort'), array('getRelativeUrlRoot' => '', 'getProtocol' => 'http', 'getHostWithPort' => 'localhost')); $url = new AkUrl($path, $query); $url->setOptions(array('relative_url_root' => '', 'protocol' => 'http', 'host' => 'localhost')); return $this->Url = $url; } } ak_test_case('Url_TestCase');
$this->assertEqual($Article->get('en_headline'), 'New PHP Framework re-released'); $this->assertEqual($Article->get('es_body'), 'Un equipo de programadores españoles ha re-lanzado un entorno de desarrollo para PHP...'); $this->assertEqual($Article->get('en_excerpt_limit'), 7); } public function test_multilingual_getting_an_specific_locale() { $Article = new Article(); $this->assertTrue($Article = $Article->findFirstBy('en_headline', 'New PHP Framework released')); $this->assertEqual($Article->get('excerpt_limit', 'en'), 7); $this->assertEqual($Article->get('excerpt_limit', 'es'), 3); $this->assertEqual($Article->getAttribute('excerpt_limit', 'en'), 7); $this->assertEqual($Article->getAttribute('excerpt_limit', 'es'), 3); $this->assertEqual($Article->get('headline', 'en'), 'New PHP Framework released'); $this->assertEqual($Article->get('headline', 'es'), 'Se ha liberado un nuevo Framework para PHP'); $this->assertEqual($Article->getAttribute('headline', 'en'), 'New PHP Framework released'); $this->assertEqual($Article->getAttribute('headline', 'es'), 'Se ha liberado un nuevo Framework para PHP'); $this->assertEqual($Article->get('headline'), 'New PHP Framework released'); $this->assertEqual($Article->getAttribute('headline'), 'New PHP Framework released'); $this->assertEqual($Article->getAttributeLocales('headline'), array('en' => 'New PHP Framework released', 'es' => 'Se ha liberado un nuevo Framework para PHP')); } public function test_multilingual_setting_an_specific_locale() { $Article = new Article(); $Article->set('headline', 'Happiness on developers boost productivity', 'en'); $Article->set('headline', 'La felicidad de los programadores mejora la productivdad', 'es'); $this->assertEqual($Article->en_headline, 'Happiness on developers boost productivity'); $this->assertEqual($Article->es_headline, 'La felicidad de los programadores mejora la productivdad'); } } ak_test_case('I18n_TestCase');
class FormTagHelper_TestCase extends HelperUnitTest { public function test_for_form_tag_helpers() { $Controller = new MockAkActionController($this); $Controller->setReturnValue('urlFor', '/url/for/test'); $form_tag = new FormTagHelper(); $form_tag->setController($Controller); $this->assertEqual($form_tag->form_tag(), '<form action="/url/for/test" method="post">'); $this->assertEqual($form_tag->form_tag(array(), array('method' => 'get')), '<form action="/url/for/test" method="get">'); $this->assertEqual($form_tag->form_tag(array(), array('multipart' => true)), '<form action="/url/for/test" enctype="multipart/form-data" method="post">'); $this->assertEqual($form_tag->end_form_tag(), '</form>'); $this->assertEqual($form_tag->start_form_tag(), '<form action="/url/for/test" method="post">'); $this->assertEqual($form_tag->select_tag('person', '<option>Bermi</option>', array('id' => 'bermi')), '<select id="bermi" name="person"><option>Bermi</option></select>'); $this->assertEqual($form_tag->text_field_tag('person', 'Bermi', array('id' => 'bermi')), '<input id="bermi" name="person" type="text" value="Bermi" />'); $this->assertEqual($form_tag->text_field_tag('person[1][name]', 'Bermi'), '<input id="person_1_name" name="person[1][name]" type="text" value="Bermi" />'); $this->assertEqual($form_tag->hidden_field_tag('person', 'Bermi', array('id' => 'bermi')), '<input id="bermi" name="person" type="hidden" value="Bermi" />'); $this->assertEqual($form_tag->file_field_tag('photo', array('id' => 'pick_photo')), '<input id="pick_photo" name="photo" type="file" />'); $this->assertEqual($form_tag->password_field_tag('password', '', array('id' => 'pass')), '<input id="pass" name="password" type="password" value="" />'); $this->assertEqual($form_tag->text_area_tag('address', 'My address', array('id' => 'address_box')), '<textarea id="address_box" name="address">My address</textarea>'); $this->assertEqual($form_tag->check_box_tag('subscribe', 'subscribed', true), '<input checked="checked" id="subscribe" name="subscribe" type="checkbox" value="subscribed" />'); $this->assertEqual($form_tag->radio_button_tag('subscribe', 'subscribed', true), '<input checked="checked" id="subscribe" name="subscribe" type="radio" value="subscribed" />'); $this->assertEqual($form_tag->submit_tag(), '<input name="commit" type="submit" value="Save changes" />'); $this->assertEqual($form_tag->submit_tag('Commit changes', array('disable_with' => "Wait'Please")), '<input name="commit" onclick="this.disabled=true;this.value=\'Wait\\\'Please\';this.form.submit();" type="submit" value="Commit changes" />'); /** * @todo TEST FOR image_submit_tag($source, $options = array()) */ } } ak_test_case('FormTagHelper_TestCase');
{ $Person = new TestPerson(array('first_name' => 'Alicia')); $Person->validate(); $this->assertFalse($Person->hasErrors()); $Person = new TestPerson(array('last_name' => 'SadurnÃ', 'country' => 'ES')); $Person->validate(); $this->assertEqual($Person->getErrorsOn('first_name'), $Person->getDefaultErrorMessageFor('blank')); } public function Test_of_isValid() { $Person = new TestPerson(array('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('user_name = ?', 'bermi')); $Person->set('tos', 0); $this->assertFalse($Person->isValid()); $this->assertEqual($Person->getErrors(), array('email' => array("can't be blank"))); } public function Test_of_validatesAssociated() { $Picture = new Picture(array('title' => 'Carlet')); $Landlord = new Landlord(); $Landlord->test_validators = array('validatesPresenceOf' => array('name')); $Picture->landlord->assign($Landlord); $Picture->validatesAssociated('landlord'); $this->assertEqual($Picture->getErrorsOn('landlord'), $Picture->getDefaultErrorMessageFor('invalid')); } } ak_test_case('Validations_TestCase');
$Comment3_1->save(); $Comment3_2->save(); $Test = $User1->findAllBy('name', 'Arno', array('order' => 'id ASC', 'include' => array('posts' => array('order' => 'id ASC', 'include' => array('comments' => array('order' => 'id ASC')))))); $this->assertEqual($Test[0]->email, '*****@*****.**'); $this->assertEqual($Test[1]->email, '*****@*****.**'); $this->assertEqual($Test[0]->posts[0]->title, 'Test1'); $this->assertEqual($Test[0]->posts[1]->title, 'Test2'); $this->assertEqual($Test[0]->posts[0]->comments[0]->name, 'Comment1_1'); $this->assertEqual($Test[0]->posts[0]->comments[1]->name, 'Comment1_2'); $this->assertEqual($Test[0]->posts[1]->comments[0]->name, 'Comment2_1'); $this->assertEqual($Test[0]->posts[1]->comments[1]->name, 'Comment2_2'); $this->assertEqual($Test[1]->posts[0]->title, 'Test3'); $this->assertEqual($Test[1]->posts[0]->comments[0]->name, 'Comment3_1'); $this->assertEqual($Test[1]->posts[0]->comments[1]->name, 'Comment3_2'); } public function test_belongs_to_has_many() { $this->installAndIncludeModels('Many,Belong'); $hasMany = new Many(); $belongsTo = new Belong(); $many = $hasMany->create(array('name' => 'test')); $belongs1 = $belongsTo->create(array('name' => 'belongs1')); $belongs2 = $belongsTo->create(array('name' => 'belongs2')); $array = array($belongs1, $belongs2); $many->belong->set($array); $result = $hasMany->findFirstBy('name', 'test', array('include' => 'belongs')); $this->assertEqual(2, count($result->belongs)); } } ak_test_case('BelongsToFindIncludeOwner_TestCase');
$check_default_connection = AkDbAdapter::getInstance(); $this->assertReference($default_connection, $check_default_connection); $this->assertReference($default_connection->connection, $check_default_connection->connection); } public function test_should_establish_multiple_connections() { $db_file_existed = false; if (file_exists(AkConfig::getDir('config') . DS . 'database.yml')) { $db_file_existed = true; $db_settings = Ak::convert('yaml', 'array', AkConfig::getDir('config') . DS . 'database.yml'); } $db_settings['sqlite_databases'] = array('database_file' => AK_TMP_DIR . DS . 'testing_sqlite_database.sqlite', 'type' => 'sqlite'); file_put_contents(AkConfig::getDir('config') . DS . 'database.yml', Ak::convert('array', 'yaml', $db_settings)); @unlink(AK_TMP_DIR . DS . 'testing_sqlite_database.sqlite'); $this->installAndIncludeModels(array('TestOtherConnection')); Ak::import('test_other_connection'); $OtherConnection = new TestOtherConnection(array('name' => 'Delia')); $this->assertTrue($OtherConnection->save()); $this->installAndIncludeModels(array('DummyModel' => 'id,name')); $Dummy = new DummyModel(); $this->assertNotEqual($Dummy->getConnection(), $OtherConnection->getConnection()); unset($db_settings['sqlite_databases']); if ($db_file_existed) { file_put_contents(AkConfig::getDir('config') . DS . 'database.yml', Ak::convert('array', 'yaml', $db_settings)); } else { unlink(AkConfig::getDir('config') . DS . 'database.yml'); } } } ak_test_case('ConnectionHandling_TestCase', true);
public function test_with_relations_json() { $person = $this->Person->create(array('first_name' => 'Hansi', 'last_name' => 'Müller', 'email' => '*****@*****.**')); $person_created_at = gmdate('Y-m-d\\TH:i:s\\Z', Ak::getTimestamp($person->created_at)); $person->account->create(array('username' => 'hansi', 'password' => 'wilma')); $account_created_at = gmdate('Y-m-d\\TH:i:s\\Z', Ak::getTimestamp($person->account->created_at)); $expected = <<<EOX {"id":{$person->id},"first_name":"Hansi","last_name":"M\\u00fcller","email":"*****@*****.**","created_at":"{$person_created_at}","account":{"id":{$person->account->id},"person_id":{$person->id},"username":"******","password":"******","is_enabled":0,"credit_limit":null,"firm_id":null,"reset_key":null,"created_at":"{$account_created_at}"}} EOX; $json = $person->toJson(array('include' => 'account')); $this->_compareJson($expected, $json); $person_reloaded = $person->fromJson($json); $this->assertEqual($person->first_name, $person_reloaded->first_name); $this->assertEqual($person->last_name, $person_reloaded->last_name); $this->assertEqual($person->account->id, $person_reloaded->account->id); } private function _compareXml($expected, $given) { $expected = Ak::convert('xml', 'array', $expected); $given = Ak::convert('xml', 'array', $given); $this->assertEqual($expected, $given); } private function _compareJson($expected, $given) { $expected = json_decode($expected, true); $given = json_decode($given, true); $this->assertEqual($expected, $given); } } ak_test_case('ConversionBetweenFormats_TestCase');
$this->assertEqual(array('person' => array('name' => 'Steve')), $Request->getPostParams()); } public function testJsonIsAutomaticallyMergedIntoParamsOnPostRequests() { $data = '{"person":{"name":"Steve"}}'; $Request = $this->createRequest('post', $data, 'text/x-json'); $this->assertEqual(array('person' => array('name' => 'Steve')), $Request->getPostParams()); } public function testWwwFormIsAutomaticallyMergedIntoParamsOnPost() { $_save_POST = $_POST; $_POST = array('something' => 'here'); $Request = $this->createRequest('post', 'ignored, uses standard super-global', 'application/x-www-form-urlencoded'); $this->assertEqual($_POST, $Request->getPostParams()); $_POST = $_save_POST; } /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */ /** * @return AkRequest */ public function createRequest($method, $data, $content_type = 'text/xml') { $_SERVER['REQUEST_METHOD'] = $method; $_SERVER['CONTENT_TYPE'] = $content_type; $Request = $this->partialMock('AkRequest', array('getMessageBody', 'getMethod'), array('getMessageBody' => $data, 'getMethod' => $method)); $Request->init(); return $this->Request = $Request; } } ak_test_case('ParseMessageBody_TestCase');
}'; $class = new AkReflectionClass($string); $array = $class->getDefinition(); $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($docBlock instanceof 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)); } public function test_get_methods_filtered() { $file = AkConfig::getDir('fixtures') . 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_case('ReflectionClass_TestCase');
public function test_should_get_controller_methods() { $controller_file_name = 'authentication_controller.php'; require_once AkConfig::getDir('controllers') . DS . $controller_file_name; $this->assertTrue(in_array('authenticate', $this->menu_helper->_get_this_class_methods('AuthenticationController'))); } public function test_should_get_all_controllers_with_their_actions() { $available_controllers = (array) AkFileSystem::dir(AkConfig::getDir('controllers'), array('dirs' => false)); $got = $this->menu_helper->_get_default_full_menu(); foreach ($available_controllers as $controller_filename) { $controller_name = str_replace('_controller.php', '', $controller_filename); $this->assertTrue(isset($got[$controller_name])); } $this->assertTrue(in_array('authenticate', $got['authentication'])); } public function tests_menu_for_controllers() { $this->assertEqual($this->menu_helper->menu_for_controllers(array('advertiser' => array('buy', 'partial_in_template'), 'locale_detection' => 'session', 'page' => 'setup')), file_get_contents(HelperUnitTest::getFixturesDir() . DS . 'menu_helper_limit.txt')); $this->assertEqual($this->menu_helper->menu_for_controllers(array('unavailable' => array('foo', 'bar'))), '<div id="menu"></div>'); $this->assertEqual($this->menu_helper->menu_for_controllers(array('unavailable' => array('foo', 'bar')), "custom_menu_id"), '<div id="custom_menu_id"></div>'); $this->assertEqual($this->menu_helper->menu_for_controllers(array('advertiser' => array('buy', 'partial_in_template'), 'locale_detection' => 'session', 'page' => 'setup'), 'menu', 'current', ''), file_get_contents(HelperUnitTest::getFixturesDir() . DS . 'menu_helper_limit_no_title_tag.txt')); $this->assertEqual($this->menu_helper->menu_for_controllers(array('advertiser' => array('buy', 'partial_in_template'), 'locale_detection' => 'session', 'page' => 'setup'), 'menu', 'current', 'p'), file_get_contents(HelperUnitTest::getFixturesDir() . DS . 'menu_helper_limit_title_tag_p.txt')); $this->controller->controller_name = 'Advertiser'; $this->assertEqual($this->menu_helper->menu_for_controllers(array('advertiser' => array('buy', 'partial_in_template'), 'locale_detection' => 'session', 'page' => 'setup')), file_get_contents(HelperUnitTest::getFixturesDir() . DS . 'menu_helper_limit_current.txt')); $this->assertEqual($this->menu_helper->menu_for_controllers(array('advertiser' => array('buy', 'partial_in_template'), 'locale_detection' => 'session', 'page' => 'setup'), 'menu', 'selected'), file_get_contents(HelperUnitTest::getFixturesDir() . DS . 'menu_helper_limit_current_not_default.txt')); $this->assertEqual($this->menu_helper->menu_for_controllers(array('advertiser' => array('buy', 'partial_in_template'), 'locale_detection' => 'session', 'page' => 'setup'), 'menu', 'selected', ''), file_get_contents(HelperUnitTest::getFixturesDir() . DS . 'menu_helper_limit_current_not_default_no_title.txt')); } } ak_test_case('MenuHelper_TestCase');
$this->assertEqual($D->getErrorsOn('password'), $D->getDefaultErrorMessageFor('confirmation')); } public function test_should_validate_uniqueness_of_attribute() { $D = clone $this->ValidDocument; $D->setAttributes(array('user_name' => 'bermi', 'first_name' => 'Bermi', 'last_name' => 'Ferrer', 'country' => 'ES', 'tos' => 1)); $this->assertTrue($D->save()); $D = clone $this->ValidDocument; $D->setAttributes(array('user_name' => 'bermi', 'first_name' => 'Bermi', 'last_name' => 'Ferrer')); $D->validatesUniquenessOf("user_name"); $this->assertTrue($D->hasErrors()); $D = $D->findFirst(array('user_name' => 'bermi')); $this->assertFalse($D->isNewRecord()); $this->assertEqual($D->user_name, 'bermi'); $D->validatesUniquenessOf("user_name"); $this->assertFalse($D->hasErrors()); $D = $D->findFirst(array('user_name' => 'bermi')); $D->validatesUniquenessOf("user_name", array('scope' => 'country')); $this->assertFalse($D->hasErrors()); $D = clone $this->ValidDocument; $D->setAttributes(array('user_name' => 'bermi', 'first_name' => 'Bermi', 'last_name' => 'Ferrer', 'country' => 'US')); $D->validatesUniquenessOf("user_name", array('scope' => 'country')); $this->assertFalse($D->hasErrors()); $D = clone $this->ValidDocument; $D->setAttributes(array('user_name' => 'bermi', 'first_name' => 'Bermi', 'last_name' => 'Ferrer', 'country' => 'ES')); $D->validatesUniquenessOf("user_name", array('scope' => 'country')); $this->assertTrue($D->hasErrors()); } } ak_test_case('DocumentValidations_TestCase');
$options['params'] = $person; $result = $Http->put($this->_test_script . 'people/1', $options); $this->assertEqual('Steve', $result); } public function testPostPersonOnTheServerViaXml() { $person = '<person><name>Steve</name></person>'; $Http = new AkHttpClient(); $options = array('header' => array('content-type' => 'text/xml')); $result = $Http->post($this->_test_script . 'people', $options, $person); $this->assertEqual('Steve', $result); } public function testPostPersonOnTheServerViaWwwForm() { $person = array('person' => array('name' => 'Steve')); $Http = new AkHttpClient(); $options['params'] = $person; $result = $Http->post($this->_test_script . 'people', $options); $this->assertEqual('Steve', $result); } public function testFileUpload() { $Http = new AkHttpClient(); $options['params'] = array('photo' => array('title' => 'My Photo.')); $options['file'] = array('inputname' => 'photo', 'filename' => __FILE__); $result = $Http->post($this->_test_script . 'people/1/photo', $options); $this->assertEqual("My Photo.|" . basename(__FILE__), $result); } } ak_test_case('RestfulRequests_TestCase');
} } public function test_should_group_by_summed_field_with_conditions_and_having() { $credit = $this->Account->sum('credit_limit', array('conditions' => "firm_id > 1", 'group' => 'firm_id', 'having' => 'sum(credit_limit) > 60')); foreach (array(1 => null, 6 => 105, 2 => null) as $k => $v) { $this->assertEqual(@$credit[$k], $v); } } public function test_should_group_by_fields_with_table_alias() { $credit = $this->Account->sum('credit_limit', array('group' => 'accounts.firm_id')); foreach (array(1 => 50, 6 => 105, 2 => 60) as $k => $v) { $this->assertEqual($credit[$k], $v); } } public function test_should_calculate_with_invalid_field() { $this->assertEqual(6, $this->Account->calculate('count', '*')); $this->assertEqual(6, $this->Account->calculate('count', 'all')); } public function test_should_calculate_grouped_with_invalid_field() { $credit = $this->Account->count('all', array('group' => 'accounts.firm_id')); foreach (array(1 => 1, 6 => 2, 2 => 1) as $k => $v) { $this->assertEqual($credit[$k], $v); } } } ak_test_case('Calculations_TestCase');
<?php require_once dirname(__FILE__) . '/../helpers.php'; class JavascriptHelper_TestCase extends HelperUnitTest { public function test_for_JavascriptHelper() { $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.bermilabs.com')), '<a href="http://www.bermilabs.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); } public 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_case('JavascriptHelper_TestCase');
$Post->save(); $Post->reload(); $expected_id = $Post->getId(); $this->assertTrue($Result = $Post->find($expected_id, array('include' => array('comments'), 'conditions' => "name = 'Aditya'"))); $this->assertEqual($Result->comments[0]->get('name'), 'Aditya'); } /** * 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'); } } public function test_cleanup() { @AkFileSystem::file_delete(AkConfig::getDir('models') . DS . 'group_user.php'); } } ak_test_case('HasManyTableInheritance_TestCase');
} } public function testLangCanBeOmittedOnUrlize() { $this->urlize(array('name' => 'martin'))->returns('/person/martin'); } public function testCanUrlizeAvailableLocales() { $this->urlize(array('lang' => 'en'))->returns('/en/person'); $this->urlize(array('lang' => 'es', 'name' => 'martin'))->returns('/es/person/martin'); } public function testBreakUrlizeOnUnknownLocales() { $this->urlize(array('lang' => 'jp'))->returnsFalse(); } public function testExplicitRequirementsOverwriteTheAutomaticOnes() { $this->withRoute('/:lang/person', array(), array('lang' => '[a-z]{2}')); $this->urlize(array('lang' => 'jp'))->returns('/jp/person'); } public function testRouterConnectAddsLangSegmentAutomatically() { $Router = new AkRouter(); $Router->person('/person/:name'); $routes = $Router->getRoutes(); $segments = $routes['person']->getSegments(); $this->assertArrayHasKey('lang', $segments); } } ak_test_case('RouteWithLangSegment_TestCase');
// now we migrate $installer = new AkInstaller(); $installer->transactionStart(); // if the following fails, you're on Postgre 7 and you have to do it just like we'll do it with the boolean-field // except you can use the CAST-function: // UPDATE test_pages SET parent_id_temp = CAST(parent_id AS integer) $installer->execute('ALTER TABLE test_pages ALTER COLUMN parent_id TYPE integer'); $installer->addColumn('test_pages', 'is_public_temp boolean'); $installer->execute('UPDATE test_pages SET is_public_temp = CASE is_public WHEN 0 THEN false WHEN 1 THEN true ELSE NULL END'); $installer->removeColumn('test_pages', 'is_public'); $installer->renameColumn('test_pages', 'is_public_temp', 'is_public'); $installer->transactionComplete(); // let's see what we got $from_datadict = $this->db->getColumnDetails('test_pages'); $this->assertEqual($from_datadict['PARENT_ID']->type, 'int4'); $this->assertEqual($from_datadict['IS_PUBLIC']->type, 'bool'); $data = $this->db->select('SELECT * FROM test_pages'); $expected = array(array('id' => 1, 'parent_id' => null, 'is_public' => 't'), array('id' => 2, 'parent_id' => null, 'is_public' => 'f'), array('id' => 3, 'parent_id' => 1, 'is_public' => null)); $this->assertEqual($data, $expected); // ok, we're done $installer->dropTable('test_pages'); } } ak_test_case('PostgreSqlDatatypeMigration_TestCase');
} public function test_should_handle_empty_date_as_null() { $this->installAndIncludeModels(array('Post')); $params = array('title' => 'An empty date is a null date', 'posted_on(1i)' => '', 'posted_on(2i)' => '', 'posted_on(3i)' => ''); $MyPost = $this->Post->create($params); $MyPost->reload(); $this->assertNull($MyPost->posted_on); } public function test_cast_date_parameters() { $params = array('posted_on(1i)' => '', 'posted_on(2i)' => '', 'posted_on(3i)' => ''); $this->Post->setAttributes($params); $this->assertEqual('', $this->Post->get('posted_on')); $params = array('posted_on(1i)' => '2008', 'posted_on(2i)' => '10', 'posted_on(3i)' => ''); $this->Post->setAttributes($params); $this->assertEqual('2008-10', $this->Post->get('posted_on')); $this->assertEqual('2008', $this->Post->{"posted_on(1i)"}); $this->assertEqual('10', $this->Post->{"posted_on(2i)"}); $this->assertEqual('', $this->Post->{"posted_on(3i)"}); } public function test_should_serialize_attributes() { $User = new User(array('preferences' => array("background" => "black", "display" => 'large'))); $User->save(); $User = $User->find($User->getId()); $this->assertEqual($User->get('preferences'), array("background" => "black", "display" => 'large')); } } ak_test_case('TypeCasting_TestCase');
$this->get($this->_test_script . 'advertiser/all'); $this->assertTextMatch('1First ad2Seccond ad'); } public function test_render_partial_collection_from_controller() { $this->get($this->_test_script . 'advertiser/show_all'); $this->assertTextMatch('1First ad2Seccond ad'); } public function test_render_partial_from_different_controller() { $this->get($this->_test_script . 'render_tests/shared_partial'); $this->assertTextMatch('First ad'); } public function test_render_partial_from_different_template() { $this->get($this->_test_script . 'render_tests/ad'); $this->assertTextMatch('First ad'); } public function test_render_partial_empty_collection() { $this->get($this->_test_script . 'advertiser/empty_collection'); $this->assertTextMatch(' '); } public function test_should_use_object_and_not_controllers_item() { $this->get($this->_test_script . 'advertiser/use_object_and_not_controllers_item'); $this->assertTextMatch('Render'); } } ak_test_case('RenderPartial_TestCase');
$this->assertFalse($data, 'The cache has expired and we recognize it (Cache class:' . $class . ')'); } public function _removeTests($type, $class) { $this->Cache->init(1, 0); $this->assertFalse(!$this->Cache->remove($this->id, $this->group), 'Removing cached file (Cache disabled must return success)'); $this->Cache->init(3, $type); $this->assertFalse(!$this->Cache->save($this->text_to_catch, $this->id, $this->group), 'saving the cache (Cache class:' . $class . ')'); $this->Cache->init(2, $type); $data = $this->Cache->get($this->id, $this->group); $this->assertEqual($data, $this->text_to_catch, 'Checking that cached data has been inserted (Cache class:' . $class . ')'); $this->assertFalse(!$this->Cache->remove($this->id, $this->group), 'Removing cached file (Cache class:' . $class . ')'); $data = $this->Cache->get($this->id, $this->group); $this->assertFalse($data, 'The cache must have been removed at this point but stills here (Cache class:' . $class . ')'); } public function _cleanTests($type, $class) { $this->Cache->init(null, $type); $this->assertFalse(!$this->Cache->save($this->text_to_catch, $this->id, $this->group), 'saving (' . $class . ' based)'); $this->Cache->init(null, $type); $data = $this->Cache->get($this->id, $this->group); $this->assertEqual($data, $this->text_to_catch, 'Checking that cached data has been inserted (' . $class . ' based)'); $this->Cache->init(null, $type); $this->assertFalse(!$this->Cache->clean($this->group), 'Removing all the items in cache(' . $class . ' based)'); $this->Cache->init(null, $type); $data = $this->Cache->get($this->id, $this->group); $this->assertFalse($data, 'The cache must have been removed at this point but stills here(' . $class . ' based)'); } } ak_test_case('Cache_TestCase');
public function test_language_change() { $this->assertEqual(array('en', 'es'), Ak::langs()); $this->addHeader('Accept-Language: es,en-us,en;q=0.5'); $this->get($this->_test_script . 'locale_detection/get_language'); $this->assertTextMatch('es'); $this->get($this->_test_script . 'locale_detection/get_param¶m=message&message=Hello'); $this->assertTextMatch('Hello'); $this->get($this->_test_script . 'locale_detection/get_param¶m=lang&lang=en'); $this->assertTextMatch('en'); $this->get($this->_test_script . 'locale_detection/get_language&lang=en'); $this->assertTextMatch('en'); $this->get($this->_test_script . 'locale_detection/get_language'); $this->assertTextMatch('en'); $this->get($this->_test_script . 'locale_detection/get_language&lang=invalid'); $this->assertTextMatch('en'); } public 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($this->_test_script . 'locale_detection/get_language'); $this->assertTextMatch('es'); $this->get($this->_test_script . 'en/locale_detection/get_language/'); $this->assertTextMatch('en'); $this->get($this->_test_script . 'locale_detection/get_language'); $this->assertTextMatch('en'); } } ak_test_case('LocaleDetection_TestCase');
$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'); } public function test_should_send_params() { $params = array('testing' => array('user' => 'bermi', 'nested' => array('one', 'two'))); $expected = Ak::toJson($params['testing']); $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"); } } public function test_should_accept_redirects() { $this->assertEqual(Ak::url_get_contents($this->url . '/redirect_1'), 3); } public function test_should_keep_cookies() { $this->assertEqual(Ak::url_get_contents($this->url . '/persisting_cookies', array('cookies' => false)), 1); $this->assertEqual(Ak::url_get_contents($this->url . '/persisting_cookies', array('cookies' => true)), 1); $this->assertEqual(Ak::url_get_contents($this->url . '/persisting_cookies', array('cookies' => true)), 2); $this->assertEqual(Ak::url_get_contents($this->url . '/persisting_cookies', array('cookies' => true)), 3); $this->assertEqual(Ak::url_get_contents($this->url . '/persisting_cookies'), 1); $this->assertEqual(Ak::url_get_contents($this->url . '/persisting_cookies', array('cookies' => false)), 1); $this->assertEqual(Ak::url_get_contents($this->url . '/persisting_cookies', array('cookies' => true)), 1); } } ak_test_case('HttpClient_TestCase');