<?php

include dirname(__FILE__) . '/../../bootstrap/functional.php';
$browser = new DarwinTestFunctional(new sfBrowser());
$browser->loadData($configuration)->login('root', 'evil');
$browser->info('Index')->get('/people/index')->with('request')->begin()->isParameter('module', 'people')->isParameter('action', 'index')->end()->with('response')->begin()->isStatusCode(200)->checkElement('.search_results_content')->checkElement('#people_filters_family_name')->end()->click('.search_submit', array('people_filters' => array('family_name' => 'poil', 'is_physical' => 1)))->with('response')->begin()->isStatusCode(200)->checkElement('.results_container')->checkElement('.results_container .results > tbody > tr', 2)->checkElement('.results_container .results > tbody > tr.hidden', 1)->end()->get('/people/index')->click('.search_submit', array('people_filters' => array('family_name' => 'ntol', 'is_physical' => 1)))->with('response')->begin()->isStatusCode(200)->end();
$browser->test()->like($browser->getResponse()->getContent(), '/No Matching Items/', 'Content is ok');
$browser->get('/people/index')->click('New')->with('response')->begin()->isStatusCode(200)->end()->click('Save', array('people' => array('family_name' => '', 'additional_names' => '')))->with('form')->begin()->hasErrors(1)->isError('family_name', 'required')->end()->click('Save', array('people' => array('family_name' => 'Dupont', 'additional_names' => 'jr')))->with('response')->begin()->isRedirected()->end()->followRedirect();
$nitems = Doctrine::getTable('People')->findByAdditionalNames('jr');
$browser->test()->is($nitems[0]->getFamilyName(), 'Dupont', 'We have the new encoded people');
$browser->with('request')->begin()->isParameter('module', 'people')->isParameter('action', 'edit')->end()->with('response')->begin()->isStatusCode(200)->end()->click('Save', array('people' => array('family_name' => 'Dupond', 'additional_names' => 'jr')))->with('response')->begin()->isRedirected()->end()->followRedirect()->with('request')->begin()->isParameter('module', 'people')->isParameter('action', 'edit')->end()->with('response')->begin()->isStatusCode(200)->checkElement('input[value="Dupond"]')->end()->click('Delete')->with('response')->begin()->isRedirected()->end()->followRedirect()->with('request')->begin()->isParameter('module', 'people')->isParameter('action', 'index')->end()->with('response')->begin()->isStatusCode(200)->end();
$nitems = Doctrine::getTable('People')->findByAdditionalNames('jr');
$browser->test()->is($nitems->count(), 0, 'We have no matching people');
$browser->info('Address')->click('.search_submit', array('people_filters' => array('family_name' => 'poil', 'is_physical' => 1)))->click('td.edit a:nth-child(2)')->with('response')->begin()->isStatusCode(200)->checkElement('#address tbody tr', 0)->end()->click('#address a.link_catalogue')->with('response')->begin()->isStatusCode(200)->end()->click('Save')->with('response')->begin()->isStatusCode(200)->end()->with('form')->begin()->hasErrors(2)->isError('locality', 'required')->isError('country', 'required')->end()->click('Save', array('people_addresses' => array('locality' => 'Bruxelles', 'country' => 'Belgium', 'tag' => 'home,pref')))->with('response')->begin()->isStatusCode(200)->end();
$browser->test()->like($browser->getResponse()->getContent(), '/ok/', 'Content is ok');
$browser->get('/people/index')->click('.search_submit', array('people_filters' => array('family_name' => 'poil', 'is_physical' => 1)))->click('td.edit a:nth-child(2)')->with('response')->begin()->isStatusCode(200)->checkElement('#address tbody tr', 1)->checkElement('#address tbody tr .tag', 2)->end()->click('#address table tbody a.link_catalogue')->with('response')->begin()->isStatusCode(200)->checkElement('input[value="Bruxelles"]')->end()->click('.delete_button')->with('response')->begin()->isStatusCode(200)->end();
$browser->test()->like($browser->getResponse()->getContent(), '/ok/', 'Content is ok');
$browser->info('Comm')->get('/people/index')->click('.search_submit', array('people_filters' => array('family_name' => 'poil', 'is_physical' => 1)))->click('td.edit a:nth-child(2)')->with('response')->begin()->isStatusCode(200)->checkElement('#comm tbody tr', 0)->end()->click('#comm a.link_catalogue')->with('response')->begin()->isStatusCode(200)->end()->click('Save')->with('response')->begin()->isStatusCode(200)->end()->with('form')->begin()->hasErrors(1)->isError('entry', 'required')->end()->click('Save', array('people_comm' => array('entry' => '+32478.254415', 'comm_type' => 'phone/fax', 'tag' => 'home')))->with('response')->begin()->isStatusCode(200)->end();
$browser->test()->like($browser->getResponse()->getContent(), '/ok/', 'Content is ok');
$browser->get('/people/index')->click('.search_submit', array('people_filters' => array('family_name' => 'poil', 'is_physical' => 1)))->click('td.edit a:nth-child(2)')->with('response')->begin()->isStatusCode(200)->checkElement('#comm tbody tr', 1)->checkElement('#comm tbody tr .tag', 'Home')->end()->click('#comm table tbody a.link_catalogue')->with('response')->begin()->isStatusCode(200)->checkElement('input[value="+32478.254415"]')->end()->click('.delete_button')->with('response')->begin()->isStatusCode(200)->end();
$browser->test()->like($browser->getResponse()->getContent(), '/ok/', 'Content is ok');
$browser->info('Relation')->get('/people/index')->click('.search_submit', array('people_filters' => array('family_name' => 'poil', 'is_physical' => 1)))->click('td.edit a:nth-child(2)')->with('response')->begin()->isStatusCode(200)->checkElement('#relation tbody tr', 0)->end()->click('#relation a.link_catalogue')->with('response')->begin()->isStatusCode(200)->end()->click('Save')->with('response')->begin()->isStatusCode(200)->end()->with('form')->begin()->hasErrors(1)->isError('person_1_ref', 'required')->end();
$nitems = Doctrine::getTable('Institutions')->findOneByFamilyName('UGMM');
$browser->click('Save', array('people_relationships' => array('person_1_ref' => $nitems->getId(), 'relationship_type' => 'work for', 'person_user_role' => 'Manager')))->with('response')->begin()->isStatusCode(200)->end();
$browser->test()->like($browser->getResponse()->getContent(), '/ok/', 'Content is ok');
$browser->get('/people/index')->click('.search_submit', array('people_filters' => array('family_name' => 'poil', 'is_physical' => 1)))->click('td.edit a:nth-child(2)')->with('response')->begin()->isStatusCode(200)->checkElement('#relation tbody tr', 1)->end()->click('#relation table tbody a.link_catalogue')->with('response')->begin()->isStatusCode(200)->checkElement('input[value="Manager"]')->end()->click('.delete_button')->with('response')->begin()->isStatusCode(200)->end();
$browser->test()->like($browser->getResponse()->getContent(), '/ok/', 'Content is ok');
$browser->info('Lang')->get('/people/index')->click('.search_submit', array('people_filters' => array('family_name' => 'poil', 'is_physical' => 1)))->click('td.edit a:nth-child(2)')->with('response')->begin()->isStatusCode(200)->checkElement('#lang tbody tr', 0)->end()->click('#lang a.link_catalogue')->with('response')->begin()->isStatusCode(200)->end()->click('Save', array('people_languages' => array('language_country' => 'ddddddd', 'mother' => '')))->with('response')->begin()->isStatusCode(200)->end()->with('form')->begin()->hasErrors(1)->isError('language_country', 'invalid')->end();
$browser->click('Save', array('people_languages' => array('language_country' => 'am', 'mother' => 'yes', 'preferred_language' => 'yes')))->with('response')->begin()->isStatusCode(200)->end();
$browser->test()->like($browser->getResponse()->getContent(), '/ok/', 'Content is ok');
$browser->get('/people/index')->click('.search_submit', array('people_filters' => array('family_name' => 'poil', 'is_physical' => 1)))->click('td.edit a:nth-child(2)')->with('response')->begin()->isStatusCode(200)->checkElement('#lang tbody tr', 1)->checkElement('#lang tbody tr td:first', '/Preferred/')->end()->click('#lang .widget_content > a.link_catalogue')->click('Save', array('people_languages' => array('language_country' => 'fr', 'mother' => '', 'preferred_language' => 'yes')))->with('response')->begin()->isStatusCode(200)->end();
<?php

