/** * Method to test the loadFromObject method. * @since 1.0.0 * @test */ public function testLoadFromObject() { //create a Clan Entity. $clan = new Clan(); //the object without prefix to load the Clan Entity. $object = new \stdClass(); $object->id = 1; $object->name = 'Name'; $object->tag = 'Tag'; $object->website = 'Website'; //load the object without prefix to the Clan Entity. $clan->loadFromObject($object); //check whether the values are valid. $this->assertEquals(1, $clan->id); $this->assertEquals('Name', $clan->name); $this->assertEquals('Tag', $clan->tag); $this->assertEquals('Website', $clan->website); //the object with prefix to load the Clan 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 Clan Entity. $clan->loadFromObject($object_prefix, 'test_'); //check whether the values are valid. $this->assertEquals(2, $clan->id); $this->assertEquals('TestName', $clan->name); $this->assertEquals('TestTag', $clan->tag); $this->assertEquals('TestWebsite', $clan->website); }
/** * The save action of the Clan. * @return bool The state if the Clan could be successfully saved. * @since 0.0.1-dev */ public function save() { //get the session. $this->needSession(); //get the information from POST. $clan = new Clan(); $clan->loadFromPOST('clan_'); //get the DataMapper. $clanMapper = ClanMapper::build(); //check if the name is valid. if ((new IsValidName())->isSatisfiedBy($clan) === false) { $this->jsonOutput('The name is not valid!', 'clan_name', LogLevel::ERROR); return false; } //check if the tag is valid. if ((new IsValidTag())->isSatisfiedBy($clan) === false) { $this->jsonOutput('The tag is not valid!', 'clan_tag', LogLevel::ERROR); return false; } //check if the website is valid. if ((new IsValidWebsite())->isSatisfiedBy($clan) === false) { $this->jsonOutput('The website is not valid!', 'clan_website', LogLevel::ERROR); return false; } //check if the Clan already exists. if ((new IsUnique(ClanRepository::build()))->isSatisfiedBy($clan) === false) { $this->jsonOutput('The Clan already exists!', '', LogLevel::ERROR); return false; } //save the Clan on the database. if ($clanMapper->save($clan)) { $this->jsonOutput('The Clan was saved successfully!', '', LogLevel::INFO, URL . 'clan'); return true; } else { $this->jsonOutput('The Clan could not be saved!', '', LogLevel::ERROR); return false; } }