Inheritance: extends BaseObject
示例#1
0
 function testEffort()
 {
     global $g_streber_url;
     TestEnvironment::initStreberUrl();
     TestEnvironment::prepare('fixtures/project_setup.sql');
     $this->addHeader('USER_AGENT: streber_unit_tester');
     ### logout first ###
     $this->assertTrue($this->get($g_streber_url), 'getting login page (%s)');
     $this->assertWantedPattern('/please login/i', 'check content (%s)');
     $this->assertValidHtmlStucture('login');
     ### Test login working ###
     $this->assertTrue($this->setField('login_name', 'bob'));
     $this->assertTrue($this->setField('login_password', 'bob_secret'));
     $this->assertTrue($this->clickSubmit('Submit'));
     validatePage($this);
     $this->assertTrue($this->get($g_streber_url . "/index.php?go=projViewEfforts&prj=10"), 'getting project effort view (%s)');
     validatePage($this);
     $this->assertTrue($this->get($g_streber_url . "/index.php?go=homeListEfforts"), 'getting user efforts (%s)');
     validatePage($this);
     $this->assertTrue($this->get($g_streber_url . "/index.php?go=effortNew&prj=10"), 'book new effort (%s)');
     validatePage($this);
     $this->assertTrue($this->setField('effort_name', 'bla2'));
     $this->assertTrue($this->clickSubmit('Submit'));
     validatePage($this);
 }
 public function testAccountGetById_Ok()
 {
     $client = TestEnvironment::client();
     $response = $client->get('/modules/api/bankaccounts/1', array('headers' => TestEnvironment::headers()));
     $this->assertEquals('200', $response->getStatusCode());
     $result = $response->getBody();
     $result = json_decode($result);
     $expected = new stdClass();
     $expected->account_code = '1060';
     $expected->account_type = '0';
     $expected->id = '1';
     $expected->bank_account_name = 'Current account';
     $expected->bank_name = 'N/A';
     $expected->bank_account_number = 'N/A';
     $expected->bank_curr_code = 'USD';
     $expected->bank_address = '';
     $expected->dflt_curr_act = '1';
     $expected->last_reconciled_date = '0000-00-00 00:00:00';
     $expected->ending_reconcile_balance = '0';
     $expected->inactive = '0';
     $expected->{'0'} = '1060';
     $expected->{'1'} = '0';
     $expected->{'2'} = 'Current account';
     $expected->{'3'} = 'N/A';
     $expected->{'4'} = 'N/A';
     $expected->{'5'} = '';
     $expected->{'6'} = 'USD';
     $expected->{'7'} = '1';
     $expected->{'8'} = '1';
     $expected->{'9'} = '0000-00-00 00:00:00';
     $expected->{'10'} = '0';
     $expected->{'11'} = '0';
     $this->assertEquals($expected, $result);
 }
 public function testAccountTypes_Ok()
 {
     $client = TestEnvironment::client();
     $response = $client->get('/modules/api/glaccounttypes', array('headers' => TestEnvironment::headers()));
     $this->assertEquals('200', $response->getStatusCode());
     $result = $response->getBody();
     $result = json_decode($result);
 }
 public static function createItem($client, $id, $description)
 {
     $response = $client->post('/modules/api/inventory/', array('headers' => TestEnvironment::headers(), 'body' => array('stock_id' => $id, 'description' => $description, 'long_description' => $description, 'category_id' => '1', 'tax_type_id' => '1', 'units' => 'ea', 'mb_flag' => '0', 'sales_account' => '1', 'inventory_account' => '1', 'cogs_account' => '1', 'adjustment_account' => '1', 'assembly_account' => '1')));
     $result = $response->getStatusCode();
     if ($result != 201) {
         throw new \Exception('Create item failed', $result);
     }
 }
 public function testCRUD_Ok()
 {
     $client = TestEnvironment::client();
     // List
     $response = $client->get('/modules/api/category/', array('headers' => TestEnvironment::headers()));
     $this->assertEquals('200', $response->getStatusCode());
     $result = $response->getBody();
     $result = json_decode($result);
     $count0 = count($result);
     $this->assertGreaterThan(1, $count0);
     // Add
     $response = $client->post('/modules/api/category/', array('headers' => TestEnvironment::headers(), 'body' => array('description' => 'description', 'tax_type_id' => '1', 'units' => 'each', 'mb_flag' => 'D', 'sales_account' => '4010', 'cogs_account' => '5010', 'adjustment_account' => '5040', 'assembly_account' => '1530', 'inventory_account' => '1510')));
     $this->assertEquals('201', $response->getStatusCode());
     $result = $response->getBody();
     $result = json_decode($result);
     $id = $result->category_id;
     $this->assertNotNull($id);
     // List again
     $response = $client->get('/modules/api/category/', array('headers' => TestEnvironment::headers()));
     $this->assertEquals('200', $response->getStatusCode());
     $result = $response->getBody();
     $result = json_decode($result);
     $count1 = count($result);
     $this->assertEquals($count0 + 1, $count1);
     // Get by id
     $response = $client->get('/modules/api/category/' . $id, array('headers' => TestEnvironment::headers()));
     $this->assertEquals('200', $response->getStatusCode());
     $result = $response->getBody();
     $result = json_decode($result);
     $this->assertEquals($id, $result->category_id);
     // Write back
     $response = $client->put('/modules/api/category/' . $id, array('headers' => TestEnvironment::headers(), 'body' => array('description' => 'other description', 'tax_type_id' => '1', 'units' => 'month', 'mb_flag' => 'D', 'sales_account' => '4010', 'cogs_account' => '5010', 'adjustment_account' => '5040', 'assembly_account' => '1530', 'inventory_account' => '1510')));
     $this->assertEquals('200', $response->getStatusCode());
     $result = $response->getBody();
     $result = json_decode($result);
     // List again
     $response = $client->get('/modules/api/category/', array('headers' => TestEnvironment::headers()));
     $this->assertEquals('200', $response->getStatusCode());
     $result = $response->getBody();
     $result = json_decode($result);
     $count1 = count($result);
     $this->assertEquals($count0 + 1, $count1);
     $this->assertEquals($id, $result[$count1 - 1]->category_id);
     $this->assertEquals('other description', $result[$count1 - 1]->description);
     // Delete
     $response = $client->delete('/modules/api/category/' . $id, array('headers' => TestEnvironment::headers()));
     $this->assertEquals('200', $response->getStatusCode());
     $result = $response->getBody();
     $result = json_decode($result);
     // List again
     $response = $client->get('/modules/api/category/', array('headers' => TestEnvironment::headers()));
     $this->assertEquals('200', $response->getStatusCode());
     $result = $response->getBody();
     $result = json_decode($result);
     $count2 = count($result);
     $this->assertEquals($count0, $count2);
 }
 public function testTaxGroups_Ok()
 {
     $client = TestEnvironment::client();
     // List
     $response = $client->get('/modules/api/taxgroups/', array('headers' => TestEnvironment::headers()));
     $this->assertEquals('200', $response->getStatusCode());
     $result = $response->getBody();
     $result = json_decode($result);
     $this->assertEquals(2, count($result));
     $expected = new stdClass();
     $expected->id = 1;
     $expected->name = 'Tax';
     $expected->tax_shipping = 0;
     $this->assertEquals($expected, $result[0]);
 }
