/** * Method to test the loadFromObject method. * @since 1.0.0 * @test */ public function testLoadFromObject() { //create a Team Entity. $team = new Team(); //the object without prefix to load the Team Entity. $object = new \stdClass(); $object->id = 1; $object->name = 'Name'; $object->tag = 'Tag'; $object->website = 'Website'; //load the object without prefix to the Team Entity. $team->loadFromObject($object); //check whether the values are valid. $this->assertEquals(1, $team->id); $this->assertEquals('Name', $team->name); $this->assertEquals('Tag', $team->tag); $this->assertEquals('Website', $team->website); //the object with prefix to load the Team Entity. $object_prefix = new \stdClass(); $object_prefix->test_id = 2; $object_prefix->test_name = 'TestName'; $object_prefix->test_tag = 'TestTag'; $object_prefix->test_website = 'TestWebsite'; //load the object with prefix to the Team Entity. $team->loadFromObject($object_prefix, 'test_'); //check whether the values are valid. $this->assertEquals(2, $team->id); $this->assertEquals('TestName', $team->name); $this->assertEquals('TestTag', $team->tag); $this->assertEquals('TestWebsite', $team->website); }
/** * The save action of the Team. * @return bool The state if the Team was successfully saved. * @since 0.0.1-dev */ public function save() { //get the session. $this->needSession(); //get the information from post. $team = new Team(); $team->loadFromPOST('team_'); //check if the name is valid. if ((new IsValidName())->isSatisfiedBy($team) === false) { $this->jsonOutput('The name is not valid!', 'team_name', LogLevel::ERROR); return false; } //check if the tag is valid. if ((new IsValidTag())->isSatisfiedBy($team) === false) { $this->jsonOutput('The tag is not valid!', 'team_tag', LogLevel::ERROR); return false; } //check if the website is valid. if ((new IsValidWebsite())->isSatisfiedBy($team) === false) { $this->jsonOutput('The website is not valid!', 'team_website', LogLevel::ERROR); return false; } //check if the Team already exists. if ((new IsUnique(TeamRepository::build()))->isSatisfiedBy($team) === false) { $this->jsonOutput('The Team already exists!', '', LogLevel::ERROR); return false; } //save the Team on the database. if (TeamMapper::build()->save($team)) { $this->jsonOutput('The Team was saved successfully!', '', LogLevel::INFO, URL . 'team'); return true; } else { $this->jsonOutput('The Team could not be saved!', '', LogLevel::ERROR); return false; } }