Scalr\Tests\Functional\Api\Service\User\V1beta0\Controller\ProjectsTest::testComplex PHP Method

testComplex() public method

public testComplex ( )
    public function testComplex()
    {
        //create archived project
        $projectArch = $this->createTestProject(['name' => $this->getTestName(), 'archived' => ProjectEntity::ARCHIVED]);
        $projects = $this->listProjects([], 1);
        $adapter = $this->getAdapter('project');
        $filterable = $adapter->getRules()[ApiEntityAdapter::RULE_TYPE_FILTERABLE];
        foreach ($projects as $project) {
            foreach ($filterable as $property) {
                $filterValue = $project->{$property};
                $listResult = $this->listProjects([$property => $filterValue], 1);
                if (!empty($filterValue)) {
                    foreach ($listResult as $filtered) {
                        $this->assertEquals($filterValue, $filtered->{$property}, "Property '{$property}' mismatch");
                    }
                }
            }
            $response = $this->getProject($project->id);
            $this->assertEquals(200, $response->status, $this->printResponseError($response));
            $dbProject = ProjectEntity::findPk($project->id);
            $this->assertFalse((bool) $dbProject->archived);
            $this->assertObjectEqualsEntity($response->getBody()->data, $dbProject, $adapter);
        }
        $filterByName = $this->listProjects(['name' => $projectArch->name], 1);
        $this->assertNotEmpty($filterByName);
        foreach ($filterByName as $project) {
            $this->assertObjectEqualsEntity($project, $projectArch, $adapter);
            $this->assertNotContains($project, $projects, "List of project shouldn't  have an archived project", false, false);
        }
        $filterByBillingCode = $this->listProjects(['billingCode' => $projectArch->getProperty(ProjectPropertyEntity::NAME_BILLING_CODE)], 1);
        $this->assertNotEmpty($filterByBillingCode);
        foreach ($filterByBillingCode as $project) {
            $this->assertObjectEqualsEntity($project, $projectArch, $adapter);
            $this->assertNotContains($project, $projects, "List of project shouldn't  have an archived project", false, false);
        }
        $ccId = Scalr_Environment::init()->loadById($this->getEnvironment()->id)->getPlatformConfigValue(Scalr_Environment::SETTING_CC_ID);
        $cc = \Scalr::getContainer()->analytics->ccs->get($ccId);
        //test create project
        $projectData = ['name' => 'test', 'costCenter' => ['id' => $ccId], 'billingCode' => $cc->getProperty(CostCentrePropertyEntity::NAME_BILLING_CODE), 'leadEmail' => '[email protected]', 'description' => 'test'];
        $response = $this->postProject($projectData);
        $this->assertEquals(201, $response->status, $this->printResponseError($response));
        $projectId = $response->getBody()->data->id;
        $dbProject = ProjectEntity::findPk($projectId);
        $this->assertNotEmpty($dbProject);
        $this->projectToDelete($projectId);
        $this->assertObjectEqualsEntity($projectData, $dbProject, $adapter);
        //test empty project name
        $projectData = ['name' => "\t\r\n\v<a href=\"#\">\t\r\n\v</a>\t\r\n\v", 'costCenter' => ['id' => $ccId], 'billingCode' => $cc->getProperty(CostCentrePropertyEntity::NAME_BILLING_CODE), 'leadEmail' => '[email protected]', 'description' => 'test-empty-name'];
        $response = $this->postProject($projectData);
        $this->assertEquals(400, $response->status, $this->printResponseError($response));
        //test wrong ccId
        $projectData = ['name' => "test-wrong-cc-id", 'costCenter' => ['id' => "\t\r\n\v<a href=\"#\">\t\r\n\v</a>\t\r\n\v"], 'billingCode' => $cc->getProperty(CostCentrePropertyEntity::NAME_BILLING_CODE), 'leadEmail' => '[email protected]', 'description' => 'test-empty-name'];
        $response = $this->postProject($projectData);
        $this->assertEquals(404, $response->status, $this->printResponseError($response));
        //test wrong leadEmail
        $projectData = ['name' => "test-wrong-cc-id", 'costCenter' => ['id' => $ccId], 'billingCode' => $cc->getProperty(CostCentrePropertyEntity::NAME_BILLING_CODE), 'leadEmail' => "\t\r\n\v<a href=\"#\">\t\r\n\v</a>\t\r\n\v", 'description' => 'test-empty-lead-email'];
        $response = $this->postProject($projectData);
        $this->assertEquals(400, $response->status, $this->printResponseError($response));
    }