include dirname(__FILE__) . '/../../bootstrap/functional.php';
$browser = new DarwinTestFunctional(new sfBrowser());
$browser->loadData($configuration)->login('root', 'evil');
$browser->info('executeSearch')->get('/catalogue/search?searchCatalogue[name]=falco&searchCatalogue[table]=taxonomy')->with('request')->begin()->isParameter('module', 'catalogue')->isParameter('action', 'search')->end()->with('response')->begin()->isStatusCode(200)->checkElement('table tbody tr', 9)->checkElement('tbody tr:first span', '/Falco Class/')->end()->info('executeTree');
$items = Doctrine::getTable('Taxonomy')->findByName('Falco Peregrinus (Duchesnus Brulus 1912)');
$browser->get('/catalogue/tree?table=taxonomy&id=' . $items[0]->getId())->with('response')->begin()->isStatusCode(200)->checkElement('body > div.wrapper > ul > li', 8)->checkElement('body > div.wrapper > ul li:first', '/Eucaryota/')->checkElement('body > div.wrapper > ul li:last', '/Duchesnus/')->end()->info('Relation');
$items = Doctrine::getTable('CatalogueRelationships')->getRelationsForTable('taxonomy', 4, 'current_name');
$browser->get('/catalogue/relation?type=rename&table=taxonomy&rid=4&id=' . $items[0]['id'])->with('response')->begin()->isStatusCode(200)->checkElement('label[for="catalogue_relationships_record_id_2"]', 'Renamed in')->checkElement('form')->checkElement('input[id="catalogue_relationships_record_id_2_name"][value="Falco Peregrinus Tunstall, 1771"]')->end();
$items = Doctrine::getTable('CatalogueRelationships')->getRelationsForTable('taxonomy', 4, 'recombined from');
$browser->get('/catalogue/relation?type=recombined&table=taxonomy&rid=4&id=' . $items[0]['id'])->with('response')->begin()->isStatusCode(200)->checkElement('label[for="catalogue_relationships_record_id_2"]', 'Recombined from')->checkElement('form')->checkElement('input[id="catalogue_relationships_record_id_2_name"][value="Falco Peregrinus recombinus"]')->end()->info('SaveRelation')->get('/catalogue/relation?type=recombined&table=taxonomy&rid=4')->with('response')->begin()->isStatusCode(200)->checkElement('label[for="catalogue_relationships_record_id_2"]', 'Recombined from')->checkElement('form')->checkElement('input[id="catalogue_relationships_record_id_2_name"][value=""]')->end()->click('Save', array('catalogue_relationships' => array('record_id_2' => '2', 'referenced_relation' => 'taxonomy', 'relationship_type' => 'recombined from', 'record_id_1' => '4')));
$browser->test()->like($browser->getResponse()->getContent(), '/ok/', 'Content is ok');
$items = Doctrine::getTable('CatalogueRelationships')->getRelationsForTable('taxonomy', 4, 'recombined from');
$tax = Doctrine::getTable('Taxonomy')->find($items[1]['record_id_2']);
$browser->get('/catalogue/relation?type=recombined&table=taxonomy&rid=4&id=' . $items[1]['id'])->with('response')->begin()->isStatusCode(200)->checkElement('label[for="catalogue_relationships_record_id_2"]', 'Recombined from')->checkElement('form')->checkElement('input[id="catalogue_relationships_record_id_2_name"]')->checkElement('input[id="catalogue_relationships_record_id_2_name"][value="' . $tax->getName() . '"]')->end()->info('DeleteRelated')->get('/catalogue/deleteRelated?table=catalogue_relationships&id=' . $items[1]['id'])->with('response')->begin()->isStatusCode(200)->end()->get('/catalogue/relation?type=recombined&table=taxonomy&rid=4&id=' . $items[1]['id'])->with('response')->begin()->isStatusCode(200)->checkElement('label[for="catalogue_relationships_record_id_2"]', 'Recombined from')->checkElement('form')->checkElement('#relation_catalogue_name', '')->end();
$items = Doctrine::getTable('Taxonomy')->findByName('Falco Peregrinus (Duchesnus Brulus 1912)');
$parent_item = Doctrine::getTable('Taxonomy')->findOneByLevelRef(48);
$items[0]->setParentRef($parent_item->getId());
$items[0]->save();
$browser->info('Test the possible upper levels check function')->get('/catalogue/searchPUL/table/taxonomy/level_id/' . $items[0]->getLevelRef() . '/parent_id/' . $parent_item->getId())->with('response')->begin()->isStatusCode(200)->matches('/ok/')->end()->get('/catalogue/searchPUL/table/taxonomy/level_id/20/parent_id/' . $parent_item->getId())->with('response')->begin()->isStatusCode(200)->matches('/not ok/')->end()->get('/catalogue/searchPUL/table/taxonomy/level_id/50/parent_id/' . $parent_item->getId())->with('response')->begin()->isStatusCode(200)->matches('/ok/')->end()->get('/catalogue/searchPUL/table/taxonomy/level_id/1/parent_id/' . $parent_item->getId())->with('response')->begin()->isStatusCode(200)->matches('/top/')->end();
<?php

