function test_controller()
 {
     $controller = $this->object->get_controller();
     if (is_a($controller, 'empty_controller')) {
         return;
     }
     $definitions = $controller->get_actions_definitions();
     $controller_class = get_class($controller);
     $empty_action = new empty_action();
     foreach ($definitions as $action => $data) {
         if (isset($data['template_path'])) {
             $template = new template($data['template_path']);
             $this->_check_template($template);
         }
         if (isset($data['action_path'])) {
             debug_mock::expect_never_write('write_error');
             $action_obj = action_factory::create($data['action_path']);
             $this->assertNotIdentical($action_obj, $empty_action, 'controller: "' . $controller_class . '" action object for action "' . $action . '"not found');
             $this->_check_action($action_obj);
         }
         if (isset($data['action_name'])) {
             $this->assertTrue($data['action_name'], 'controller: "' . $controller_class . '" action_name property for action "' . $action . '" is empty - check strings');
         }
     }
     $action = $controller->get_default_action();
     $this->assertTrue(isset($definitions[$action]), 'controller: "' . $controller_class . '" default action "' . $action . '" doesnt exist');
 }
 function _move_tree_across($branches, $mvt, $nodecount)
 {
     foreach ($branches[0] as $nodeid => $node) {
         foreach ($branches[1] as $tnodeid => $tnode) {
             if ($nodeid == $tnodeid) {
                 debug_mock::expect_write_error(NESE_ERROR_RECURSION, array('id' => $nodeid, 'target_id' => $tnodeid));
             } else {
                 $current_source = $this->_tree->get_node($nodeid);
                 $current_target = $this->_tree->get_node($tnodeid);
                 if ($current_target['root_id'] == $current_source['root_id'] && ($current_source['l'] <= $current_target['l'] && $current_source['r'] >= $current_target['r'])) {
                     debug_mock::expect_write_error(NESE_ERROR_RECURSION, array('id' => $nodeid, 'target_id' => $tnodeid));
                 }
             }
             if (($ret = $this->_tree->move_tree($nodeid, $tnodeid, $mvt)) === false) {
                 continue;
             }
             $mnode = $this->_tree->get_node($ret);
             $this->assertEqual($ret, $nodeid, 'Nodeid was not returned as expected');
             $this->assertEqual($nodecount, count($this->_tree->get_all_nodes()), 'Node count changed');
             $p = $this->_tree->get_parent($nodeid);
             if ($mvt == NESE_MOVE_BELOW) {
                 $this->assertEqual($tnode['id'], $p['id'], 'Move below failed (parent ID)');
             }
             if ($mnode['id'] != $mnode['root_id']) {
                 $this->assertEqual($p['id'], $mnode['parent_id'], 'Parent ID is wrong');
             }
         }
     }
 }
 function test_accessible_by_ids_no_ids()
 {
     $this->_login_user(200, array(100 => 'admins', 110 => 'users'));
     debug_mock::expect_write_error('ids array is empty');
     $result = $this->object->fetch_accessible_by_ids(array());
     $this->assertEqual($result, array());
 }
  function tally()
  {
    $debug =& debug_mock :: instance();

    $debug->mock->tally();
    $debug->expected_data = array();
  }
 function test_create_no_such_action()
 {
 	debug_mock :: expect_write_error('action not found', array('class_path' => 'no_such_action'));
 	
 	$c =& action_factory :: create('no_such_action');
 	
 	$this->assertIsA($c, 'empty_action'); 
 }
 function tearDown()
 {
     debug_mock::tally();
     $this->dataspace->reset();
     $this->form_action->tally();
     $this->request->tally();
     $this->response->tally();
 }
 function test_create()
 {
     $c =& action_factory::create('action');
     $this->assertNotNull($c);
     debug_mock::expect_write_error('action not found', array('class_path' => 'no_such_action'));
     $c =& action_factory::create('no_such_action');
     $this->assertNull($c);
 }
 function test_save_object_access_wrong_action_no_parent_records()
 {
     $this->object->setReturnValue('get_id', -1);
     $this->parent_object->setReturnValue('get_id', -2);
     $this->parent_object->setReturnValue('get_class_id', 10);
     $this->parent_object_controller->setReturnValue('determine_action', 'display');
     debug_mock::expect_write_error('parent object has no acccess records at all', array('parent_id' => -2));
     $this->assertFalse($this->ac->save_object_access($this->object, $this->parent_object));
 }
 function test_create_complex2()
 {
     debug_mock::expect_never_write();
     $this->_create_node('test');
     $this->_create_node('test8');
     $this->_create_node('test9');
     $this->_create_node('test10');
     $this->object->set_parent_node_id($this->parent_node_id);
     $this->object->set_identifier('node_test');
     $id = $this->object->create();
     $this->assertEqual($this->object->get_identifier(), 'test11');
 }
 function test_create()
 {
     debug_mock::expect_never_write();
     $this->object->set_parent_node_id($this->parent_node_id);
     $this->object->set_identifier('test_node');
     $id = $this->object->create();
     $this->assertNotIdentical($id, false, 'create operation failed');
     $this->assertEqual($id, $this->object->get_id());
     $this->_check_sys_site_object_tree_record();
     $this->_check_sys_site_object_record();
     $this->_check_sys_class_record();
 }
 function test_create_complex()
 {
     debug_mock::expect_never_write();
     $this->_create_node('10ru1');
     $this->_create_node('10ru2');
     $this->_create_node('10a1');
     $this->_create_node(1000);
     $this->object->set_parent_node_id($this->parent_node_id);
     $this->object->set_identifier('node_test');
     $id = $this->object->create();
     $this->assertEqual($this->object->get_identifier(), '10ru3');
 }
