BMLT Satellite Driver
Loading...
Searching...
No Matches
Functions | Variables
/home/runner/work/bmlt-satellite-driver/bmlt-satellite-driver/unit_test.php File Reference

A unit test harness for the bmlt_satellite_controller class. *. More...

Go to the source code of this file.

Functions

 u_test_get_test_server_uri ()
 Returns the URI for the test server. The default is the public trunk test server * and you can specify a local server if running on a localhost machine. *


 
 u_test_apply_root_uri (&$in_test_subject, $in_root_server_uri)
 Apply the URI, and see if the server is there (can also test for bad URI) * *.
 
 u_test_get_standard_server_parameters (&$in_test_subject, $in_root_server_uri)
 Apply the URI, and see if the server is there (can also test for bad URI) * *.
 
 u_test_draw_service_body ($in_service_body_array)
 Displays Service bodies in a hierarchical fashion. * *.
 
 u_test_server_root_uri (&$in_test_subject, $in_uri)
 Tests the various ways the class deals with the root URI . This will also * exercise the cURL calling and server communication. * *.
 
 u_test_server_parameters_outgoing (&$in_test_subject)
 Tests the outgoing parameter storage. * *.
 
 u_test_basic_search ($in_root_server_uri)
 Performs a basic meeting search * *.
 
 u_test_complex_search ( $in_root_server_uri, &$serialized_transaction)
 Performs a more complex meeting search * *.
 
 u_test_filtered_search ($in_root_server_uri)
 Performs a more complex meeting search, but only gets a couple of the fields. * *.
 
 u_test_serialized_search ( $in_test_subject, $serialized_transaction)
 Performs a more complex meeting search * *.
 
 u_test_draw_meeting ($in_meeting_array)
 Displays one meeting in a hierarchical fashion. * *.
 
 u_test_changes ($in_root_server_uri)
 Queries the server for changes. *

  • This function requires that the root server be version 1.8.13 or above. It queries the * server for all the meeting changes that occurred in a six-week window, beginning seven * weeks ago, and ending one week ago. The changes are returned with the most recent ones * first, going down to the oldest. * *.

 
 u_test ()
 Runs the unit tests. * *.
 

Variables

const U_TEST_REMOTE_URI 'https://bmlt.app/trunk/main_server'
 This is the URI to resolve a test root server (remote). Default is the public trunk test (not stable).
 
const U_TEST_LOCAL_URI 'http://bmlt-server.localhost'
 If running on localhost, you can specify a local root URI. Comment this out to always use remote.
 
const U_TEST_MEETING_ID 734
 This is an ID for a specific meeting (with some changes) for the meeting changes test.
 

Detailed Description

A unit test harness for the bmlt_satellite_controller class. *.

Find out more at: https://bmlt.app

BMLT is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

BMLT is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this code. If not, see http://www.gnu.org/licenses/.

Definition in file unit_test.php.

Function Documentation

◆ u_test()

u_test ( )

Runs the unit tests. * *.

Returns
A string. The XHTML to be displayed. *

Definition at line 766 of file unit_test.php.