示例#7
0
 function testInstallation()
 {
     #saveOriginalConfiguration();
     TestEnvironment::prepare('fixtures/project_setup.sql');
     $this->addHeader('USER_AGENT: streber_unit_tester');
     #
     #$g_streber_url= "http://localhost/streber_head";
     #
     #### logout first ###
     #$this->assertTrue($this->get("$g_streber_url/index.php?go=logout"), 'getting logout-page (%s)' );
     #
     #### test license ###
     #$this->assertTrue($this->clickLink('License'),                                          'click at license');
     #$this->assertTrue( $this->setField('login_name', 'admin'));
     #$this->assertTrue( $this->setField('login_password', 'wrong') );
     #$this->assertTrue( $this->clickSubmit('Submit'));
     #$this->assertWantedPattern('/invalid login/i',                                            'check content (%s)');
     #
     #### submit -> login to home ###
     #$this->assertNoUnwantedPattern('/<b>Warning<\/b>:|<b>Error<\/b>:|<b>Notice<\/b>:/i',    'php-error found (%s)' );
 }
 public function executeImportRestApi(sfWebRequest $request)
 {
     $qa_generic = sfConfig::get("app_table_qa_generic");
     $qa_core = sfConfig::get("app_table_qa_core");
     // Retrieve $_GET (main parameters)
     $get_params['auth_token'] = $request->getGetParameter("auth_token");
     $get_params['release_version'] = $request->getGetParameter("release_version");
     $get_params['target'] = $request->getGetParameter("target");
     $get_params['testtype'] = $request->getGetParameter("testtype");
     $get_params['testset'] = $request->getGetParameter("testset");
     $get_params['hwproduct'] = $request->getGetParameter("hwproduct");
     $get_params['product'] = $request->getGetParameter("product");
     $get_params['hardware'] = $request->getGetParameter("hardware");
     $get_params['image'] = $request->getGetParameter("image");
     $get_params['build_id'] = $request->getGetParameter("build_id");
     // Retrieve $_GET (additional parameters)
     $get_params['tested_at'] = $request->getGetParameter("tested_at");
     $get_params['report_title'] = $request->getGetParameter("title");
     $get_params['objective_txt'] = $request->getGetParameter("objective_txt");
     $get_params['build_txt'] = $request->getGetParameter("build_txt");
     $get_params['environment_txt'] = $request->getGetParameter("environment_txt");
     $get_params['qa_summary_txt'] = $request->getGetParameter("qa_summary_txt");
     $get_params['issue_summary_txt'] = $request->getGetParameter("issue_summary_txt");
     $get_params['status'] = $request->getGetParameter("status");
     // Retrieve $_GET (hwproduct additional fields)
     $get_params['te_desc'] = $request->getGetParameter("te_desc");
     $get_params['te_cpu'] = $request->getGetParameter("te_cpu");
     $get_params['te_board'] = $request->getGetParameter("te_board");
     $get_params['te_gpu'] = $request->getGetParameter("te_gpu");
     $get_params['te_hw'] = $request->getGetParameter("te_hw");
     // Retrieve $_GET (image additional fields)
     $get_params['img_desc'] = $request->getGetParameter("img_desc");
     $get_params['img_os'] = $request->getGetParameter("img_os");
     $get_params['img_dist'] = $request->getGetParameter("img_dist");
     $get_params['img_vers'] = $request->getGetParameter("img_vers");
     $get_params['img_kernel'] = $request->getGetParameter("img_kernel");
     $get_params['img_arch'] = $request->getGetParameter("img_arch");
     $get_params['img_other'] = $request->getGetParameter("img_other");
     $get_params['img_bin'] = $request->getGetParameter("img_bin");
     $get_params['img_src'] = $request->getGetParameter("img_src");
     // Old parameters support about test_environment (testtype)
     if (!isset($get_params['testtype'])) {
         $get_params['testtype'] = $get_params['testset'];
     }
     // Old parameters support about image (hwproduct)
     if (!isset($get_params['hwproduct'])) {
         if (!isset($get_params['product'])) {
             $get_params['hwproduct'] = $get_params['hardware'];
         } else {
             $get_params['hwproduct'] = $get_params['product'];
         }
     }
     // Check if auth_token parameter is empty
     if (empty($get_params['auth_token'])) {
         echo "{\"ok\":\"0\",\"errors\":{\"Parameters error\":\"Missing auth_token parameter\"}}\n";
         exit;
     }
     // Check if release_version parameter is empty
     if (empty($get_params['release_version'])) {
         echo "{\"ok\":\"0\",\"errors\":{\"Parameters error\":\"Missing release_version parameter\"}}\n";
         exit;
     }
     // Check if target parameter is empty
     if (empty($get_params['target'])) {
         echo "{\"ok\":\"0\",\"errors\":{\"Parameters error\":\"Missing target parameter\"}}\n";
         exit;
     }
     // Check if hwproduct parameter is empty
     if (empty($get_params['hwproduct'])) {
         echo "{\"ok\":\"0\",\"errors\":{\"Parameters error\":\"Missing hwproduct parameter\"}}\n";
         exit;
     }
     // Check if image parameter is empty
     if (empty($get_params['image'])) {
         $get_params['image'] = "Empty_image";
     }
     // Retrieve project_id relying on project name (if it doesn't exist, return an error)
     $query = "SELECT proj.id AS project_id\n\t\t\t\t\tFROM " . $qa_generic . ".project proj\n\t\t\t\t\tWHERE proj.name = '" . $get_params['release_version'] . "'";
     $result = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetch(PDO::FETCH_ASSOC);
     if (empty($result["project_id"])) {
         echo "{\"ok\":\"0\",\"errors\":{\"release_version\":\"Incorrect release_version '" . $get_params['release_version'] . "'\"}}\n";
         exit;
     }
     $project_id = $result["project_id"];
     // Retrieve project_group_id relying on project_group_name (if it doesn't exist, return an error)
     $query = "SELECT pg.id AS project_group_id\n\t\t\t\t\tFROM " . $qa_core . ".sf_guard_group pg\n\t\t\t\t\tWHERE pg.name = '" . sfConfig::get("app_project_group") . "'";
     $result = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetch(PDO::FETCH_ASSOC);
     if (empty($result["project_group_id"])) {
         echo "{\"ok\":\"0\",\"errors\":{\"project_group_name\":\"Incorrect project_group_name '" . sfConfig::get("app_project_group") . "'\"}}\n";
         exit;
     }
     $project_group_id = $result["project_group_id"];
     // Retrieve product_id relying on product formfactor (if it doesn't exist, return an error)
     $query = "SELECT pt.id AS product_id\n\t\t\t\t\tFROM " . $qa_core . ".product_type pt\n\t\t\t\t\tWHERE pt.name = '" . $get_params['target'] . "'";
     $result = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetch(PDO::FETCH_ASSOC);
     if (empty($result["product_id"])) {
         echo "{\"ok\":\"0\",\"errors\":{\"target\":\"Incorrect target '" . $get_params['target'] . "'\"}}\n";
         exit;
     }
     $product_id = $result["product_id"];
     // Retrieve project_to_product_id, relying on project_id, project_group_id, and product_id
     $query = "SELECT ptp.id AS ptp_id\n\t\t\t\t\tFROM " . $qa_generic . ".project_to_product ptp\n\t\t\t\t\tWHERE ptp.project_id = " . $project_id . "\n\t\t\t\t\t\tAND ptp.project_group_id = " . $project_group_id . "\n\t\t\t\t\t\tAND ptp.product_id = " . $product_id;
     $result = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetch(PDO::FETCH_ASSOC);
     if (empty($result["ptp_id"])) {
         echo "{\"ok\":\"0\",\"errors\":{\"project_to_product\":\"Cannot find project_to_product_id\"}}\n";
         exit;
     }
     $project_to_product_id = $result["ptp_id"];
     // Retrieve user_id, relying on auth_token
     $query = "SELECT up.user_id\n\t\t\t\t\tFROM " . $qa_core . ".sf_guard_user_profile up\n\t\t\t\t\tWHERE up.token = '" . $get_params['auth_token'] . "'";
     $result = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetch(PDO::FETCH_ASSOC);
     if (empty($result["user_id"])) {
         echo "{\"ok\":\"0\",\"errors\":{\"auth_token\":\"Authorized token is not valid\"}}\n";
         exit;
     }
     $user_id = $result["user_id"];
     // Customize database connection to begin a transactionnal query
     $conn = Doctrine_Manager::getInstance()->getConnection("qa_generic");
     $conn->setAttribute(Doctrine_Core::ATTR_AUTOCOMMIT, FALSE);
     $conn->beginTransaction();
     // If test_environment_name exists, retrieve id, else, create new entry and retrieve id
     $query = "SELECT te.id AS test_environment_id\n\t\t\t\t\tFROM " . $qa_generic . ".test_environment te\n\t\t\t\t\tWHERE te.name = '" . $get_params['hwproduct'] . "'";
     $result = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetch(PDO::FETCH_ASSOC);
     if (empty($result["test_environment_id"])) {
         // Check if creation of a new entry is allowed
         if (sfConfig::get("app_rest_configuration_creation", false) == false) {
             $conn->rollback();
             $conn->setAttribute(Doctrine_Core::ATTR_AUTOCOMMIT, TRUE);
             echo "{\"ok\":\"0\",\"errors\":{\"test_environment\":\"Creation of new test environment is forbidden\"}}\n";
             exit;
         } else {
             // Add new environment
             $environment = new TestEnvironment();
             $environment->setName($get_params['hwproduct']);
             $environment->setNameSlug(MiscUtils::slugify($get_params['hwproduct']));
             // Add hwproduct additional fields if given as parameters
             if (isset($get_params['te_desc'])) {
                 $environment->setDescription($get_params['te_desc']);
             }
             if (isset($get_params['te_cpu'])) {
                 $environment->setCpu($get_params['te_cpu']);
             }
             if (isset($get_params['te_board'])) {
                 $environment->setBoard($get_params['te_board']);
             }
             if (isset($get_params['te_gpu'])) {
                 $environment->setGpu($get_params['te_gpu']);
             }
             if (isset($get_params['te_hw'])) {
                 $environment->setOtherHardware($get_params['te_hw']);
             }
             // Save new environment
             $environment->save($conn);
             $environmentId = $environment->getId();
         }
     } else {
         $environmentId = $result["test_environment_id"];
     }
     // If image_name exists, retrieve id, else, create new entry and retrieve id
     $query = "SELECT i.id AS image_id\n\t\t\t\t\tFROM " . $qa_generic . ".image i\n\t\t\t\t\tWHERE i.name = '" . $get_params['image'] . "'";
     $result = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetch(PDO::FETCH_ASSOC);
     if (empty($result["image_id"])) {
         // Check if creation of a new entry is allowed
         if (sfConfig::get("app_rest_configuration_creation", false) == false) {
             $conn->rollback();
             $conn->setAttribute(Doctrine_Core::ATTR_AUTOCOMMIT, TRUE);
             echo "{\"ok\":\"0\",\"errors\":{\"image\":\"Creation of new image is forbidden\"}}\n";
             exit;
         } else {
             // Add new image
             $image = new Image();
             $image->setName($get_params['image']);
             $image->setNameSlug(MiscUtils::slugify($get_params['image']));
             // Add image additional fields if given as parameters
             if (isset($get_params['img_desc'])) {
                 $image->setDescription($get_params['img_desc']);
             }
             if (isset($get_params['img_os'])) {
                 $image->setOs($get_params['img_os']);
             }
             if (isset($get_params['img_dist'])) {
                 $image->setDistribution($get_params['img_dist']);
             }
             if (isset($get_params['img_vers'])) {
                 $image->setVersion($get_params['img_vers']);
             }
             if (isset($get_params['img_kernel'])) {
                 $image->setKernel($get_params['img_kernel']);
             }
             if (isset($get_params['img_arch'])) {
                 $image->setArchitecture($get_params['img_arch']);
             }
             if (isset($get_params['img_other'])) {
                 $image->setOtherFw($get_params['img_other']);
             }
             if (isset($get_params['img_bin'])) {
                 $image->setBinaryLink($get_params['img_bin']);
             }
             if (isset($get_params['img_src'])) {
                 $image->setSourceLink($get_params['img_src']);
             }
             // Save new image
             $image->save($conn);
             $imageId = $image->getId();
         }
     } else {
         $imageId = $result["image_id"];
     }
     // If configuration exists, retrieve id, else, create new entry and retrieve id
     $query = "SELECT c.id AS configuration_id\n\t\t\t\t\tFROM " . $qa_generic . ".configuration c\n\t\t\t\t\tWHERE c.project_to_product_id = " . $project_to_product_id . "\n\t\t\t\t\t\tAND c.test_environment_id = " . $environmentId . "\n\t\t\t\t\t\tAND c.image_id = " . $imageId;
     $result = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetch(PDO::FETCH_ASSOC);
     if (empty($result["configuration_id"])) {
         $configuration = new Configuration();
         $configuration->setProjectToProductId($project_to_product_id);
         $configuration->setTestEnvironmentId($environmentId);
         $configuration->setImageId($imageId);
         $configuration->save($conn);
         $configurationId = $configuration->getId();
     } else {
         $configurationId = $result["configuration_id"];
     }
     $date_now = date("Y-m-d H:i:s");
     $date_now_wo_sec = date("Y-m-d H:i");
     $testSession = new TestSession();
     $testSession->setName($get_params['target'] . " " . $get_params['testtype'] . " " . $get_params['hwproduct'] . " " . $date_now_wo_sec . " " . $get_params['build_id']);
     $testSession->setUserId($user_id);
     $testSession->setCreatedAt($date_now);
     $testSession->setUpdatedAt($date_now);
     $testSession->setStatus(2);
     $testSession->setPublished(1);
     $testSession->setConfigurationId($configurationId);
     // Fill in the build_id if it is given
     if (!empty($get_params['build_id'])) {
         $testSession->setBuildId($get_params['build_id']);
         $testSession->setBuildSlug(MiscUtils::slugify($get_params['build_id']));
     }
     // Fill in the testset if it is given
     if (!empty($get_params['testtype'])) {
         $testSession->setTestset($get_params['testtype']);
         $testSession->setTestsetSlug(MiscUtils::slugify($get_params['testtype']));
     }
     if (isset($get_params['report_title'])) {
         $testSession->setName($get_params['report_title']);
     }
     if (isset($get_params['objective_txt'])) {
         $testSession->setTestObjective($get_params['objective_txt']);
     }
     if (isset($get_params['environment_txt'])) {
         $testSession->setNotes($get_params['environment_txt']);
     }
     if (isset($get_params['qa_summary_txt'])) {
         $testSession->setQaSummary($get_params['qa_summary_txt']);
     }
     if (isset($get_params['issue_summary_txt'])) {
         $testSession->setIssueSummary($get_params['issue_summary_txt']);
     }
     if (isset($get_params['status'])) {
         $testSession->setStatus($get_params['status']);
     }
     $testSession->save($conn);
     $testSessionId = $testSession->getId();
     // Retrieve table_name_test_session_id from table_name
     $query = "SELECT tn.id AS table_name_id\n\t\t\t\t\tFROM " . $qa_generic . ".table_name tn\n\t\t\t\t\tWHERE tn.name = 'test_session'";
     $result = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetch(PDO::FETCH_ASSOC);
     $tableNameTestSessionId = $result["table_name_id"];
     // Concatenate directory path
     $dir_path = sfConfig::get('sf_upload_dir') . "/testsession_" . $testSessionId;
     // Get all files sent
     $files = $request->getFiles();
     // Check if there is any report file to import
     if (empty($files)) {
         $conn->rollback();
         $conn->setAttribute(Doctrine_Core::ATTR_AUTOCOMMIT, TRUE);
         echo "{\"ok\":\"0\",\"errors\":\"Missing report file\"}\n";
         exit;
     }
     // Import each report file and register attachment files
     $report_file_found = false;
     foreach ($files as $key => $file) {
         $reportType = false;
         $fileName = $file['name'];
         $fileSize = $file['size'];
         $fileType = $file['type'];
         $fileError = $file['error'];
         $fileChecksum = sha1_file($file["tmp_name"]);
         // Check file error and file size
         if (!$fileError and $fileSize <= sfConfig::get('app_max_file_size', '10000000')) {
             if (!is_dir($dir_path)) {
                 mkdir($dir_path, 0777, true);
             }
             $dest_path = $dir_path . "/" . $fileName;
             // Move file to uploads directory
             move_uploaded_file($file['tmp_name'], $dest_path);
             $web_path = "/uploads" . "/testsession_" . $testSessionId . "/" . $fileName;
             $fileAttachment = new FileAttachment();
             $fileAttachment->setName($fileName);
             $fileAttachment->setUserId($user_id);
             $fileAttachment->setUploadedAt(date("Y-m-d H:i:s"));
             $fileAttachment->setFilename($fileName);
             $fileAttachment->setFileSize($fileSize);
             $fileAttachment->setFileMimeType($fileType);
             $fileAttachment->setLink($web_path);
             $fileAttachment->setChecksum($fileChecksum);
             $fileAttachment->setTableNameId($tableNameTestSessionId);
             $fileAttachment->setTableEntryId($testSessionId);
             if ((preg_match("#\\.xml\$#i", $fileName) | preg_match("#\\.csv\$#i", $fileName)) & !preg_match("#attachment.?[0-9]*#i", $key)) {
                 $report_file_found = true;
                 $reportType = true;
                 $fileAttachment->setCategory(1);
             } else {
                 if (preg_match("#attachment.?[0-9]*#i", $key)) {
                     $fileAttachment->setCategory(2);
                 } else {
                     $conn->rollback();
                     $conn->setAttribute(Doctrine_Core::ATTR_AUTOCOMMIT, TRUE);
                     echo "{\"ok\":\"0\",\"errors\":\"Only upload files with the extension .xml or .csv\"}\n";
                     exit;
                 }
             }
             $fileAttachment->save($conn);
             // If it is an XML or CSV file, parse it and fill qa_generic database
             if ($reportType) {
                 if ($err_code = Import::file($dest_path, $testSessionId, $configurationId, $conn)) {
                     $error_message = Import::getImportErrorMessage($err_code);
                     MiscUtils::deleteDir($dir_path);
                     $conn->rollback();
                     $conn->setAttribute(Doctrine_Core::ATTR_AUTOCOMMIT, TRUE);
                     echo "{\"ok\":\"0\",\"errors\":\"File " . $fileName . " is not valid = " . $error_message . "\"}\n";
                     exit;
                 }
             }
         } else {
             MiscUtils::deleteDir($dir_path);
             $conn->rollback();
             $conn->setAttribute(Doctrine_Core::ATTR_AUTOCOMMIT, TRUE);
             echo "{\"ok\":\"0\",\"errors\":\"File " . $fileName . " exceed maximum size\"}\n";
             exit;
         }
     }
     // If only attachment files have been found, cancel the new test session
     if (!$report_file_found) {
         $conn->rollback();
         $conn->setAttribute(Doctrine_Core::ATTR_AUTOCOMMIT, TRUE);
         echo "{\"ok\":\"0\",\"errors\":\"Missing report file\"}\n";
         exit;
     }
     $conn->commit();
     $conn->setAttribute(Doctrine_Core::ATTR_AUTOCOMMIT, TRUE);
     // Retrieve project name_slug, product name_slug, test environment name_slug and image name_slug
     $query = "SELECT i.name_slug image_name_slug, te.name_slug test_environment_name_slug, p.name_slug project_name_slug, pt.name_slug product_name_slug\n\t\t\t\t\tFROM " . $qa_generic . ".test_session ts\n\t\t\t\t\tJOIN " . $qa_generic . ".configuration c ON c.id = ts.configuration_id\n\t\t\t\t\tJOIN " . $qa_generic . ".image i ON i.id = c.image_id\n\t\t\t\t\tJOIN " . $qa_generic . ".test_environment te ON te.id = c.test_environment_id\n\t\t\t\t\tJOIN " . $qa_generic . ".project_to_product ptp ON ptp.id = c.project_to_product_id\n\t\t\t\t\tJOIN " . $qa_generic . ".project p ON p.id = ptp.project_id\n\t\t\t\t\tJOIN " . $qa_core . ".product_type pt ON pt.id = ptp.product_id\n\t\t\t\t\tWHERE ts.id = " . $testSessionId;
     $configInfo = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetch(PDO::FETCH_ASSOC);
     $projectNameSlug = $configInfo['project_name_slug'];
     $productNameSlug = $configInfo['product_name_slug'];
     $testEnvironmentNameSlug = $configInfo['test_environment_name_slug'];
     $imageNameSlug = $configInfo['image_name_slug'];
     // Return datas to CATS
     $url_to_return = $request->getUriPrefix() . $this->generateUrl("test_session", array('project' => $projectNameSlug, 'product' => $productNameSlug, 'environment' => $testEnvironmentNameSlug, 'image' => $imageNameSlug, 'id' => $testSessionId));
     echo "{\"ok\":\"1\",\"url\":\"" . $url_to_return . "\"}\n";
     // Return is done (with echo) so make sure nothing else will be sent
     exit;
 }
 /**
  * Process the form to edit an existing test session.
  *
  * @param sfWebRequest $request
  * @param SessionForm $form
  */
 protected function processEdit(sfWebRequest $request, SessionForm $form)
 {
     $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
     if ($form->isValid()) {
         $qa_generic = sfConfig::get("app_table_qa_generic");
         // Get sent values and uploaded files
         $values = $form->getValues();
         $files = $request->getFiles();
         // Retrieve values from form
         $projectGroupId = $values["project_group_id"];
         $projectId = $values["project"];
         $productId = $values["product"];
         // Get test environment and image names
         $environmentForm = $form->getValue("environmentForm");
         $imageForm = $form->getValue("imageForm");
         // Create a new relationship between project group, project and product if needed
         $projectToProductId = Doctrine_Core::getTable("ProjectToProduct")->getProjectToProductId($projectGroupId, $projectId, $productId);
         if ($projectToProductId == null) {
             $projectToProduct = new ProjectToProduct();
             $projectToProduct->setProjectGroupId($projectGroupId);
             $projectToProduct->setProjectId($projectId);
             $projectToProduct->setProductId($productId);
             $projectToProduct->save($conn);
             $projectToProductId = $projectToProduct->getId();
         }
         // Create a new environment if needed
         $environment = Doctrine_Core::getTable("TestEnvironment")->findByArray($environmentForm);
         if ($environment == null) {
             // Add new environment
             $environment = new TestEnvironment();
             $environment->setName($environmentForm["name"]);
             $environment->setDescription($environmentForm["description"]);
             $environment->setCpu($environmentForm["cpu"]);
             $environment->setBoard($environmentForm["board"]);
             $environment->setGpu($environmentForm["gpu"]);
             $environment->setOtherHardware($environmentForm["other_hardware"]);
             // Check if its slug does not already exist and generate a new one if needed
             $slug = MiscUtils::slugify($environmentForm["name"]);
             $size = 1;
             while (Doctrine_Core::getTable("TestEnvironment")->checkSlug($slug)) {
                 $slug = MiscUtils::slugify($environmentForm["name"]) . substr(microtime(), -$size);
                 $size++;
             }
             $environment->setNameSlug($slug);
             $environment->save($conn);
             // Convert object into associative array
             $environment = $environment->toArray();
         }
         // Create a new image if needed
         $image = Doctrine_Core::getTable("Image")->findByArray($imageForm);
         if ($image == null) {
             // Add new image
             $image = new Image();
             $image->setName($imageForm["name"]);
             $image->setDescription($imageForm["description"]);
             $image->setOs($imageForm["os"]);
             $image->setDistribution($imageForm["distribution"]);
             $image->setVersion($imageForm["version"]);
             $image->setKernel($imageForm["kernel"]);
             $image->setArchitecture($imageForm["architecture"]);
             $image->setOtherFw($imageForm["other_fw"]);
             $image->setBinaryLink($imageForm["binary_link"]);
             $image->setSourceLink($imageForm["source_link"]);
             // Check if its slug does not already exist and generate a new one if needed
             $slug = MiscUtils::slugify($imageForm["name"]);
             $size = 1;
             while (Doctrine_Core::getTable("Image")->checkSlug($slug)) {
                 $slug = MiscUtils::slugify($imageForm["name"]) . substr(microtime(), -$size);
                 $size++;
             }
             $image->setNameSlug(MiscUtils::slugify($slug));
             $image->save($conn);
             // Convert object into associative array
             $image = $image->toArray();
         }
         // Create a new configuration relationship if needed
         $configurationId = Doctrine_Core::getTable("Configuration")->getConfigurationId($projectToProductId, $environment["id"], $image["id"]);
         if ($configurationId == null) {
             $configuration = new Configuration();
             $configuration->setProjectToProductId($projectToProductId);
             $configuration->setTestEnvironmentId($environment["id"]);
             $configuration->setImageId($image["id"]);
             $configuration->save($conn);
             $configurationId = $configuration->getId();
         }
         // Edit the session into DB
         $testSession = Doctrine_Core::getTable("TestSession")->find($values["id"]);
         $testSession->setId($values["id"]);
         $testSession->setBuildId($values["build_id"]);
         $testSession->setTestset($values["testset"]);
         $testSession->setName($values["name"]);
         $testSession->setTestObjective($values["test_objective"]);
         $testSession->setQaSummary($values["qa_summary"]);
         $testSession->setUserId($values["user_id"]);
         $testSession->setCreatedAt($values["created_at"]);
         $testSession->setEditorId($values["editor_id"]);
         $testSession->setUpdatedAt($values["updated_at"]);
         $testSession->setProjectRelease($values["project_release"]);
         $testSession->setProjectMilestone($values["project_milestone"]);
         $testSession->setIssueSummary($values["issue_summary"]);
         $testSession->setStatus($values["status"]);
         $testSession->setPublished($values["published"]);
         $testSession->setConfigurationId(intval($configurationId));
         $testSession->setCampaignChecksum($values["campaign_checksum"]);
         $testSession->setBuildSlug(MiscUtils::slugify($values["build_id"]));
         $testSession->setTestsetSlug(MiscUtils::slugify($values["testset"]));
         $testSession->setNotes($values["notes"]);
         $testSession->save();
         $testSessionId = $values["id"];
         // Get all results (and add associative key for each result)
         $array = array();
         foreach (Doctrine_Core::getTable("TestSession")->getSessionResults($this->currentSession["id"]) as $key => $value) {
             $array[MiscUtils::slugify($value["label"]) . $value["id"]] = $value;
         }
         $results = $array;
         // Get all measures (and add associative key for each measure)
         $array = array();
         foreach (Doctrine_Core::getTable("TestSession")->getSessionMeasures($this->currentSession["id"]) as $key => $value) {
             $array[MiscUtils::slugify($value["label"]) . $value["id"]] = $value;
         }
         $measures = $array;
         // Save test results
         foreach ($results as $key => $result) {
             if (array_key_exists($key, $values)) {
                 $resultForm = Doctrine_Core::getTable("TestResult")->find($result["id"]);
                 $resultForm->setId($result["id"]);
                 $resultForm->setDecisionCriteriaId($values[$key]["decision_criteria_id"]);
                 $resultForm->setComment($values[$key]["comment"]);
                 $resultForm->save();
             }
         }
         // Save measures
         foreach ($measures as $key => $measure) {
             if (array_key_exists($key, $values)) {
                 $resultForm = Doctrine_Core::getTable("TestResult")->find($measure["id"]);
                 $resultForm->setId($measure["id"]);
                 $resultForm->setDecisionCriteriaId($values[$key]["decision_criteria_id"]);
                 $resultForm->setComment($values[$key]["comment"]);
                 $resultForm->save();
             }
         }
         // Get project and product name slug
         $projectSlug = Doctrine_Core::getTable("Project")->getSlugById($projectId);
         $productSlug = Doctrine_Core::getTable("ProductType")->getSlugById($productId);
         // Retrieve table_name_test_session_id from table_name
         $tableName = Doctrine_Core::getTable("TableName")->findOneByName("test_session");
         $tableNameTestSessionId = $tableName->getId();
         // Import attachments and result files
         foreach ($files["attachments"] as $key => $file) {
             if ($file["error"] != UPLOAD_ERR_NO_FILE) {
                 $fileName = $file['name'];
                 $fileSize = $file['size'];
                 $fileType = $file['type'];
                 $fileError = $file['error'];
                 $fileChecksum = sha1_file($file["tmp_name"]);
                 // Check file error and file size (5Mo max)
                 if (!$fileError and $fileSize <= 5000000) {
                     // Concatenate destination path
                     $dest_path = sfConfig::get('sf_upload_dir') . "/testsession_" . $testSessionId;
                     if (!is_dir($dest_path)) {
                         mkdir($dest_path, 0777, true);
                     }
                     $dest_path .= "/" . $fileName;
                     // Move file to uploads directory
                     move_uploaded_file($file['tmp_name'], $dest_path);
                     $web_path = "/uploads" . "/testsession_" . $testSessionId . "/" . $fileName;
                     $fileAttachment = new FileAttachment();
                     $fileAttachment->setName($fileName);
                     $fileAttachment->setUserId($this->getUser()->getGuardUser()->getId());
                     $fileAttachment->setUploadedAt(date("Y-m-d H:i:s"));
                     $fileAttachment->setFilename($fileName);
                     $fileAttachment->setFileSize($fileSize);
                     $fileAttachment->setFileMimeType($fileType);
                     $fileAttachment->setLink($web_path);
                     $fileAttachment->setChecksum($fileChecksum);
                     $fileAttachment->setTableNameId($tableNameTestSessionId);
                     $fileAttachment->setTableEntryId($testSessionId);
                     $fileAttachment->setCategory(2);
                     $fileAttachment->save();
                 }
             }
         }
         // Customize database connection to begin a transactionnal query
         $conn = Doctrine_Manager::getInstance()->getConnection("qa_generic");
         $conn->setAttribute(Doctrine_Core::ATTR_AUTOCOMMIT, FALSE);
         $conn->beginTransaction();
         // Get file attachments id into an array
         $fileAttachmentIdList = array();
         $query = "SELECT fa.id\n\t\t\t\t\tFROM " . $qa_generic . ".file_attachment fa\n\t\t\t\t\tWHERE fa.table_entry_id = " . $testSessionId . "\n\t\t\t\t\t\tAND fa.table_name_id = " . $tableNameTestSessionId;
         $results = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetchAll(PDO::FETCH_ASSOC);
         foreach ($results as $result) {
             $fileAttachmentIdList[] = $result["id"];
         }
         $fileAttachmentIdStringList = implode(",", $fileAttachmentIdList);
         // Concatenate directory path
         $dir_path = sfConfig::get('sf_upload_dir') . "/testsession_" . $testSessionId;
         $fileAttachmentResultIds = array();
         $similarFileFound = false;
         foreach ($files["result_files"] as $key => $file) {
             if ($file["error"] != UPLOAD_ERR_NO_FILE) {
                 $reportType = false;
                 $fileName = $file['name'];
                 $fileSize = $file['size'];
                 $fileType = $file['type'];
                 $fileError = $file['error'];
                 $fileChecksum = sha1_file($file["tmp_name"]);
                 $query = "SELECT fa.id\n\t\t\t\t\t\t\tFROM " . $qa_generic . ".file_attachment fa\n\t\t\t\t\t\t\tWHERE fa.table_entry_id = " . $testSessionId . "\n\t\t\t\t\t\t\t\tAND fa.table_name_id = " . $tableNameTestSessionId . "\n\t\t\t\t\t\t\t\tAND fa.checksum = '" . $fileChecksum . "'";
                 $result = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetch(PDO::FETCH_ASSOC);
                 if (!empty($result["id"])) {
                     $fileAttachmentResultIds[] = $result["id"];
                     $similarFileFound = true;
                 }
                 // Check file error and file size
                 if (!$fileError and $fileSize <= sfConfig::get('app_max_file_size', '10000000')) {
                     if (!is_dir($dir_path)) {
                         mkdir($dir_path, 0777, true);
                     }
                     $dest_path = $dir_path . "/" . $fileName;
                     $idx = 0;
                     while (is_file($dest_path)) {
                         $idx++;
                         $dest_path = $dir_path . "/" . "(" . $idx . ")" . $fileName;
                     }
                     // Move file to uploads directory
                     move_uploaded_file($file['tmp_name'], $dest_path);
                     if ($idx == 0) {
                         $web_path = "/uploads" . "/testsession_" . $testSessionId . "/" . $fileName;
                     } else {
                         $web_path = "/uploads" . "/testsession_" . $testSessionId . "/" . "(" . $idx . ")" . $fileName;
                     }
                     $fileAttachment = new FileAttachment();
                     $fileAttachment->setName($fileName);
                     $fileAttachment->setUserId($this->getUser()->getGuardUser()->getId());
                     $fileAttachment->setUploadedAt(date("Y-m-d H:i:s"));
                     $fileAttachment->setFilename($fileName);
                     $fileAttachment->setFileSize($fileSize);
                     $fileAttachment->setFileMimeType($fileType);
                     $fileAttachment->setLink($web_path);
                     $fileAttachment->setChecksum($fileChecksum);
                     $fileAttachment->setTableNameId($tableNameTestSessionId);
                     $fileAttachment->setTableEntryId($testSessionId);
                     if (preg_match("#\\.xml\$#i", $fileName) | preg_match("#\\.csv\$#i", $fileName)) {
                         $reportType = true;
                         $fileAttachment->setCategory(1);
                     } else {
                         $fileAttachment->setCategory(2);
                     }
                     $fileAttachment->save($conn);
                     // If it is an XML or CSV file, parse it and fill qa_generic database
                     if ($reportType) {
                         if ($err_code = Import::file($dest_path, $testSessionId, $configurationId, $conn, true)) {
                             // Delete new files
                             $query = "SELECT fa.link\n\t\t\t\t\t\t\t\t\t\tFROM " . $qa_generic . ".file_attachment fa\n\t\t\t\t\t\t\t\t\t\tWHERE fa.table_entry_id = " . $testSessionId . "\n\t\t\t\t\t\t\t\t\t\t\tAND fa.table_name_id = " . $tableNameTestSessionId . "\n\t\t\t\t\t\t\t\t\t\t\tAND fa.id NOT IN (" . $fileAttachmentIdStringList . ")";
                             $results = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetchAll(PDO::FETCH_ASSOC);
                             foreach ($results as $result) {
                                 unlink(sfConfig::get('sf_web_dir') . $result["link"]);
                             }
                             $error_message = Import::getImportErrorMessage($err_code);
                             $conn->rollback();
                             $conn->setAttribute(Doctrine_Core::ATTR_AUTOCOMMIT, TRUE);
                             $this->getUser()->setFlash("error", "Invalid file content on " . $fileName . " : " . $error_message);
                             $this->redirect("edit_report", array("project" => $projectSlug, "product" => $productSlug, "environment" => $environment["name_slug"], "image" => $image["name_slug"], "id" => $testSessionId));
                         }
                     }
                 } else {
                     // Delete new files
                     $query = "SELECT fa.link\n\t\t\t\t\t\t\t\tFROM " . $qa_generic . ".file_attachment fa\n\t\t\t\t\t\t\t\tWHERE fa.table_entry_id = " . $testSessionId . "\n\t\t\t\t\t\t\t\t\tAND fa.table_name_id = " . $tableNameTestSessionId . "\n\t\t\t\t\t\t\t\t\tAND fa.id NOT IN (" . $fileAttachmentIdStringList . ")";
                     $results = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetchAll(PDO::FETCH_ASSOC);
                     foreach ($results as $result) {
                         unlink(sfConfig::get('sf_web_dir') . $result["link"]);
                     }
                     $conn->rollback();
                     $conn->setAttribute(Doctrine_Core::ATTR_AUTOCOMMIT, TRUE);
                     $this->getUser()->setFlash("error", "File size limit reached");
                     $this->redirect("edit_report", array("project" => $projectSlug, "product" => $productSlug, "environment" => $environment["name_slug"], "image" => $image["name_slug"], "id" => $testSessionId));
                 }
             }
         }
         if ($similarFileFound) {
             $fileAttachmentStringResultIds = implode(",", $fileAttachmentResultIds);
             // Delete similar files and attachment entries
             $query = "SELECT fa.id, fa.link\n\t\t\t\t\t\tFROM " . $qa_generic . ".file_attachment fa\n\t\t\t\t\t\tWHERE fa.table_entry_id = " . $testSessionId . "\n\t\t\t\t\t\t\tAND fa.table_name_id = " . $tableNameTestSessionId . "\n\t\t\t\t\t\t\tAND fa.id IN (" . $fileAttachmentStringResultIds . ")";
             $results = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetchAll(PDO::FETCH_ASSOC);
             foreach ($results as $result) {
                 unlink(sfConfig::get('sf_web_dir') . $result["link"]);
                 Doctrine_Core::getTable("FileAttachment")->deleteFileAttachmentById($result["id"], $conn);
             }
         }
         $conn->commit();
         $conn->setAttribute(Doctrine_Core::ATTR_AUTOCOMMIT, TRUE);
         // 			// Clear cache for actions related to this test session
         // 			$cacheManager = $this->getContext()->getViewCacheManager();
         // 			$cacheManager->remove("reports/session?project=".$projectSlug."&product=".$productSlug."&environment=".$environment["name_slug"]."&image=".$image["name_slug"]."?id=".$testSession["id"]);
         // Set flash for user and redirect to session display
         $this->getUser()->setFlash("notice", "Test session was updated successfully");
         if (!empty($testSession["build_slug"])) {
             $this->redirect("build_session", array("project" => $projectSlug, "product" => $productSlug, "build" => $testSession["build_slug"], "environment" => $environment["name_slug"], "image" => $image["name_slug"], "id" => $request->getParameter("id")));
         } else {
             $this->redirect("test_session", array("project" => $projectSlug, "product" => $productSlug, "environment" => $environment["name_slug"], "image" => $image["name_slug"], "id" => $request->getParameter("id")));
         }
     }
 }