Пример #12
0
 function test_group()
 {
     $ini =& ini::instance('test.ini', TEST_CASES_DIR, false);
     debug_mock::expect_write_notice('unknown block', array('ini' => $ini->file_name(), 'block_name' => 'no_group'));
     $this->assertNull($ini->group('no_group'));
     $this->assertNotNull($ini->group('default'));
     $group = $ini->group('test2');
     $this->assertTrue(is_array($group) && sizeof($group) == 3);
     $this->assertEqual($group['test1'], 2);
     $this->assertEqual($group['test2'], 3);
     $this->assertEqual($group['test3'], "  #It's just a \"test\"!#  ");
 }
 function test_move_tree()
 {
     $movemodes[] = NESE_MOVE_BEFORE;
     $movemodes[] = NESE_MOVE_AFTER;
     $movemodes[] = NESE_MOVE_BELOW;
     for ($j = 0; $j < count($movemodes); $j++) {
         $mvt = $movemodes[$j];
         // Build a nice random tree
         $rnc = 1;
         $depth = 2;
         $npl = 2;
         $relation_tree = $this->_create_sub_node($rnc, $depth, $npl);
         $lastrid = false;
         $rootnodes = $this->_tree->get_root_nodes();
         $branches = array();
         $allnodes1 = $this->_tree->get_all_nodes();
         foreach ($rootnodes as $rid => $rootnode) {
             if ($lastrid) {
                 if ($rid == $lastrid) {
                     debug_mock::expect_write_error(NESE_ERROR_RECURSION);
                 }
                 $this->_tree->move_tree($rid, $lastrid, $mvt);
             }
             $branch = $this->_tree->get_branch($rid);
             if (!empty($branch)) {
                 $branches[] = $branch;
             }
             if (count($branches) == 2) {
                 $this->_move_tree_across($branches, $mvt, count($this->_tree->get_all_nodes()));
                 $branches = array();
             }
             $lastrid = $rid;
         }
         $allnodes2 = $this->_tree->get_all_nodes();
         // Just make sure that all the nodes are still there
         $this->assertFalse(count(array_diff(array_keys($allnodes1), array_keys($allnodes2))), 'Nodes got lost during the move');
     }
     return true;
 }
