예제 #1
0
 /**
  * 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;
     }
 }
예제 #2
0
 /**
  * Method to build a new object of TeamRepository.
  * @return TeamRepository The created object of TeamRepository.
  * @since 1.0.0
  * @uses TeamMapper::build() to get the connection to the database.
  */
 public static function build()
 {
     return new self(TeamMapper::build());
 }
예제 #3
0
 /**
  * Method to test if the method update() works.
  * @since 0.0.1-dev
  * @test
  */
 public function testSaveUpdate()
 {
     //The Team which will be deleted on database.
     $team = new Team();
     $team->id = 2;
     $team->name = 'Example Team';
     $team->tag = 'ET';
     $team->website = 'http://example.com/esport';
     //The TeamMapper to delete the Team on database.
     $teamMapper = new TeamMapper($this->pdo);
     $teamMapper->save($team);
     //Get the actual and expected table.
     $queryTable = $this->getConnection()->createQueryTable('team', 'SELECT * FROM team');
     $expectedDataSet = __DIR__ . '/DataSets/Team/team-save-update.xml';
     $expectedTable = $this->createXMLDataSet($expectedDataSet)->getTable('team');
     //Check if the tables are equal.
     $this->assertTablesEqual($expectedTable, $queryTable);
 }
예제 #4
0
 /**
  * Method to test the update method.
  * @since 1.0.0
  * @test
  */
 public function testUpdate()
 {
     //the Team Entity which will be updated on database.
     $team = new Team();
     $team->id = 2;
     $team->name = 'Example Team';
     $team->tag = 'ET';
     $team->website = 'http://example.com/esport';
     //the TeamMapper to update the Team Entity on database.
     $teamMapper = new TeamMapper($this->getConnection()->getConnection());
     $teamMapper->update($team);
     //get the actual and expected table.
     $actualTable = $this->getConnection()->createQueryTable('team', 'SELECT * FROM team');
     $expectedDataset = __DIR__ . '/DataSets/Team/team-update.xml';
     $expectedTable = $this->createXMLDataSet($expectedDataset)->getTable('team');
     //check whether the tables are equal.
     $this->assertTablesEqual($expectedTable, $actualTable);
     //another Entity than Team Entity is not valid on the TeamMapper.
     $this->assertFalse($teamMapper->update(new Clan()));
 }