示例#10
0
* test installation
*/
#$grouptest = new GroupTest('Installation');
#$grouptest->addTestFile('test_install.php');
#$grouptest->run(new HtmlReporter());
#
### create a function to make sure we are starting at index.php ###
function startedIndexPhp()
{
    return true;
}
### include some core libraries ###
require_once '../std/common.inc.php';
require_once dirname(__FILE__) . '/../conf/conf.inc.php';
require_once dirname(__FILE__) . '/class.test_environment.php';
#confChange('DB_TABLE_PREFIX_UNITTEST', '');   # overwrite development database!!!
TestEnvironment::initStreberUrl();
TestEnvironment::prepare('fixtures/project_setup.sql');
$grouptest = new GroupTest('Efforts');
$grouptest->addTestFile('test_efforts.php');
$grouptest->run(new HtmlReporter());
$grouptest = new GroupTest('Item visibility');
$grouptest->addTestFile('test_item_visibility.php');
$grouptest->run(new HtmlReporter());
$grouptest = new GroupTest('Login logic');
$grouptest->addTestFile('test_pages_login.php');
$grouptest->run(new HtmlReporter());
$grouptest = new GroupTest('Render all pages');
$grouptest->addTestFile('test_pages_all.php');
$result = $grouptest->run(new HtmlReporter());
#TestEnvironment::prepare('fixtures/remove_tables.sql');
示例#11
0
<?php