Пример #14
0
 function test_update_file()
 {
     $this->test_create_file();
     $obj =& site_object_factory::create('file_object');
     $this->db->sql_select('media');
     $row = $this->db->fetch_row();
     $obj->set_attribute('tmp_file_path', PROJECT_DIR . 'images/2.jpg');
     $obj->set_attribute('file_name', 'new_name.jpg');
     $obj->set_attribute('mime_type', 'image/jpeg');
     debug_mock::expect_write_error('media id not set');
     $this->assertFalse($obj->update_file(), __LINE__);
     $obj->set_attribute('media_id', $row['id']);
     $this->assertTrue($obj->update_file(), __LINE__);
     $this->db->sql_select('media');
     $arr = $this->db->get_array();
     $media_id = $obj->get_attribute('media_id');
     $this->assertTrue(is_array($arr), __LINE__);
     $this->assertEqual(sizeof($arr), 1, __LINE__);
     $this->assertEqual($arr[0]['id'], $media_id, __LINE__);
     $this->assertEqual($arr[0]['file_name'], $obj->get_attribute('file_name'), __LINE__);
     $this->assertEqual($arr[0]['mime_type'], $obj->get_attribute('mime_type'), __LINE__);
     $this->assertTrue(file_exists(MEDIA_DIR . $media_id . '.media'), __LINE__);
     $this->assertEqual(filesize(MEDIA_DIR . $media_id . '.media'), filesize($obj->get_attribute('tmp_file_path')), __LINE__);
 }
  function tearDown()
  { 
  	$this->_clean_up();

		debug_mock :: tally();
  }
  function test_get_wrong_type_value()
  {
    $sp =& sys_param :: instance();

    debug_mock :: expect_write_error(
      'trying to get undefined type in sys_param',
      array (
        'type' => 'blabla',
        'param' => 'param_1',
      )
    );

    $number = 123.053;
    $sp->save_param('param_1', 'float', $number);

    $this->assertNull($sp->get_param('param_1', 'blabla'));
    $this->assertNull($sp->get_param('param_2'));
  }
  function test_display_empty_view()
  { 
  	$this->request->setReturnValue('get_attribute', 'no_such_action', array('action'));
  	
  	debug_mock :: expect_write_warning('action not found', 
  		array (
					  'class' => 'site_object_controller_test_version1',
					  'action' => 'no_such_action',
					  'default_action' => 'display',
					)
		);

  	$this->assertIdentical($this->site_object_controller->determine_action($this->request), false);

		debug_mock :: expect_write_error('template is null');
		
  	$this->site_object_controller->display_view();  	
  }  
 function test_perform_with_name()
 {
     $_REQUEST['test1']['username'] = '******';
     $_REQUEST['test1']['password'] = '******';
     $_REQUEST['test1']['password_confirm'] = 'yo';
     $a1 =& new form_action1('test1');
     $this->assertIsA($a1->perform(), 'failed_response');
     $_REQUEST['test1']['submitted'] = true;
     debug_mock::expect_write_error('validation failed');
     $this->assertIsA($a1->perform(), 'not_valid_response');
     $_REQUEST['test1']['password'] = '******';
     $_REQUEST['test1']['password_confirm'] = 'yoyoyoyo';
     debug_mock::expect_write_error('validation failed');
     $this->assertIsA($a1->perform(), 'not_valid_response', 'validation occurs only once');
     $a2 =& new form_action1('test1');
     $this->assertIsA($a2->perform(), 'response');
 }
 function test_perform_with_name_validation_fails()
 {
     $_REQUEST['test1']['username'] = '******';
     $_REQUEST['test1']['password'] = '******';
     $_REQUEST['test1']['password_confirm'] = 'yo';
     $this->form_action->setReturnValue('_define_dataspace_name', 'test1');
     $this->form_action->form_action();
     $this->assertIsA($this->form_action->perform(), 'failed_response');
     $_REQUEST['test1']['submitted'] = true;
     debug_mock::expect_write_error('validation failed');
     $this->assertIsA($this->form_action->perform(), 'not_valid_response');
 }
  function test_update_node()
  {
    $node_id = $this->imp->create_root_node(array('identifier' => 'root', 'object_id' => 10));

    $node = array(
      'identifier' => 'test',
      'object_id' => 100,
      'id' => 12,
      'path' => '/0/',
      'root_id' => 0,
      'level' => 23,
      'parent_id' => 1000,
      'children' => 1000
    );

    debug_mock :: expect_write_error(TREE_ERROR_NODE_WRONG_PARAM, array('value' => 'id'));
    debug_mock :: expect_write_error(TREE_ERROR_NODE_WRONG_PARAM, array('value' => 'path'));
    debug_mock :: expect_write_error(TREE_ERROR_NODE_WRONG_PARAM, array('value' => 'root_id'));
    debug_mock :: expect_write_error(TREE_ERROR_NODE_WRONG_PARAM, array('value' => 'level'));
    debug_mock :: expect_write_error(TREE_ERROR_NODE_WRONG_PARAM, array('value' => 'children'));

    $this->assertTrue($this->imp->update_node($node_id, $node));

    $updated_node = $this->imp->get_node($node_id);

    $this->assertEqual($updated_node['object_id'], 100, 'invalid parameter: object_id');
    $this->assertEqual($updated_node['identifier'], 'test', 'invalid parameter: identifier');
    $this->assertNotEqual($updated_node, $node, 'invalid update');
  }
 function test_change_order()
 {
     $rnc = 2;
     $depth = 2;
     $npl = 3;
     // Create a new tree
     $relation_tree = $this->_create_sub_node($rnc, $depth, $npl);
     debug_mock::expect_write_error('node not found', array('node_id' => 0));
     $this->assertFalse($this->_tree->change_node_order(0, 'up'));
     $this->assertFalse($this->_tree->change_node_order(1, 'up'));
     $this->assertFalse($this->_tree->change_node_order(1, 'down'));
     foreach (array_keys($relation_tree) as $id) {
         if (isset($relation_tree[$id]['children'])) {
             foreach ($relation_tree[$id]['children'] as $child_id) {
                 $children_before = $this->_tree->get_children($id);
                 $direction = mt_rand(0, 1) ? 'up' : 'down';
                 $result = $this->_tree->change_node_order($child_id, $direction);
                 $children_after = $this->_tree->get_children($id);
                 $pos_before = array_search($child_id, array_keys($children_before));
                 $pos_after = array_search($child_id, array_keys($children_after));
                 if ($direction == 'up') {
                     if ($pos_before == 0) {
                         $this->assertFalse($result);
                     } else {
                         $this->assertTrue($result);
                         $this->assertEqual($pos_after - $pos_before, -1);
                     }
                 } elseif ($direction == 'down') {
                     if ($pos_before == sizeof($children_before) - 1) {
                         $this->assertFalse($result);
                     } else {
                         $this->assertTrue($result);
                         $this->assertEqual($pos_after - $pos_before, 1);
                     }
                 }
             }
         }
     }
 }
 function test_failed_update_file()
 {
     debug_mock::expect_write_error('media id not set');
     $this->_set_file_update_attributes();
     $this->assertFalse($this->object->update_file());
 }
 function test_display_empty_view()
 {
     $_REQUEST['action'] = 'no_such_action';
     debug_mock::expect_write_warning('action not found', array('class' => 'site_object_controller_test_version1', 'action' => 'no_such_action', 'default_action' => 'display'));
     $this->assertIdentical($this->site_object_controller->determine_action(), false);
     debug_mock::expect_write_error('template is null');
     $this->site_object_controller->display_view();
 }
 function test_failed_change_own_password_no_user_node_id()
 {
     debug_mock::expect_write_error('user not logged in - node id is not set');
     $this->assertFalse($this->object->change_own_password('changed_password'));
 }
 function test_fetch_by_ids_no_ids()
 {
     debug_mock::expect_write_error('ids array is empty');
     $result = $this->object->fetch_by_ids(array());
     $this->assertEqual($result, array());
 }
 function test_get_sub_branch_by_path_failed()
 {
   debug_mock :: expect_write_error(TREE_ERROR_NODE_NOT_FOUND,  array('id' => 1));
   $this->assertFalse($this->driver->get_sub_branch(1));
 }
Пример #27
0
  function test_get_group()
  {
    register_testing_ini(
      'testing.ini',
      '
        unassigned =
        test = 1

        [test]
        test = 1
      '
    );

    $ini =& get_ini('testing.ini');

    $this->assertEqual($ini->get_group('default'), array('unassigned' => '', 'test' => 1));
    $this->assertEqual($ini->get_group('test'), array('test' => 1));

    debug_mock :: expect_write_notice('undefined group',
      array(
        'ini' => $ini->get_original_file(),
        'group' => 'no_such_group'
      )
    );

    $this->assertNull($ini->get_group('no_such_group'));
  }