767{
768 // We return a fully-qualified XHTML 1.0 Strict page.
769 $ret = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><title>bmlt_satellite_controller Class Unit Test (###-SERVER-URI-###)</title>';
770 $ret .= '<style type="text/css">';
771 $ret .= '*{margin:0;padding:0}';
772 $ret .= 'body{font-family:Courier;font-size:small}';
773 $ret .= '.test_container_div{padding-left:20px}';
774 $ret .= '</style>';
775 $ret .= '</head><body>';
776
777 // Start by getting the main URI
779
780 // The URI goes in the page title.
781 $ret = str_replace('###-SERVER-URI-###', htmlspecialchars($uri), $ret);
782
783 //#######################
784 //### START TEST #
785 //#######################
786
787 $ret .= '<h1>BEGIN UNIT TEST</h1>';
788 $ret .= '<div class="test_container_div">';
789
790 $ret .= '<strong>USAGE:</strong> Override URI by "test_uri=<em>XXX</em>"<br />';
791 $ret .= '<strong>USING:</strong> ' . htmlspecialchars($uri);
792
793 // The first test we run is to make sure that the parameterized constructor works OK.
794 $ret .= '<h1 id="constructor_unit_test"># BEGIN CONSTRUCTOR UNIT TEST</h1>';
795 $ret .= '<div class="test_container_div">';
796 // We are just making sure the URI gets in there properly.
797 $start_time = microtime(true);
798 $test_subject = new bmlt_satellite_controller($uri);
799 $total_time = intval((microtime(true) - $start_time) * 1000);
800 $error_message = $test_subject->get_m_error_message();
801 if ($error_message) {
802 $ret .= 'The test failed, because the object reported the following error: "' . htmlspecialchars($error_message) . '"';
803 $ret .= '</div><h1># END CONSTRUCTOR UNIT TEST</h1>';
804 } else {
805 $ret .= '<h2>Auto-Setup Constructor Test</h2>';
806 $ret .= '<div class="test_container_div">The initialization (setting up the object) took ';
807 if ($total_time > 1000) {
808 $total_time /= 1000.0;
809 $ret .= htmlspecialchars($total_time) . ' seconds';
810 } else {
811 $ret .= htmlspecialchars($total_time) . ' milliseconds';
812 }
813
814 $ret .= ' to run.<br />The object has the following URI set via the constructor: ';
815 $ret .= htmlspecialchars($test_subject->get_m_root_uri());
816 // These all need to be already loaded, so we access the stored parameters.
817 $server_version = $test_subject->get_server_version();
818 $server_langs = $test_subject->get_m_outgoing_parameter('langs');
819 $server_formats = $test_subject->get_m_outgoing_parameter('formats');
820 $server_services = $test_subject->get_m_outgoing_parameter('services');
821 $server_meeting_key = $test_subject->get_m_outgoing_parameter('meeting_key');
822
823 if ($server_version && is_array($server_langs) && is_array($server_formats) && is_array($server_services) && is_array($server_meeting_key)) {
824 $ret .= '<br />The test passed, because all the data items were set up and cached.';
825 } else {
826 $ret .= '<br />The test failed, because not all the data items were cached.';
827 }
828
829 $ret .= '</div>';
830 $ret .= '</div>';
831 $ret .= '<h1># END CONSTRUCTOR UNIT TEST</h1>';
832
833 // After that, we relase the original object, and instantiate a new "blank slate" object.
834 $test_subject = null;
835
836 // We will test the various accessors, here.
837 $test_subject = new bmlt_satellite_controller();
838
839 if ($test_subject) {
840 // First, we test the various ways the class deals with the root server URI.
841 $ret .= u_test_server_root_uri($test_subject, $uri);
842 $ret .= u_test_server_parameters_outgoing($test_subject);
843 $ret .= u_test_get_standard_server_parameters($test_subject, $uri);
844 $ret .= u_test_basic_search($uri);
845 $ret .= u_test_filtered_search($uri);
846 $serialized_transaction = null;
847 $ret .= u_test_complex_search($uri, $serialized_transaction);
848 $ret .= u_test_serialized_search($test_subject, $serialized_transaction);
849 $ret .= u_test_changes($uri);
850 } else {
851 $ret .= 'FAIL: Cannot instantiate bmlt_satellite_controller object!';
852 }
853 $ret .= '</div>';
854 }
855
856 $ret .= '<h1>END UNIT TEST</h1>';
857
858 //#######################
859 //### END TEST #
860 //#######################
861
862 $ret .= '</body></html>'; // Wrap up the page.
863
864 return $ret;
865}
Provides low-level communication to the BMLT Root Server.
u_test_complex_search( $in_root_server_uri, &$serialized_transaction)
Performs a more complex meeting search * *.
u_test_server_parameters_outgoing(&$in_test_subject)
Tests the outgoing parameter storage. * *.
u_test_get_test_server_uri()
Returns the URI for the test server. The default is the public trunk test server * and you can specif...
Definition unit_test.php:55
u_test_server_root_uri(&$in_test_subject, $in_uri)
Tests the various ways the class deals with the root URI . This will also * exercise the cURL calling...
u_test_get_standard_server_parameters(&$in_test_subject, $in_root_server_uri)
Apply the URI, and see if the server is there (can also test for bad URI) * *.
u_test_serialized_search( $in_test_subject, $serialized_transaction)
Performs a more complex meeting search * *.
u_test_filtered_search($in_root_server_uri)
Performs a more complex meeting search, but only gets a couple of the fields. * *.
u_test_changes($in_root_server_uri)
Queries the server for changes. *This function requires that the root server be version 1....
u_test_basic_search($in_root_server_uri)
Performs a basic meeting search * *.

References u_test_basic_search(), u_test_changes(), u_test_complex_search(), u_test_filtered_search(), u_test_get_standard_server_parameters(), u_test_get_test_server_uri(), u_test_serialized_search(), u_test_server_parameters_outgoing(), and u_test_server_root_uri().

◆ u_test_apply_root_uri()

u_test_apply_root_uri ( $in_test_subject,
  $in_root_server_uri 
)

Apply the URI, and see if the server is there (can also test for bad URI) * *.

Returns
A string. The XHTML to be displayed (Can be an error message). *
Parameters
$in_test_subjectThe object to be tested.
$in_root_server_uriA string. The root server URI.

Definition at line 80 of file unit_test.php.

83 {
84 $ret = '<h3>URI Test</h3>';
85 $ret .= '<div class="test_container_div">';
86 $in_test_subject->set_m_root_uri($in_root_server_uri);
87 $in_root_server_uri = $in_test_subject->get_m_root_uri();
88 $ret .= 'The object has the following URI set: ';
89 $ret .= htmlspecialchars($in_test_subject->get_m_root_uri());
90 $server_version = $in_test_subject->get_server_version();
91 $error_message = $in_test_subject->get_m_error_message();
92 if ($error_message) {
93 $ret .= '<br />The object reported the following error: "' . htmlspecialchars($error_message) . '"';
94 } else {
95 $ret .= '<br />The server reports that its version is ' . htmlspecialchars($server_version) . '<br />Test Passed!';
96 }
97 $ret .= '</div>';
98 return $ret;
99}

Referenced by u_test_server_root_uri().

◆ u_test_basic_search()

u_test_basic_search (   $in_root_server_uri)

Performs a basic meeting search * *.

Returns
A string. The XHTML to be displayed. *
Parameters
$in_root_server_uriThe root uri of the server to be searched.

Definition at line 386 of file unit_test.php.

387{
388 $ret = '<h1 id="basic_search_test"># BEGIN BASIC SEARCH UNIT TEST</h1>';
389 $ret .= '<div class="test_container_div">';
390
391 $start_time = microtime(true);
392 $test_subject = new bmlt_satellite_controller($in_root_server_uri);
393
394 $error_message = $test_subject->get_m_error_message();
395 if ($error_message) {
396 $ret .= 'The test failed, because the object reported the following error: "' . htmlspecialchars($error_message) . '"';
397 } else {
398 // OK. Very simple search. Look for meetings around Mineola, NY. This will return around 10 meetings.
399 $test_subject->set_current_transaction_parameter('SearchString', 'Mineola, NY');
400 if ($error_message) {
401 $ret .= 'The test failed, because the object reported the following error: "' . htmlspecialchars($error_message) . '"';
402 } else {
403 $test_subject->set_current_transaction_parameter('StringSearchIsAnAddress', true);
404 if ($error_message) {
405 $ret .= 'The test failed, because the object reported the following error: "' . htmlspecialchars($error_message) . '"';
406 } else {
407 $search_result = $test_subject->meeting_search();
408 $error_message = $test_subject->get_m_error_message();
409 if ($error_message) {
410 $ret .= 'The test failed, because the object reported the following error: "' . htmlspecialchars($error_message) . '"';
411 } elseif (isset($search_result) && is_array($search_result) && count($search_result)) {
412 $total_time = intval((microtime(true) - $start_time) * 1000);
413 // We now have a meeting search result. Let's display it.
414 $ret .= '<h2>Test Passed! (The complete setup and search took ';
415 if ($total_time > 1000) {
416 $total_time /= 1000.0;
417 $ret .= htmlspecialchars($total_time) . ' seconds';
418 } else {
419 $ret .= htmlspecialchars($total_time) . ' milliseconds';
420 }
421 $ret .= ' to run.) Here are the returned meetings:</h2><div class="test_container_div">';
422 foreach ($search_result['meetings'] as $meeting) {
423 $ret .= u_test_draw_meeting($meeting);
424 }
425
426 $ret .= '</div>';
427 $ret .= '<h3>The query URI was: ' . htmlspecialchars($search_result['uri']) . '<br />(Search for all meetings near Mineola, NY)</h3>';
428 } else {
429 $ret .= 'Test Failed! No Meetings Returned!';
430 }
431 }
432 }
433 }
434
435 $ret .= '</div>';
436 $ret .= '<h1># END BASIC SEARCH UNIT TEST</h1>';
437
438 return $ret;
439}
u_test_draw_meeting($in_meeting_array)
Displays one meeting in a hierarchical fashion. * *.

References u_test_draw_meeting().

Referenced by u_test().

◆ u_test_changes()

u_test_changes (   $in_root_server_uri)

Queries the server for changes. *

  • This function requires that the root server be version 1.8.13 or above. It queries the * server for all the meeting changes that occurred in a six-week window, beginning seven * weeks ago, and ending one week ago. The changes are returned with the most recent ones * first, going down to the oldest. * *.

Returns
A string. The XHTML to be displayed. *
Parameters
$in_root_server_uriThe server URI.

Definition at line 693 of file unit_test.php.

694{
695 $ret = null;
696 $ret = '<h1 id="change_request_test"># BEGIN CHANGE REQUEST UNIT TEST</h1>';
697 $ret .= '<div class="test_container_div">';
698 $ret .= '<h2 id="change_request_test"># BEGIN GENERAL CHANGES TEST</h1>';
699
700 $start_time = microtime(true);
701 $test_subject = new bmlt_satellite_controller($in_root_server_uri);
702 $error_message = $test_subject->get_m_error_message();
703 if ($error_message) {
704 $ret .= 'The test failed, because the object reported the following error: "' . htmlspecialchars($error_message) . '"';
705 } else {
706 // We will get changes from 7 weeks ago, to 1 week ago (six week period).
707 $start_date = time() - (7 * 24 * 60 * 60 * 7);
708 $end_date = time() - (7 * 24 * 60 * 60);
709 $change_array = $test_subject->get_meeting_changes($start_date, $end_date);
710 $error_message = $test_subject->get_m_error_message();
711 if ($error_message) {
712 $ret .= 'The test failed, because the object reported the following error: "' . htmlspecialchars($error_message) . '"';
713 } elseif (is_array($change_array) && count($change_array)) {
714 $total_time = intval((microtime(true) - $start_time) * 1000);
715 // We now have a meeting search result. Let's display it.
716 $ret .= '<h2>Test Passed! (The complete transaction took ';
717 if ($total_time > 1000) {
718 $total_time /= 1000.0;
719 $ret .= htmlspecialchars($total_time) . ' seconds';
720 } else {
721 $ret .= htmlspecialchars($total_time) . ' milliseconds';
722 }
723 $ret .= ' to run.) Here are the meeting changes from ' . htmlspecialchars(date('F j, Y', $start_date)) . ' to ' . htmlspecialchars(date('F j, Y', $end_date)) . ':</h2><div class="test_container_div">';
724 $ret .= '<pre>' . htmlspecialchars(print_r($change_array, true)) . '</pre>';
725 $ret .= '</div>';
726 } else {
727 $ret .= 'The test failed, because the object returned no meeting changes for the given period.';
728 }
729 }
730 $ret .= '<h2># END GENERAL CHANGES TEST</h1>';
731 $ret .= '</div>';
732 $ret .= '<div class="test_container_div">';
733 $ret .= '<h2 id="change_meeting_request_test"># BEGIN SPECIFIC MEETING CHANGES TEST</h1>';
734 $change_array = $test_subject->get_meeting_changes(null, null, U_TEST_MEETING_ID);
735 $error_message = $test_subject->get_m_error_message();
736 if ($error_message) {
737 $ret .= 'The test failed, because the object reported the following error: "' . htmlspecialchars($error_message) . '"';
738 } elseif (is_array($change_array) && count($change_array)) {
739 $total_time = intval((microtime(true) - $start_time) * 1000);
740 // We now have a meeting search result. Let's display it.
741 $ret .= '<h2>Test Passed! (The complete transaction took ';
742 if ($total_time > 1000) {
743 $total_time /= 1000.0;
744 $ret .= htmlspecialchars($total_time) . ' seconds';
745 } else {
746 $ret .= htmlspecialchars($total_time) . ' milliseconds';
747 }
748 $ret .= ' to run.) Here are the meeting changes for this meeting:</h2><div class="test_container_div">';
749 $ret .= '<pre>' . htmlspecialchars(print_r($change_array, true)) . '</pre>';
750 $ret .= '</div>';
751 } else {
752 $ret .= 'The test failed, because the object returned no meeting changes for the given period.';
753 }
754 $ret .= '<h2># END SPECIFIC MEETING CHANGES TEST</h1>';
755 $ret .= '</div>';
756 $ret .= '<h1># END CHANGE REQUEST UNIT TEST</h1>';
757
758 return $ret;
759}
const U_TEST_MEETING_ID
This is an ID for a specific meeting (with some changes) for the meeting changes test.
Definition unit_test.php:44

References U_TEST_MEETING_ID.

Referenced by u_test().

◆ u_test_complex_search()

u_test_complex_search (   $in_root_server_uri,
$serialized_transaction 
)

Performs a more complex meeting search * *.

Returns
A string. The XHTML to be displayed. *
Parameters
$in_root_server_uriThe root uri of the server to be searched.
$serialized_transactionThis will hold the serialized transaction for another test.

Definition at line 446 of file unit_test.php.

449 {
450 $ret = '<h1 id="complex_search_test"># BEGIN COMPLEX SEARCH UNIT TEST</h1>';
451 $ret .= '<div class="test_container_div">';
452
453 $start_time = microtime(true);
454 $test_subject = new bmlt_satellite_controller($in_root_server_uri);
455 $error_message = $test_subject->get_m_error_message();
456 if ($error_message) {
457 $ret .= 'The test failed, because the object reported the following error: "' . htmlspecialchars($error_message) . '"';
458 } else {
459 // OK. Very simple search. Look for meetings around Mineola, NY. This will return around 10 meetings.
460 $test_subject->set_current_transaction_parameter('SearchString', 'Bleeker Street at 14th Street, Manhattan, NY');
461 $error_message = $test_subject->get_m_error_message();
462 if ($error_message) {
463 $ret .= 'The test failed, because the object reported the following error: "' . htmlspecialchars($error_message) . '"';
464 } else {
465 $test_subject->set_current_transaction_parameter('StringSearchIsAnAddress', true);
466 $error_message = $test_subject->get_m_error_message();
467 if ($error_message) {
468 $ret .= 'The test failed, because the object reported the following error: "' . htmlspecialchars($error_message) . '"';
469 } else {
470 $test_subject->set_current_transaction_parameter('weekdays', array ( 1, 2, 3, 4, 5 ));
471 $error_message = $test_subject->get_m_error_message();
472 if ($error_message) {
473 $ret .= 'The test failed, because the object reported the following error: "' . htmlspecialchars($error_message) . '"';
474 } else {
475 $test_subject->set_current_transaction_parameter('formats', array ( 17 ));
476 $error_message = $test_subject->get_m_error_message();
477 if ($error_message) {
478 $ret .= 'The test failed, because the object reported the following error: "' . htmlspecialchars($error_message) . '"';
479 } else {
480 $test_subject->set_current_transaction_parameter('langs', array ( 'en' ));
481 if ($error_message) {
482 $ret .= 'The test failed, because the object reported the following error: "' . htmlspecialchars($error_message) . '"';
483 } else {
484 $search_result = $test_subject->meeting_search();
485 $error_message = $test_subject->get_m_error_message();
486 if ($error_message) {
487 $ret .= 'The test failed, because the object reported the following error: "' . htmlspecialchars($error_message) . '"';
488 } elseif (isset($search_result) && is_array($search_result) && count($search_result)) {
489 if (!isset($search_result['meetings']) || !is_array($search_result['meetings']) || !count($search_result['meetings'])) {
490 $ret .= '<h2>Test Failed! No meetings were returned!</h2>';
491 } else {
492 $total_time = intval((microtime(true) - $start_time) * 1000);
493 // We now have a meeting search result. Let's display it.
494 $ret .= '<h2>Test Passed! (The complete setup and search took ';
495 if ($total_time > 1000) {
496 $total_time /= 1000.0;
497 $ret .= htmlspecialchars($total_time) . ' seconds';
498 } else {
499 $ret .= htmlspecialchars($total_time) . ' milliseconds';
500 }
501 $ret .= ' to run.) Here are the returned meetings:</h2><div class="test_container_div">';
502 foreach ($search_result['meetings'] as $meeting) {
503 $ret .= u_test_draw_meeting($meeting);
504 }
505
506 $ret .= '</div>';
507 }
508
509 $ret .= '<h3>The query URI was: ' . htmlspecialchars($search_result['uri']) . '<br />(Search for open, English-speaking, beginners\' meetings, on Sunday, Monday, Tuesday, Wednesday, or Thursday, near Bleeker Street and 14th Street, in Manhattan)</h3>';
510 $serialized_transaction = $search_result['serialized'];
511 } else {
512 $ret .= 'Test Failed! No Meetings Returned!';
513 }
514 }
515 }
516 }
517 }
518 }
519 }
520
521 $ret .= '</div>';
522 $ret .= '<h1># END COMPLEX SEARCH UNIT TEST</h1>';
523
524 return $ret;
525}

References u_test_draw_meeting().

Referenced by u_test().

◆ u_test_draw_meeting()

u_test_draw_meeting (   $in_meeting_array)

Displays one meeting in a hierarchical fashion. * *.

Returns
A string. The XHTML to be displayed. *

Definition at line 670 of file unit_test.php.

671{
672 $ret = '<div class="name_div"><h3>' . htmlspecialchars($in_meeting_array['meeting_name']) . ' (' . htmlspecialchars($in_meeting_array['id_bigint']) . ')</h3>';
673 foreach ($in_meeting_array as $key => $value) {
674 if ($key != 'meeting_name' && $key != 'id_bigint') {
675 $ret .= '<div class="test_container_div"><strong>' . htmlspecialchars($key) . ':</strong> ' . htmlspecialchars($value) . '</div>';
676 }
677 }
678 $ret .= '</div>';
679
680 return $ret;
681}

Referenced by u_test_basic_search(), u_test_complex_search(), and u_test_serialized_search().

◆ u_test_draw_service_body()

u_test_draw_service_body (   $in_service_body_array)

Displays Service bodies in a hierarchical fashion. * *.

Returns
A string. The XHTML to be displayed (Can be an error message). *

Definition at line 179 of file unit_test.php.

180{
181 $ret = '<div class="name_div"><strong>' . htmlspecialchars($in_service_body_array['name']) . '</strong></div>';
182 $ret .= '<div class="test_container_div">';
183 $ret .= '<div class="type_div">' . htmlspecialchars($in_service_body_array['type']) . '</div>';
184 $ret .= '<div class="desc_div">' . htmlspecialchars($in_service_body_array['description']) . '</div>';
185 $ret .= '<div class="uri_div">' . htmlspecialchars($in_service_body_array['uri']) . '</div>';
186 $ret .= '<div class="kmluri_div">' . htmlspecialchars($in_service_body_array['kmluri']) . '</div>';
187 if (isset($in_service_body_array['children']) && is_array($in_service_body_array['children']) && count($in_service_body_array['children'])) {
188 $ret .= '<div class="test_container_div">';
189 foreach ($in_service_body_array['children'] as $child) {
190 $ret .= u_test_draw_service_body($child);
191 }
192 $ret .= '</div>';
193 }
194 $ret .= '</div>';
195
196 return $ret;
197}
u_test_draw_service_body($in_service_body_array)
Displays Service bodies in a hierarchical fashion. * *.

References u_test_draw_service_body().

Referenced by u_test_draw_service_body(), and u_test_get_standard_server_parameters().

◆ u_test_filtered_search()

u_test_filtered_search (   $in_root_server_uri)

Performs a more complex meeting search, but only gets a couple of the fields. * *.

Returns
A string. The XHTML to be displayed. *
Parameters
$in_root_server_uriThe root uri of the server to be searched.

Definition at line 532 of file unit_test.php.

533{
534 $ret = '<h1 id="partial_search_test"># BEGIN FILTERED SEARCH UNIT TEST</h1>';
535 $ret .= '<div class="test_container_div">';
536
537 $start_time = microtime(true);
538 $test_subject = new bmlt_satellite_controller($in_root_server_uri);
539 $error_message = $test_subject->get_m_error_message();
540 if ($error_message) {
541 $ret .= 'The test failed, because the object reported the following error: "' . htmlspecialchars($error_message) . '"';
542 } else {
543 // OK. Very simple search. Look for meetings around Mineola, NY. This will return around 10 meetings.
544 $test_subject->set_current_transaction_parameter('SearchString', 'Bleeker Street at 14th Street, Manhattan, NY');
545 $error_message = $test_subject->get_m_error_message();
546 if ($error_message) {
547 $ret .= 'The test failed, because the object reported the following error: "' . htmlspecialchars($error_message) . '"';
548 } else {
549 $test_subject->set_current_transaction_parameter('StringSearchIsAnAddress', true);
550 $error_message = $test_subject->get_m_error_message();
551 if ($error_message) {
552 $ret .= 'The test failed, because the object reported the following error: "' . htmlspecialchars($error_message) . '"';
553 } else {
554 $test_subject->set_current_transaction_parameter('data_field_key', 'location_municipality,meeting_name');
555 $error_message = $test_subject->get_m_error_message();
556 if ($error_message) {
557 $ret .= 'The test failed, because the object reported the following error: "' . htmlspecialchars($error_message) . '"';
558 } else {
559 $search_result = $test_subject->meeting_search(true);
560 $error_message = $test_subject->get_m_error_message();
561 if ($error_message) {
562 $ret .= 'The test failed, because the object reported the following error: "' . htmlspecialchars($error_message) . '"';
563 } elseif (isset($search_result) && is_array($search_result) && count($search_result)) {
564 if (!isset($search_result['meetings']) || !is_array($search_result['meetings']) || !count($search_result['meetings'])) {
565 $ret .= '<h2>Test Failed! No meetings were returned!</h2>';
566 } else {
567 $total_time = intval((microtime(true) - $start_time) * 1000);
568 // We now have a meeting search result. Let's display it.
569 $pass = true;
570 foreach ($search_result['meetings'] as $meeting) {
571 foreach ($meeting as $key => $value) {
572 if (($key != 'location_municipality') && ($key != 'meeting_name' )) {
573 $ret .= 'The meeting should not have the ' . htmlspecialchars($key) . ' field!!';
574 $pass = false;
575 break;
576 }
577 }
578 }
579
580 if ($pass) {
581 $ret .= '<h2>Test Passed! (The complete setup and search took ';
582 if ($total_time > 1000) {
583 $total_time /= 1000.0;
584 $ret .= htmlspecialchars($total_time) . ' seconds';
585 } else {
586 $ret .= htmlspecialchars($total_time) . ' milliseconds';
587 }
588 $ret .= ' to run.).';
589 } else {
590 $ret .= 'Test Failed! The meeting data had extra fields!';
591 }
592 }
593
594 $ret .= '<h3>The query URI was: ' . htmlspecialchars($search_result['uri']) . '</h3>';
595 } else {
596 $ret .= 'Test Failed! No Meetings Returned!';
597 }
598 }
599 }
600 }
601 }
602
603 $ret .= '</div>';
604 $ret .= '<h1># END FILTERED SEARCH UNIT TEST</h1>';
605
606 return $ret;
607}

Referenced by u_test().

◆ u_test_get_standard_server_parameters()

u_test_get_standard_server_parameters ( $in_test_subject,
  $in_root_server_uri 
)

Apply the URI, and see if the server is there (can also test for bad URI) * *.

Returns
A string. The XHTML to be displayed (Can be an error message). *
Parameters
$in_test_subjectThe object to be tested.
$in_root_server_uriA string. The root server URI.

Definition at line 106 of file unit_test.php.

109 {
110 $ret = '<h1 id="standard_query_test"># BEGIN STANDARD SERVER QUERY UNIT TESTS</h1>';
111 $ret .= '<div class="test_container_div">';
112 $ret .= '<h3>Standard Server Parameters Test</h3>';
113 $in_test_subject->set_m_root_uri($in_root_server_uri);
114 $ret .= '<div class="test_container_div">';
115
116 $server_formats = $in_test_subject->get_server_formats();
117 $error_message = $in_test_subject->get_m_error_message();
118 if ($error_message) {
119 $ret .= '<br />The object reported the following error: "' . htmlspecialchars($error_message) . '"';
120 } else {
121 $server_langs_ret = $in_test_subject->get_server_langs();
122 $server_langs = '';
123 $def_lang = '';
124 foreach ($server_langs_ret as $lang) {
125 if ($server_langs) {
126 $server_langs .= ', ';
127 }
128 $server_langs .= $lang['name'];
129
130 if ($lang['default']) {
131 $server_langs .= ' (default language)';
132 if (isset($lang['key'])) {
133 $def_lang = $lang['key'];
134 }
135 }
136 }
137 $error_message = $in_test_subject->get_m_error_message();
138 if ($error_message) {
139 $ret .= '<br />The object reported the following error: "' . htmlspecialchars($error_message) . '"';
140 } else {
141 $server_service_bodies = $in_test_subject->get_server_service_bodies();
142 $error_message = $in_test_subject->get_m_error_message();
143 if ($error_message) {
144 $ret .= '<br />The object reported the following error: "' . htmlspecialchars($error_message) . '"';
145 } else {
146 $server_meeting_keyss = $in_test_subject->get_server_meeting_keys();
147 $error_message = $in_test_subject->get_m_error_message();
148 if ($error_message) {
149 $ret .= '<br />The object reported the following error: "' . htmlspecialchars($error_message) . '"';
150 } else {
151 $ret .= '<h4>The server at ' . htmlspecialchars($in_root_server_uri) . ' supports the following languages:</h4><div class="test_container_div">' . htmlspecialchars($server_langs);
152 $ret .= '</div><h4>The server at ' . htmlspecialchars($in_root_server_uri) . ' supports the following formats:</h4>';
153 foreach ($server_formats as $id => $format) {
154 $ret .= '<div class="test_container_div"><strong>' . htmlspecialchars($id) . ' ' . htmlspecialchars($format['key_string']) . '</strong> (' . htmlspecialchars($format['description_string']) . ')</div>';
155 }
156 $ret .= '<h4>The server at ' . htmlspecialchars($in_root_server_uri) . ' has the following Service bodies:</h4><div class="test_container_div">';
157 foreach ($server_service_bodies as $sb) {
158 $ret .= u_test_draw_service_body($sb);
159 }
160 $ret .= '</div><h4>The server at ' . htmlspecialchars($in_root_server_uri) . ' has the following Meeting Keys:</h4>';
161 foreach ($server_meeting_keyss as $key) {
162 $ret .= '<div class="test_container_div">' . htmlspecialchars($key) . '</div>';
163 }
164 }
165 }
166 }
167 }
168 $ret .= '</div>';
169 $ret .= '</div>';
170 $ret .= '<h1># END STANDARD SERVER QUERY UNIT TESTS</h1>';
171 return $ret;
172}

References u_test_draw_service_body().

Referenced by u_test().

◆ u_test_get_test_server_uri()

u_test_get_test_server_uri ( )

Returns the URI for the test server. The default is the public trunk test server * and you can specify a local server if running on a localhost machine. *

Returns
A string. The URI to be presented to the class. *

Definition at line 55 of file unit_test.php.

56{
57 // First, establish our working URIs.
58 $ret = U_TEST_REMOTE_URI; // We return the remote by default.
59 $local = ( defined('U_TEST_LOCAL_URI') ? U_TEST_LOCAL_URI : null);
60
61 // If we are running local, and have a local URI, we return that, instead.
62 if ($local && preg_match('|localhost|', $_SERVER['SERVER_NAME'])) {
63 $ret = $local;
64 }
65
66 $override_uri = (isset($_GET['test_uri']) && $_GET['test_uri']) ? $_GET['test_uri'] : null; // The caller can specify a URI that will override the presets.
67
68 if ($override_uri) {
69 $ret = $override_uri;
70 }
71
72 return $ret;
73}
const U_TEST_LOCAL_URI
If running on localhost, you can specify a local root URI. Comment this out to always use remote.
Definition unit_test.php:41
const U_TEST_REMOTE_URI
This is the URI to resolve a test root server (remote). Default is the public trunk test (not stable)...
Definition unit_test.php:38

References U_TEST_LOCAL_URI, and U_TEST_REMOTE_URI.

Referenced by u_test().

◆ u_test_serialized_search()

u_test_serialized_search (   $in_test_subject,
  $serialized_transaction 
)

Performs a more complex meeting search * *.

Returns
A string. The XHTML to be displayed. *
Parameters
$in_test_subjectAn initialized object.
$serialized_transactionThis has the serialized transaction for the test.

Definition at line 614 of file unit_test.php.

617 {
618 $ret = '<h1 id="serialized_search_test"># BEGIN SERIALIZED SEARCH UNIT TEST</h1>';
619 $ret .= '<div class="test_container_div">';
620
621 $start_time = microtime(true);
622
623 $in_test_subject->apply_serialized_transaction($serialized_transaction);
624 $error_message = $in_test_subject->get_m_error_message();
625 if ($error_message) {
626 $ret .= 'The test failed, because the object reported the following error: "' . htmlspecialchars($error_message) . '"';
627 } else {
628 $search_result = $in_test_subject->meeting_search();
629 $error_message = $in_test_subject->get_m_error_message();
630 if ($error_message) {
631 $ret .= 'The test failed, because the object reported the following error: "' . htmlspecialchars($error_message) . '"';
632 } elseif (isset($search_result) && is_array($search_result) && count($search_result)) {
633 if (!isset($search_result['meetings']) || !is_array($search_result['meetings']) || !count($search_result['meetings'])) {
634 $ret .= '<h2>Test Failed! No meetings were returned!</h2>';
635 } else {
636 $total_time = intval((microtime(true) - $start_time) * 1000);
637 // We now have a meeting search result. Let's display it.
638 $ret .= '<h2>Test Passed! (The complete search took ';
639 if ($total_time > 1000) {
640 $total_time /= 1000.0;
641 $ret .= htmlspecialchars($total_time) . ' seconds';
642 } else {
643 $ret .= htmlspecialchars($total_time) . ' milliseconds';
644 }
645 $ret .= ' to run.) Here are the returned meetings:</h2><div class="test_container_div">';
646 foreach ($search_result['meetings'] as $meeting) {
647 $ret .= u_test_draw_meeting($meeting);
648 }
649
650 $ret .= '</div>';
651 }
652
653 $ret .= '<h3>The query URI was: ' . htmlspecialchars($search_result['uri']);
654 } else {
655 $ret .= 'Test Failed! No Meetings Returned!';
656 }
657 }
658
659 $ret .= '</div>';
660 $ret .= '<h1># END SERIALIZED SEARCH UNIT TEST</h1>';
661
662 return $ret;
663}

References u_test_draw_meeting().

Referenced by u_test().

◆ u_test_server_parameters_outgoing()

u_test_server_parameters_outgoing ( $in_test_subject)

Tests the outgoing parameter storage. * *.

Returns
A string. The XHTML to be displayed (Can be an error message). *
Parameters
$in_test_subjectThe object to be tested.

Definition at line 277 of file unit_test.php.

278{
279 $ret = '<h1 id="outgoing_parameter_test"># BEGIN OUTGOING PARAMETER STORAGE UNIT TESTS</h1>';
280 $ret .= '<div class="test_container_div">';
281 $ret .= '<h2>Place two Values By Two Keys, Then Retrieve Them</h2>';
282 $ret .= '<div class="test_container_div">';
283 $test_key = 'SearchString';
284 $test_val = 'Test Value String 1';
285 $in_test_subject->set_m_outgoing_parameter($test_key, $test_val);
286 $error_message = $in_test_subject->get_m_error_message();
287
288 if ($error_message) {
289 $ret .= 'The test failed, because the object reported the following error: "' . htmlspecialchars($error_message) . '"';
290 } else {
291 $test_key2 = 'meeting_key_value';
292 $test_val2 = 'Test Value String 2';
293 $in_test_subject->set_m_outgoing_parameter($test_key2, $test_val2);
294 $error_message = $in_test_subject->get_m_error_message();
295
296 if ($error_message) {
297 $ret .= 'The test failed, because the object reported the following error: "' . htmlspecialchars($error_message) . '"';
298 } else {
299 $returned_val = $in_test_subject->get_m_outgoing_parameter($test_key);
300 $error_message = $in_test_subject->get_m_error_message();
301
302 if ($error_message) {
303 $ret .= 'The test failed, because the object reported the following error: "' . htmlspecialchars($error_message) . '"';
304 } else {
305 if (is_string($returned_val) && ( strcmp($returned_val, $test_val) === 0 )) {
306 $ret .= 'Test Passed! The object stored and returned the first string correctly.';
307 } else {
308 $ret .= "Test Failed! '$returned_val', which was returned from the object, is not '$test_val', which was stored in the object! ($test_key)";
309 }
310 }
311
312 $returned_val2 = $in_test_subject->get_m_outgoing_parameter($test_key2);
313
314 $ret .= '<br />';
315
316 $error_message = $in_test_subject->get_m_error_message();
317
318 if ($error_message) {
319 $ret .= 'The test failed, because the object reported the following error: "' . htmlspecialchars($error_message) . '"';
320 } else {
321 if (is_string($returned_val2) && ( strcmp($returned_val2, $test_val2) === 0 )) {
322 $ret .= 'Test Passed! The object stored and returned the second string correctly.';
323 } else {
324 $ret .= "Test Failed! '$returned_val2', which was returned from the object, is not '$test_val2', which was stored in the object! ($test_key2)";
325 }
326 }
327 }
328 }
329 $ret .= '</div>';
330
331 $ret .= '<h2>Make Sure That The Errors Are Set for Bad Key Selection</h2>';
332 $ret .= '<div class="test_container_div">';
333 // At this point, the storage has one element, with a key of $test_key, and a value of $test_val2. We deliberately ask for a bad key.
334
335 $returned_val = $in_test_subject->get_m_outgoing_parameter('badz-maru');
336 $error_message = $in_test_subject->get_m_error_message();
337
338 if ($error_message) {
339 if ($returned_val === null) {
340 $ret .= 'The test passed, because the object reported the following error: "' . htmlspecialchars($error_message) . '"';
341 } else {
342 $ret .= 'The test failed, because the object reported the following error: "' . htmlspecialchars($error_message) . '", but the following value was returned: "' . htmlspecialchars($returned_val) . '"';
343 }
344
345 // Extra test. Make sure the error message clears.
346
347 $in_test_subject->clear_m_error_message();
348
349 if ($in_test_subject->get_m_error_message()) {
350 $ret .= '<br />The error message was not cleared! Test fail!';
351 }
352 } else {
353 $ret .= 'The Test Failed! We were expecting an error!';
354 }
355
356 // Now, we set a bad key.
357 $in_test_subject->set_m_outgoing_parameter('spaz', $test_val);
358 $error_message = $in_test_subject->get_m_error_message();
359 $ret .= '<br />';
360 if ($error_message) {
361 $ret .= 'The test passed, because the object reported the following error: "' . htmlspecialchars($error_message) . '"';
362 $in_test_subject->clear_m_error_message();
363 } else {
364 $ret .= 'The Test Failed! We were expecting an error!';
365 }
366
367 // Just make sure we don't get anything returned from a null request.
368 $returned_val = $in_test_subject->get_m_outgoing_parameter(null);
369
370 if ($returned_val !== null) {
371 $ret .= '<br />The Test Failed! We got data from a null request!';
372 }
373 $ret .= '</div>';
374
375 $ret .= '</div>';
376 $ret .= '<h1># END OUTGOING PARAMETER STORAGE UNIT TESTS</h1>';
377
378 return $ret;
379}

Referenced by u_test().

◆ u_test_server_root_uri()

u_test_server_root_uri ( $in_test_subject,
  $in_uri 
)

Tests the various ways the class deals with the root URI . This will also * exercise the cURL calling and server communication. * *.

Returns
A string. The XHTML to be displayed (Can be an error message). *
Parameters
$in_test_subjectThe object to be tested.
$in_uriThe base URI.

Definition at line 205 of file unit_test.php.

208 {
209 $ret = '<h1 id="root_uri_accessor_test"># BEGIN ROOT URI ACCESSOR UNIT TESTS</h1>';
210 $ret .= '<div class="test_container_div">';
211 // First, simply test that the object saves the URI, and that it can use it to connect to the server.
212 $ret .= '<h2>Test With Good URI</h2>';
213 $ret .= '<div class="test_container_div">';
214 $test_uri = $in_uri;
215 $ret .= 'We are giving the object the following URI: ' . htmlspecialchars($test_uri) . '<br />';
216 $ret .= u_test_apply_root_uri($in_test_subject, $in_uri);
217 $ret .= '</div>';
218
219 // Next, make sure that a trailing slash is removed from a given URI.
220 $ret .= '<h2>Test With Good URI (With Slash at End)</h2>';
221 $ret .= '<div class="test_container_div">';
222 $test_uri = $in_uri . '/';
223 $ret .= 'We are giving the object the following URI: ' . htmlspecialchars($test_uri) . '<br />';
224 $ret .= u_test_apply_root_uri($in_test_subject, $test_uri);
225 $ret .= '</div>';
226
227 // Next, make sure that the default 'http://' is added to the URI.
228 $ret .= '<h2>Test With Good URI (With No Protocol Preamble)</h2>';
229 $ret .= '<div class="test_container_div">';
230 $test_uri = str_replace('http://', '', $in_uri);
231 $ret .= 'We are giving the object the following URI: ' . htmlspecialchars($test_uri) . '<br />';
232 $ret .= u_test_apply_root_uri($in_test_subject, $test_uri);
233 $ret .= '</div>';
234
235 // This is a typical "Copy and Paste" typo.
236 $ret .= '<h2>Test With Bad URI (Typical Typo Mistake -Will be Corrected)</h2>';
237 $ret .= '<div class="test_container_div">';
238 $test_uri = str_replace('http://', 'ttp://', $in_uri);
239 $ret .= 'We are giving the object the following URI: ' . htmlspecialchars($test_uri) . '<br />';
240 $ret .= u_test_apply_root_uri($in_test_subject, $test_uri);
241 $ret .= '</div>';
242
243 // This specifies an invalid protocol. It will be replaced by the default HTTP.
244 $ret .= '<h2>Test With Bad URI (Invalid Protocol -Will be Corrected)</h2>';
245 $ret .= '<div class="test_container_div">';
246 $test_uri = str_replace('http://', 'wcal://', $in_uri);
247 $ret .= 'We are giving the object the following URI: ' . htmlspecialchars($test_uri) . '<br />';
248 $ret .= u_test_apply_root_uri($in_test_subject, $test_uri);
249 $ret .= '</div>';
250
251 // This is a typical "Copy and Paste" typo. This one will not be corrected, as it is merely a missing piece from the end.
252 $ret .= '<h2>Test With Bad URI (Typical Typo Mistake -Will Not be Corrected)</h2>';
253 $ret .= '<div class="test_container_div">';
254 $test_uri = preg_replace('|.$|', '', $in_uri);
255 $ret .= 'We are giving the object the following URI: ' . htmlspecialchars($test_uri) . '<br />';
256 $ret .= u_test_apply_root_uri($in_test_subject, $test_uri);
257 $ret .= '</div>';
258
259 // This one is just plain bad.
260 $ret .= '<h2>Test With Bad URI (Will Not be Corrected)</h2>';
261 $ret .= '<div class="test_container_div">';
262 $test_uri = $in_uri . '/monkee-business';
263 $ret .= 'We are giving the object the following URI: ' . htmlspecialchars($test_uri) . '<br />';
264 $ret .= u_test_apply_root_uri($in_test_subject, $test_uri);
265 $ret .= '</div>';
266 $ret .= '</div>';
267 $ret .= '<h1># END ROOT URI ACCESSOR UNIT TESTS</h1>';
268
269 return $ret;
270}
u_test_apply_root_uri(&$in_test_subject, $in_root_server_uri)
Apply the URI, and see if the server is there (can also test for bad URI) * *.
Definition unit_test.php:80

References u_test_apply_root_uri().

Referenced by u_test().

Variable Documentation

◆ U_TEST_LOCAL_URI

const U_TEST_LOCAL_URI 'http://bmlt-server.localhost'

If running on localhost, you can specify a local root URI. Comment this out to always use remote.

Definition at line 41 of file unit_test.php.

Referenced by u_test_get_test_server_uri().

◆ U_TEST_MEETING_ID

const U_TEST_MEETING_ID 734

This is an ID for a specific meeting (with some changes) for the meeting changes test.

Definition at line 44 of file unit_test.php.

Referenced by u_test_changes().

◆ U_TEST_REMOTE_URI

const U_TEST_REMOTE_URI 'https://bmlt.app/trunk/main_server'

This is the URI to resolve a test root server (remote). Default is the public trunk test (not stable).

Definition at line 38 of file unit_test.php.

Referenced by u_test_get_test_server_uri().