/**
* Simpletest suite for testing installation
*/
error_reporting(E_ALL);
require_once 'simpletest/web_tester.php';
require_once 'simpletest/reporter.php';
### create a function to make sure we are starting at index.php ###
function startedIndexPhp()
{
    return true;
}
### include some core libraries ###
require_once '../std/common.inc.php';
require_once dirname(__FILE__) . '/../conf/conf.inc.php';
require_once dirname(__FILE__) . '/class.test_environment.php';
#confChange('DB_TABLE_PREFIX_UNITTEST', '');   # overwrite development database!!!
TestEnvironment::prepare('fixtures/project_setup.sql');
$grouptest = new GroupTest('Item visibility');
$grouptest->addTestFile('test_item_visibility.php');
$grouptest->run(new HtmlReporter());
$grouptest = new GroupTest('Login logic');
$grouptest->addTestFile('test_pages_login.php');
$grouptest->run(new HtmlReporter());
$grouptest = new GroupTest('Render all pages');
$grouptest->addTestFile('test_pages_all.php');
$result = $grouptest->run(new HtmlReporter());
TestEnvironment::prepare('fixtures/remove_tables.sql');
 public function testCRUD_Ok()
 {
     $client = TestEnvironment::client();
     TestEnvironment::createCustomer($client, 'TEST_CUST', 'Test Customer');
     TestEnvironment::createItem($client, 'TEST_ITEM', 'Test Item');
     // List
     $response = $client->get('/modules/api/sales/' . ST_SALESINVOICE, array('headers' => TestEnvironment::headers()));
     $this->assertEquals('200', $response->getStatusCode());
     $result = $response->getBody();
     $result = json_decode($result);
     $count0 = count($result);
     $this->assertEquals(0, $count0);
     // Add
     $ref = TestEnvironment::createId();
     //?XDEBUG_SESSION_START=cambell
     $response = $client->post('/modules/api/sales/', array('headers' => TestEnvironment::headers(), 'body' => array('trans_type' => ST_SALESINVOICE, 'ref' => $ref, 'comments' => 'comments', 'order_date' => '01/02/2013', 'delivery_date' => '03/04/2013', 'cust_ref' => 'cust_ref', 'deliver_to' => 'deliver_to', 'delivery_address' => 'delivery_address', 'phone' => 'phone', 'ship_via' => 'ship_via', 'location' => 'DEF', 'freight_cost' => '0', 'customer_id' => '2', 'branch_id' => '2', 'sales_type' => '1', 'dimension_id' => '0', 'dimension2_id' => '0', 'items' => array(0 => array('stock_id' => 'TEST_ITEM', 'qty' => '1', 'price' => '2', 'discount' => '0', 'description' => 'description')))));
     $this->assertEquals('200', $response->getStatusCode());
     $result = $response->getBody();
     $result = json_decode($result);
     // List again
     $response = $client->get('/modules/api/sales/' . ST_SALESINVOICE . '/', array('headers' => TestEnvironment::headers()));
     $this->assertEquals('200', $response->getStatusCode());
     $result = $response->getBody();
     $result = json_decode($result);
     $count1 = count($result);
     $this->assertEquals($count0 + 1, $count1);
     $id = $result[0]->trans_no;
     // Get by id
     $response = $client->get('/modules/api/sales/' . $id . '/' . ST_SALESINVOICE, array('headers' => TestEnvironment::headers()));
     $this->assertEquals('200', $response->getStatusCode());
     $result = $response->getBody();
     $result = json_decode($result);
     $expected = new stdClass();
     $expected->ref = $ref;
     $expected->comments = "comments";
     $expected->order_date = "01/02/2013";
     $expected->payment = "0";
     $expected->payment_terms = false;
     $expected->due_date = "03/04/2013";
     $expected->phone = "";
     $expected->cust_ref = "cust_ref";
     $expected->delivery_address = "delivery_address";
     $expected->ship_via = "0";
     $expected->deliver_to = "Test Customer";
     $expected->delivery_date = "03/04/2013";
     $expected->location = NULL;
     $expected->freight_cost = "0";
     $expected->email = "";
     $expected->customer_id = "2";
     $expected->branch_id = "2";
     $expected->sales_type = "1";
     $expected->dimension_id = "0";
     $expected->dimension2_id = "0";
     $item = new stdClass();
     $item->id = "2";
     $item->stock_id = "TEST_ITEM";
     $item->qty = 1;
     $item->units = "ea";
     $item->price = "2";
     $item->discount = "0";
     $item->description = "description";
     $expected->line_items = array($item);
     $expected->sub_total = 2;
     $expected->display_total = 2;
     $this->assertEquals($expected, $result);
     // Write back
     $response = $client->put('/modules/api/sales/' . $id . '/' . ST_SALESINVOICE, array('headers' => TestEnvironment::headers(), 'body' => array('trans_type' => ST_SALESINVOICE, 'ref' => $ref, 'comments' => 'new comments', 'order_date' => '02/03/2013', 'delivery_date' => '04/05/2013', 'cust_ref' => 'cust_ref', 'deliver_to' => 'new deliver_to', 'delivery_address' => 'new delivery_address', 'phone' => 'new phone', 'ship_via' => 'new ship_via', 'location' => 'DEF', 'freight_cost' => '0', 'customer_id' => '2', 'branch_id' => '2', 'sales_type' => '1', 'dimension_id' => '0', 'dimension2_id' => '0')));
     $this->assertEquals('200', $response->getStatusCode());
     $result = $response->getBody();
     $result = json_decode($result);
     // Get by id
     $response = $client->get('/modules/api/sales/' . $id . '/' . ST_SALESINVOICE, array('headers' => TestEnvironment::headers()));
     $this->assertEquals('200', $response->getStatusCode());
     $result = $response->getBody();
     $result = json_decode($result);
     $expected = new stdClass();
     $expected->ref = $ref;
     $expected->comments = "new comments";
     $expected->order_date = "02/03/2013";
     $expected->payment = "0";
     $expected->payment_terms = false;
     $expected->due_date = "04/05/2013";
     $expected->phone = "";
     $expected->cust_ref = "cust_ref";
     $expected->delivery_address = "delivery_address";
     $expected->ship_via = "0";
     $expected->deliver_to = "Test Customer";
     $expected->delivery_date = "04/05/2013";
     $expected->location = NULL;
     $expected->freight_cost = "0";
     $expected->email = "";
     $expected->customer_id = "2";
     $expected->branch_id = "2";
     $expected->sales_type = "1";
     $expected->dimension_id = "0";
     $expected->dimension2_id = "0";
     $item = new stdClass();
     $item->id = "2";
     $item->stock_id = "TEST_ITEM";
     $item->qty = 1;
     $item->units = "ea";
     $item->price = "2";
     $item->discount = "0";
     $item->description = "description";
     $expected->line_items = array($item);
     $expected->sub_total = 2;
     $expected->display_total = 2;
     $this->assertEquals($expected, $result);
     /* Delete is currently untested, and not implemented with standard FA
     		// Delete
     		$response = $client->delete('/modules/api/sales/' . $id, array(
     			'headers' => TestEnvironment::headers()
     		));
     		$this->assertEquals('200', $response->getStatusCode());
     		$result = $response->getBody();
     		$result = json_decode($result);
     
     		// List again
     		$response = $client->get('/modules/api/sales/', array(
     			'headers' => TestEnvironment::headers()
     		));
     
     		$this->assertEquals('200', $response->getStatusCode());
     		$result = $response->getBody();
     		$result = json_decode($result);
     
     		$count2 = count($result);
     		$this->assertEquals($count0, $count2);
     		*/
 }