include dirname(__FILE__) . '/../../bootstrap/functional.php';
$browser = new DarwinTestFunctional(new sfBrowser());
$browser->loadData($configuration)->login('root', 'evil');
$browser->get('/cataloguepeople/people?table=taxonomy&rid=3')->with('request')->begin()->isParameter('module', 'cataloguepeople')->isParameter('action', 'people')->end()->with('response')->begin()->isStatusCode(200)->checkElement('form')->checkElement('#catalogue_people_people_type option', 2)->checkElement('.tab_choice li', 2)->end()->click('Save')->with('form')->begin()->hasErrors(1)->isError('people_ref', 'required')->end();
$people = Doctrine::getTable('People')->findOneByFamilyName('Root');
$browser->click('Save', array('catalogue_people' => array('people_type' => 'expert', 'people_sub_type' => 'Main', 'record_id' => '3', 'people_ref' => $people->getId(), 'referenced_relation' => 'taxonomy')))->with('form')->begin()->hasErrors(0)->end();
$browser->test()->like($browser->getResponse()->getContent(), '/ok/', 'Content is ok');
$rbins = Doctrine::getTable('People')->findOneByFamilyName('Institut Royal des Sciences Naturelles de Belgique');
$rbins->save();
$browser->get('/cataloguepeople/people?table=taxonomy&rid=3')->click('Save', array('catalogue_people' => array('people_type' => 'author', 'people_sub_type' => 'Main', 'record_id' => '3', 'people_ref' => $rbins->getId(), 'referenced_relation' => 'taxonomy')))->with('form')->begin()->hasErrors(0)->end();
$browser->test()->like($browser->getResponse()->getContent(), '/ok/', 'Content is ok');
$browser->get('/widgets/reloadContent?widget=cataloguePeople&category=catalogue_taxonomy&eid=3')->with('response')->begin()->isStatusCode(200)->checkElement('table tr:nth-child(1) .widget_sub_table tbody tr', 2)->checkElement('table tr:nth-child(1) .widget_sub_table tbody tr:first td:nth-child(2)', '/Root/')->checkElement('table tr:nth-child(1) .widget_sub_table tbody tr:last td:nth-child(2)', '/Institut Royal des Sciences Naturelles de Belgique/')->end();
$rbins_recId = Doctrine_Query::create()->from('CataloguePeople c')->where('c.people_ref = ?', $rbins->getId())->andWhere('c.people_type=?', 'author')->fetchOne();
$root_recId = Doctrine_Query::create()->from('CataloguePeople c')->where('c.people_ref = ?', $people->getId())->andWhere('c.people_type=?', 'author')->fetchOne();
$browser->get('/cataloguepeople/editOrder?table=taxonomy&rid=3&people_type=author&order=' . $rbins_recId->getId() . ',' . $root_recId->getId() . ',')->with('response')->begin()->isStatusCode(200)->end();
$browser->test()->like($browser->getResponse()->getContent(), '/ok/', 'Content is ok');
$browser->get('/widgets/reloadContent?widget=cataloguePeople&category=catalogue_taxonomy&eid=3')->with('response')->begin()->isStatusCode(200)->checkElement('table tr:nth-child(1) .widget_sub_table tbody tr', 2)->checkElement('table tr:nth-child(1) .widget_sub_table tbody tr:first td:nth-child(2)', '/Institut Royal des Sciences Naturelles de Belgique/')->checkElement('table tr:nth-child(1) .widget_sub_table tbody tr:last td:nth-child(2)', '/Root/')->end();
$browser->get('/cataloguepeople/getSubType?type=author')->with('response')->begin()->isStatusCode(200)->end();
$browser->test()->like($browser->getResponse()->getContent(), '/Secondary Author/', 'Content is ok');
$browser->test()->like($browser->getResponse()->getContent(), '/Corrector/', 'Content is ok');
$browser->get('/cataloguepeople/getSubType?type=expert')->with('response')->begin()->isStatusCode(200)->end();
$browser->test()->like($browser->getResponse()->getContent(), '/Main/', 'Content is ok');