public function testFetchCommit() { $commitHash = 'commit-hash'; $treeHash = 'tree-hash'; $message = 'My message'; $username = '******'; $createdAt = new \DateTime(); $factory = $this->getFactory(); $tree = $this->prophesize(TreeInterface::class); $tree->getHash()->willReturn($treeHash); $user = $this->prophesize(UserInterface::class); $user->getUsername()->willReturn($username); $commit = new Commit(); $commit->setPolicyCollection(new PolicyCollection()); $commit->setHash($commitHash); $commit->setTree($tree->reveal()); $commit->setCommitter($user->reveal()); $commit->setCreatedAt(new \DateTime()); $commit->setMessage($message); $commit->setParentCommit(null); $database = $this->prophesize(DatabaseInterface::class); $database->fetch($commitHash, Commit::class)->willReturn($commit); $userProvider = $this->prophesize(UserProviderInterface::class); $userProvider->loadUserByUsername($username)->willReturn($user); $commitManager = new CommitManager($factory, $database->reveal(), $userProvider->reveal()); $result = $commitManager->fetch($commitHash); $this->assertEquals($commitHash, $result->getHash()); $this->assertEquals($treeHash, $result->getTree()->getHash()); $this->assertEquals($createdAt->format(\DateTime::ISO8601), $result->getCreatedAt()->format(\DateTime::ISO8601)); $this->assertEquals($message, $result->getMessage()); $this->assertEquals($username, $result->getCommitter()->getUsername()); $this->assertEquals(null, $result->getParentCommit()); }
public function testCreatesIS08601WithFractionalSeconds() { $time = '2009-03-07T08:03:50.012Z'; $date = DateTime::createFromISO8601($time); $standard = \DateTime::createFromFormat('Y-m-d\\TH:i:s.uO', $time); $this->assertEquals($standard, $date); }
/** * Get the entry modification date * * @return string */ public function getDateModified() { if (array_key_exists('datemodified', $this->data)) { return $this->data['datemodified']; } $date = null; if ($this->getAtomType() === Reader\Reader::TYPE_ATOM_03) { $dateModified = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/atom:modified)'); } else { $dateModified = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/atom:updated)'); } if ($dateModified) { $date = DateTime::createFromISO8601($dateModified); } $this->data['datemodified'] = $date; return $this->data['datemodified']; }
/** * * * @return DateTime|null */ public function getDate() { if (array_key_exists('date', $this->data)) { return $this->data['date']; } $d = null; $date = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc11:date)'); if (!$date) { $date = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc10:date)'); } if ($date) { $d = DateTime::createFromISO8601($date); } $this->data['date'] = $d; return $this->data['date']; }
/** * @param bool|IPAddress $ip * @param bool $ignoreConfig */ public function createIPBan($ip = false, $ignoreConfig = false) { if ($ignoreConfig || Config::get('concrete.security.ban.ip.enabled') == 1) { $ip = $ip instanceof IPAddress ? $ip : $this->getRequestIP(); $db = Loader::db(); //If there's a permanent ban, obey its setting otherwise set up a temporary ban if (!$this->existsManualPermBan($ip)) { $db->StartTrans(); $q = 'DELETE FROM UserBannedIPs WHERE ipFrom = ? AND ipTo = ? AND isManual = ?'; $v = array($ip->getIp(), 0, 0); $db->execute($q, $v); //IP_BAN_LOCK_IP_HOW_LONG_MIN of 0 or undefined means forever $timeOffset = Config::get('concrete.security.ban.ip.length'); $timeOffset = $timeOffset ? $timeOffset : 0; if ($timeOffset !== 0) { $banUntil = new \DateTime(); $banUntil->modify('+' . $timeOffset . ' minutes'); $banUntil = $banUntil->format('Y-m-d H:i:s'); } else { $banUntil = '0000-00-00 00:00:00'; } $q = 'INSERT INTO UserBannedIPs (ipFrom,ipTo,banCode,expires,isManual) '; $q .= 'VALUES (?,?,?,?,?)'; $v = array($ip->getIp(), 0, UserBannedIp::IP_BAN_CODE_REGISTRATION_THROTTLE, $banUntil, 0); $db->execute($q, $v); $db->CompleteTrans(); } } }