示例#13
0
 /**
  *
  */
 function testAllPages()
 {
     global $g_streber_url;
     TestEnvironment::prepare('fixtures/project_setup.sql');
     TestEnvironment::initStreberUrl();
     $this->addHeader('USER_AGENT: streber_unit_tester');
     /**
      * we require some valid logins and ids to test all pages
      */
     $login_name = "admin";
     $login_password = "";
     # FIXME: Setting an absolute path is bad!
     $url_start = $g_streber_url . '/index.php?go=logout';
     $test_params = array("_projectView_" => 12, "_projectEdit_" => 12, "_taskView_" => 18, "_taskEdit_" => 18, "_personView_" => 1, "_personEdit_" => 1, "_companyView_" => 8, "_companyEdit_" => 8, "_commentView_" => 39, "_commentEdit_" => 39, "_effortView_" => 35, "_effortEdit_" => 35);
     require_once "../conf/defines.inc.php";
     # the order of those includes is tricky
     require_once '../std/class_auth.inc.php';
     require_once "../std/class_pagehandler.inc.php";
     require_once "../pages/_handles.inc.php";
     confChange('USE_MOD_REWRITE', false);
     # uncomment this for apache 1.x
     /**
      * test all pagehandles for correct rendering
      */
     ### go though all pagehandles and render ###
     foreach ($PH->hash as $key => $handle) {
         ### enter login-infos ###
         $this->assertTrue($this->get($url_start), 'getting logout-page (%s)');
         $this->assertTrue($this->setField('login_name', $login_name), 'set login-name (%s)');
         $this->assertTrue($this->setField('login_password', $login_password), 'set password (%s)');
         ### submit -> login to home ###
         $this->assertTrue($this->clickSubmit('Submit'), 'click_submit');
         $this->assertNoUnwantedPattern('/invalid login/i', 'Login for testing working (%s)');
         if ($handle->test == 'yes') {
             TestEnvironment::prepare('fixtures/project_setup.sql');
             $params = array();
             if (isset($handle->test_params)) {
                 foreach ($handle->test_params as $param => $value) {
                     if (isset($test_params[$value])) {
                         #echo "using param $param=$test_params[$value]<br>";
                         $params[$param] = $test_params[$value];
                     }
                 }
                 $url = $g_streber_url . $PH->getUrl($key, $params);
             } else {
                 $url = $g_streber_url . $PH->getUrl($key);
             }
             echo "<b>{$handle->id}</b> ";
             print_r($params);
             echo "<br>";
             $this->assertTrue($this->get("/" . $url), "getting {$url} (%s)");
             $this->assertNoUnwantedPattern('/PHP Error |<b>Fatal error<\\/b>|<b>Warning<\\/b>|<b>Error<\\/b>|<b>Notice<\\/b>|<b>Parse error<\\/b>/i', 'php-error found (%s)');
             $this->assertNoUnwantedPattern('/' . '%' . '%' . '/i', 'debug output found (%s)');
             $this->assertValidHtmlStucture($url);
             $this->assertNoUnwantedPattern('/fatal error \\(/i', 'check for streber warnings (%s)');
             $this->assertNoUnwantedPattern('/Error:/i', 'check for streber warnings (%s)');
             $this->assertWantedPattern('/<\\/html>/', 'rendering Complete? (%s)');
             $this->assertNoUnwantedPattern('/<x>/', 'check unescaped data (%s)');
             $this->assertNoUnwantedPattern('/&amp;lt;x&amp;gt;/', 'check double escaped data (%s)');
             for ($i = 0; $i < 20; $i++) {
                 echo "                       ";
             }
         }
     }
 }
