Esempio n. 1
0
 /**
  * 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;
     }
 }
Esempio n. 2
0
 /**
  * Method to build a new object of ClanRepository.
  * @return ClanRepository The created object of ClanRepository.
  * @since 1.0.0
  * @uses ClanMapper::build() to get the connetion to the database.
  */
 public static function build()
 {
     return new self(ClanMapper::build());
 }
Esempio n. 3
0
 /**
  * Method to test the update method.
  * @since 1.0.0
  * @test
  */
 public function testUpdate()
 {
     //the Clan Entity which will be updated on database.
     $clan = new Clan();
     $clan->id = 2;
     $clan->name = 'Clanify Gaming';
     $clan->tag = 'CG';
     $clan->website = 'http://clanify.rocks/gaming';
     //the ClanMapper to update the Clan Entity on database.
     $clanMapper = new ClanMapper($this->getConnection()->getConnection());
     $clanMapper->update($clan);
     //get the actual and expected table.
     $actualTable = $this->getConnection()->createQueryTable('clan', 'SELECT * FROM clan');
     $expectedDataset = __DIR__ . '/DataSets/Clan/clan-update.xml';
     $expectedTable = $this->createXMLDataSet($expectedDataset)->getTable('clan');
     //check whether the tables are equal.
     $this->assertTablesEqual($expectedTable, $actualTable);
     //another Entity than Clan Entity is not valid on the ClanMapper.
     $this->assertFalse($clanMapper->update(new Team()));
 }
Esempio n. 4
0
 /**
  * Method to test if the method update() works.
  * @since 0.0.1-dev
  * @test
  */
 public function testSaveUpdate()
 {
     //The Clan which will be updated on database.
     $clan = new Clan();
     $clan->id = 2;
     $clan->name = 'Clanify eSport';
     $clan->tag = 'CeS';
     $clan->website = 'http://clanify.rocks/esport';
     //The ClanMapper to update the Clan on database.
     $clanMapper = new ClanMapper($this->pdo);
     $clanMapper->save($clan);
     //Get the actual and expected table.
     $queryTable = $this->getConnection()->createQueryTable('clan', 'SELECT * FROM clan');
     $expectedDataSet = __DIR__ . '/DataSets/Clan/clan-save-update.xml';
     $expectedTable = $this->createXMLDataSet($expectedDataSet)->getTable('clan');
     //Check if the tables are equal.
     $this->assertTablesEqual($expectedTable, $queryTable);
 }