<?php

use Api\Models\User;
require_once __DIR__ . '/../TestConfig.php';
require_once __DIR__ . '/../TestEnvironment.php';
TestEnvironment::ensureDatabaseConfigured();
class UserModelTest extends PHPUnit_Framework_TestCase
{
    public function testPassword_Ok()
    {
        $user = User::find(170);
        $this->assertNotNull($user);
        $plain_password = '******';
        $isAuth = $user->passwordCheck($plain_password);
        $this->assertTrue($isAuth);
    }
    public function testFindByLogin_Ok()
    {
        $user = User::findByLogin('bogus_login');
        $this->assertNull($user);
        $user = User::findByLogin('test');
        $this->assertNotNull($user);
        $this->assertEquals('test', $user->login);
    }
    public function testProjectsJoin_Ok()
    {
        $user = User::findByLogin('test');
        $this->assertNotNull($user);
        $projects = $user->projects;
        $c = count($projects);
        $this->assertEquals(2, $c);
示例#15
0
 /**
  * scenario: 
  * - bob runs beserk an deletes all tasks of manhatten project
  * - pm logs in an reverts all changes by bob
  */
 function testRevertChanges()
 {
     TestEnvironment::initStreberUrl();
     global $g_streber_url;
     TestEnvironment::prepare('fixtures/project_setup.sql');
     $this->addHeader('USER_AGENT: streber_unit_tester');
     $deleted_items = array(25, 23, 19, 18);
     ### login as bob ###
     $this->assertTrue($this->get($g_streber_url), 'getting login page (%s)');
     $this->assertTrue($this->setField('login_name', 'bob'));
     $this->assertTrue($this->setField('login_password', 'bob_secret'));
     $this->assertTrue($this->clickSubmit('Submit'));
     validatePage($this);
     ### View topics ###
     ### delete all tasks
     foreach ($deleted_items as $id) {
         $this->assertTrue($this->get($g_streber_url . '/?go=tasksDelete&tsk=' . $id), 'deleting (%s)');
         print $id;
         $this->assertNoUnwantedText('Warning:');
     }
     ### make sure, we are at home and items are listed as deleted
     $this->assertWantedText('deleted by ');
     ### make sure, bob can't access revert function, because it's only for admins
     $this->assertTrue($this->get($g_streber_url . '/?go=personRevertChanges&person=5'), 'getting revert page (%s)');
     $this->assertWantedText('Operation aborted');
     ### logout bob ###
     $this->assertTrue($this->clickLink('Logout'));
     $this->assertWantedPattern('/please login/i', 'check content (%s)');
     $this->assertValidHtmlStucture('login');
     ### login as pm ###
     $this->assertTrue($this->get($g_streber_url), 'getting login page (%s)');
     $this->assertTrue($this->setField('login_name', 'pm'));
     $this->assertTrue($this->setField('login_password', 'pm_secret'));
     $this->assertTrue($this->clickSubmit('Submit'));
     validatePage($this);
     ### make sure he sees the deleted tasks at home
     $this->assertWantedPattern("/body class=\"home\"/");
     #$this->showSource();
     foreach ($deleted_items as $id) {
         $this->assertWantedPattern("/{$id}\">.*deleted by <span class=person>Bob/");
         #            echo "<pre>" . $this->_browser->getContent() . "</pre>";
     }
     $this->assertTrue($this->get($g_streber_url . '/?go=personRevertChanges&person=5'), 'getting revert page (%s)');
     validatePage($this);
     $this->assertTrue($this->get($g_streber_url));
     ### make sure pm does no longer see any changes by bob
     foreach ($deleted_items as $id) {
         $this->assertNoUnwantedPattern("/href=\"{$id}\">.*deleted by <span class=person>Bob/");
     }
 }
 public function testCRUD_Ok()
 {
     $client = TestEnvironment::client();
     // List
     $response = $client->get('/modules/api/suppliers/', array('headers' => TestEnvironment::headers()));
     $this->assertEquals('200', $response->getStatusCode());
     $result = $response->getBody();
     $result = json_decode($result);
     $count0 = count($result);
     $this->assertEquals(0, $count0);
     // Add
     // 		$id = TestEnvironment::createId();
     $response = $client->post('/modules/api/suppliers/', array('headers' => TestEnvironment::headers(), 'body' => array('supp_name' => 'supp_name', 'supp_ref' => 'supp_ref', 'address' => 'address', 'supp_address' => 'supp_address', 'gst_no' => 'gst_no', 'website' => 'website', 'supp_account_no' => 'supp_account_no', 'bank_account' => 'bank_account', 'credit_limit' => '1000', 'curr_code' => 'USD', 'payment_terms' => '1', 'payable_account' => '1010', 'purchase_account' => '1020', 'payment_discount_account' => '1030', 'notes' => 'notes', 'tax_group_id' => '1', 'tax_included' => '1')));
     $this->assertEquals('201', $response->getStatusCode());
     $result = $response->getBody();
     $result = json_decode($result);
     // 		var_dump($result);
     $id = $result->supplier_id;
     $expected = new stdClass();
     $expected->supplier_id = '1';
     $expected->supp_name = 'supp_name';
     $expected->supp_ref = 'supp_ref';
     $expected->address = 'address';
     $expected->supp_address = 'supp_address';
     $expected->gst_no = 'gst_no';
     $expected->website = 'website';
     $expected->supp_account_no = 'supp_account_no';
     $expected->bank_account = 'bank_account';
     $expected->credit_limit = '1000';
     $expected->curr_code = 'USD';
     $expected->payment_terms = '1';
     $expected->payable_account = '1010';
     $expected->purchase_account = '1020';
     $expected->payment_discount_account = '1030';
     $expected->notes = 'notes';
     $expected->tax_group_id = '1';
     $expected->tax_included = '1';
     $expected->contact = '';
     $expected->dimension_id = '0';
     $expected->dimension2_id = '0';
     $expected->inactive = '0';
     $expected->{'0'} = '1';
     $expected->{'1'} = 'supp_name';
     $expected->{'2'} = 'supp_ref';
     $expected->{'3'} = 'address';
     $expected->{'4'} = 'supp_address';
     $expected->{'5'} = 'gst_no';
     $expected->{'6'} = '';
     $expected->{'7'} = 'supp_account_no';
     $expected->{'8'} = 'website';
     $expected->{'9'} = 'bank_account';
     $expected->{'10'} = 'USD';
     $expected->{'11'} = '1';
     $expected->{'12'} = '1';
     $expected->{'13'} = '0';
     $expected->{'14'} = '0';
     $expected->{'15'} = '1';
     $expected->{'16'} = '1000';
     $expected->{'17'} = '1020';
     $expected->{'18'} = '1010';
     $expected->{'19'} = '1030';
     $expected->{'20'} = 'notes';
     $expected->{'21'} = '0';
     $this->assertEquals($expected, $result);
     // List again
     $response = $client->get('/modules/api/suppliers/', array('headers' => TestEnvironment::headers()));
     $this->assertEquals('200', $response->getStatusCode());
     $result = $response->getBody();
     $result = json_decode($result);
     $count1 = count($result);
     $this->assertEquals($count0 + 1, $count1);
     // Get by id
     $response = $client->get('/modules/api/suppliers/' . $id, array('headers' => TestEnvironment::headers()));
     $this->assertEquals('200', $response->getStatusCode());
     $result = $response->getBody();
     $result = json_decode($result);
     $this->assertEquals($expected, $result);
     // Write back
     $response = $client->put('/modules/api/suppliers/' . $id, array('headers' => TestEnvironment::headers(), 'body' => array('supp_name' => 'new supp_name', 'supp_ref' => 'new supp_ref', 'address' => 'new address', 'supp_address' => 'new supp_address', 'gst_no' => 'new gst_no', 'website' => 'new website', 'supp_account_no' => 'new supp_account_no', 'bank_account' => 'new bank_account', 'credit_limit' => '2000', 'curr_code' => 'NZD', 'payment_terms' => '2', 'payable_account' => '2010', 'purchase_account' => '2020', 'payment_discount_account' => '2030', 'notes' => 'new notes', 'tax_group_id' => '2', 'tax_included' => '2')));
     $this->assertEquals('200', $response->getStatusCode());
     $result = $response->getBody();
     $result = json_decode($result);
     // Get by id to read back
     $response = $client->get('/modules/api/suppliers/' . $id, array('headers' => TestEnvironment::headers()));
     $this->assertEquals('200', $response->getStatusCode());
     $result = $response->getBody();
     $result = json_decode($result);
     $expected->supp_name = 'new supp_name';
     $expected->supp_ref = 'new supp_ref';
     $expected->address = 'new address';
     $expected->supp_address = 'new supp_address';
     $expected->gst_no = 'new gst_no';
     $expected->website = 'new website';
     $expected->supp_account_no = 'new supp_account_no';
     $expected->bank_account = 'new bank_account';
     $expected->credit_limit = '2000';
     $expected->curr_code = 'NZD';
     $expected->payment_terms = '2';
     $expected->payable_account = '2010';
     $expected->purchase_account = '2020';
     $expected->payment_discount_account = '2030';
     $expected->notes = 'new notes';
     $expected->tax_group_id = '2';
     $expected->tax_included = '2';
     $expected->contact = '';
     $expected->dimension_id = '0';
     $expected->dimension2_id = '0';
     $expected->inactive = '0';
     $expected->{'0'} = '1';
     $expected->{'1'} = 'new supp_name';
     $expected->{'2'} = 'new supp_ref';
     $expected->{'3'} = 'new address';
     $expected->{'4'} = 'new supp_address';
     $expected->{'5'} = 'new gst_no';
     $expected->{'6'} = '';
     $expected->{'7'} = 'new supp_account_no';
     $expected->{'8'} = 'new website';
     $expected->{'9'} = 'new bank_account';
     $expected->{'10'} = 'NZD';
     $expected->{'11'} = '2';
     $expected->{'12'} = '2';
     $expected->{'13'} = '0';
     $expected->{'14'} = '0';
     $expected->{'15'} = '2';
     $expected->{'16'} = '2000';
     $expected->{'17'} = '2020';
     $expected->{'18'} = '2010';
     $expected->{'19'} = '2030';
     $expected->{'20'} = 'new notes';
     $expected->{'21'} = '0';
     $this->assertEquals($expected, $result);
     // List again
     $response = $client->get('/modules/api/suppliers/', array('headers' => TestEnvironment::headers()));
     $this->assertEquals('200', $response->getStatusCode());
     $result = $response->getBody();
     $result = json_decode($result);
     $count1 = count($result);
     $this->assertEquals($count0 + 1, $count1);
     $this->assertEquals($id, $result[$count1 - 1]->supplier_id);
     // Delete
     $response = $client->delete('/modules/api/suppliers/' . $id, array('headers' => TestEnvironment::headers()));
     $this->assertEquals('200', $response->getStatusCode());
     $result = $response->getBody();
     $result = json_decode($result);
     // List again
     $response = $client->get('/modules/api/suppliers/', array('headers' => TestEnvironment::headers()));
     $this->assertEquals('200', $response->getStatusCode());
     $result = $response->getBody();
     $result = json_decode($result);
     $count2 = count($result);
     $this->assertEquals($count0, $count2);
 }
 public function testCRUD_Ok()
 {
     $client = TestEnvironment::client();
     // List
     $response = $client->get('/modules/api/customers/', array('headers' => TestEnvironment::headers()));
     $this->assertEquals('200', $response->getStatusCode());
     $result = $response->getBody();
     $result = json_decode($result);
     $count0 = count($result);
     $this->assertEquals(0, $count0);
     // Add
     // 		$id = TestEnvironment::createId();
     $response = $client->post('/modules/api/customers/', array('headers' => TestEnvironment::headers(), 'body' => array('custname' => 'custname', 'cust_ref' => 'cust_ref', 'address' => 'address', 'tax_id' => 'tax_id', 'curr_code' => 'USD', 'credit_status' => '1', 'payment_terms' => '1', 'discount' => '0', 'pymt_discount' => '0', 'credit_limit' => '1000', 'sales_type' => '1', 'notes' => 'notes')));
     $this->assertEquals('201', $response->getStatusCode());
     $result = $response->getBody();
     $result = json_decode($result);
     $id = $result->debtor_no;
     $expected = new stdClass();
     $expected->debtor_no = '1';
     $expected->name = 'custname';
     $expected->debtor_ref = 'cust_ref';
     $expected->address = 'address';
     $expected->tax_id = 'tax_id';
     $expected->curr_code = 'USD';
     $expected->sales_type = '1';
     $expected->dimension_id = '0';
     $expected->dimension2_id = '0';
     $expected->credit_status = '1';
     $expected->payment_terms = '1';
     $expected->discount = '0';
     $expected->pymt_discount = '0';
     $expected->credit_limit = '1000';
     $expected->notes = 'notes';
     $expected->inactive = '0';
     $expected->{'0'} = '1';
     $expected->{'1'} = 'custname';
     $expected->{'2'} = 'cust_ref';
     $expected->{'3'} = 'address';
     $expected->{'4'} = 'tax_id';
     $expected->{'5'} = 'USD';
     $expected->{'6'} = '1';
     $expected->{'7'} = '0';
     $expected->{'8'} = '0';
     $expected->{'9'} = '1';
     $expected->{'10'} = '1';
     $expected->{'11'} = '0';
     $expected->{'12'} = '0';
     $expected->{'13'} = '1000';
     $expected->{'14'} = 'notes';
     $expected->{'15'} = '0';
     $this->assertEquals($expected, $result);
     // List again
     $response = $client->get('/modules/api/customers/', array('headers' => TestEnvironment::headers()));
     $this->assertEquals('200', $response->getStatusCode());
     $result = $response->getBody();
     $result = json_decode($result);
     $count1 = count($result);
     $this->assertEquals($count0 + 1, $count1);
     // Get by id
     $response = $client->get('/modules/api/customers/' . $id, array('headers' => TestEnvironment::headers()));
     $this->assertEquals('200', $response->getStatusCode());
     $result = $response->getBody();
     $result = json_decode($result);
     $this->assertEquals($expected, $result);
     // Write back
     $response = $client->put('/modules/api/customers/' . $id, array('headers' => TestEnvironment::headers(), 'body' => array('custname' => 'new custname', 'cust_ref' => 'new cust_ref', 'address' => 'new address', 'tax_id' => 'new tax_id', 'curr_code' => 'NZD', 'credit_status' => '2', 'payment_terms' => '2', 'discount' => '1', 'pymt_discount' => '1', 'credit_limit' => '2000', 'sales_type' => '2', 'notes' => 'new notes')));
     $this->assertEquals('200', $response->getStatusCode());
     $result = $response->getBody();
     $result = json_decode($result);
     // Get by id to read back
     $response = $client->get('/modules/api/customers/' . $id, array('headers' => TestEnvironment::headers()));
     $this->assertEquals('200', $response->getStatusCode());
     $result = $response->getBody();
     $result = json_decode($result);
     $expected->name = 'new custname';
     $expected->debtor_ref = 'new cust_ref';
     $expected->address = 'new address';
     $expected->tax_id = 'new tax_id';
     $expected->curr_code = 'NZD';
     $expected->sales_type = '2';
     // 		$expected->dimension_id = '0';
     // 		$expected->dimension2_id = '0';
     $expected->credit_status = '2';
     $expected->payment_terms = '2';
     $expected->discount = '1';
     $expected->pymt_discount = '1';
     $expected->credit_limit = '2000';
     $expected->notes = 'new notes';
     // 		$expected->inactive = '0';
     $expected->{'0'} = '1';
     $expected->{'1'} = 'new custname';
     $expected->{'2'} = 'new cust_ref';
     $expected->{'3'} = 'new address';
     $expected->{'4'} = 'new tax_id';
     $expected->{'5'} = 'NZD';
     $expected->{'6'} = '2';
     $expected->{'7'} = '0';
     $expected->{'8'} = '0';
     $expected->{'9'} = '2';
     $expected->{'10'} = '2';
     $expected->{'11'} = '1';
     $expected->{'12'} = '1';
     $expected->{'13'} = '2000';
     $expected->{'14'} = 'new notes';
     $expected->{'15'} = '0';
     $this->assertEquals($expected, $result);
     // List again
     $response = $client->get('/modules/api/customers/', array('headers' => TestEnvironment::headers()));
     $this->assertEquals('200', $response->getStatusCode());
     $result = $response->getBody();
     $result = json_decode($result);
     $count1 = count($result);
     $this->assertEquals($count0 + 1, $count1);
     $this->assertEquals($id, $result[$count1 - 1]->debtor_no);
     // Delete
     $response = $client->delete('/modules/api/customers/' . $id, array('headers' => TestEnvironment::headers()));
     $this->assertEquals('200', $response->getStatusCode());
     $result = $response->getBody();
     $result = json_decode($result);
     // List again
     $response = $client->get('/modules/api/customers/', array('headers' => TestEnvironment::headers()));
     $this->assertEquals('200', $response->getStatusCode());
     $result = $response->getBody();
     $result = json_decode($result);
     $count2 = count($result);
     $this->assertEquals($count0, $count2);
 }
 /**
  * @return \Stagehand\TestRunner\Core\ApplicationContext
  */
 protected function createApplicationContext()
 {
     return TestEnvironment::getApplicationContext();
 }