public function testLoad() { $loader = new \Library\I18n\Translator\Loader\Po(); $textDomain = $loader->load('de', \Library\Module::getPath('data/Test/I18n/Translator/Loader/PoTest.po')); $this->assertInstanceOf('Zend\\I18n\\Translator\\TextDomain', $textDomain); $translations = array('single2single' => 'single to single', 'single2multi' => 'single to multi', 'multi2single' => 'multi to single', 'multi2multi' => 'multi to multi', "\\\n\"" => "\"\n\\"); $this->assertEquals($translations, $textDomain->getArrayCopy()); }
public function testLoadVendorDatabaseFromFile() { // Clear database first to ensure that data actually gets loaded MacAddress::loadVendorDatabase(array()); // Pass default database. It should load without errors. MacAddress::loadVendorDatabaseFromFile(\Library\Module::getPath('data/MacAddress/manuf')); $this->assertAttributeNotEmpty('_vendorList', 'Library\\MacAddress'); }
public function testLoadVendorDatabaseFromFile() { // Clear database first to ensure that data actually gets loaded MacAddress::loadVendorDatabase(array()); // Pass default database. It should load without errors. MacAddress::loadVendorDatabaseFromFile(\Library\Module::getPath('data/MacAddress/manuf')); $reflectionClass = new \ReflectionClass('Library\\MacAddress'); $this->assertNotEmpty($reflectionClass->getStaticProperties()['_vendorList']); }
/** * Return the vendor for this address. * * If the database is empty, the default database is loaded. * * @return string Vendor or NULL if the address is not found in the database. */ public function getVendor() { if (empty(self::$_vendorList)) { self::loadVendorDatabaseFromFile(\Library\Module::getPath('data/MacAddress/manuf')); } $addr = str_replace(':', '', $this->_address); // @codeCoverageIgnoreStart if (PHP_INT_SIZE < 8) { $addr = gmp_init($addr, 16); } else { $addr = hexdec($addr); } // @codeCoverageIgnoreEnd $longest = 0; $vendor = null; foreach (self::$_vendorList as $entry) { $mask = $entry['mask']; // Compare addresses only if this entry is more specific than the // last matching one. if ($mask > $longest and ($addr & $mask) == $entry['address']) { $vendor = $entry['vendor']; $longest = $mask; } } return $vendor; }
/** * Return the vendor for this address. * * If the database is empty, the default database is loaded. * * @return string Vendor or NULL if the address is not found in the database. */ public function getVendor() { if (empty(self::$_vendorList)) { self::loadVendorDatabaseFromFile(\Library\Module::getPath('data/MacAddress/manuf')); } $addr = str_replace(':', '', $this->_address); $longest = 0; $vendor = null; foreach (self::$_vendorList as $entry) { $length = $entry['length']; // Compare strings only if this entry is more specific than the // last matching one. The === operator is necessary to prevent // implicit casts that would lead to false positives with // "00:00:00" and similar. if ($length > $longest and substr($addr, 0, $length) === $entry['address']) { $vendor = $entry['vendor']; $longest = $length; } } return $vendor; }
/** * @requires extension zip */ public function testZipArchiveCreation() { // The Zip extension does not support stream wrappers. Use real // filesystem objects instead. Since the target file must not exist, // tmpfile() is not suitable. Instead, use tempnam() with a dedicated // directory to get a safe filename and delete the created file. This // is mostly safe because the only source for filename clashes would be // another test running on the same tree in parallel, and the randomized // filename part reduces the risk even further. $tmpDir = \Library\Module::getPath('data/Test/ArchiveManager'); $archiveFile = tempnam($tmpDir, 'zip'); try { if (dirname($archiveFile) != $tmpDir) { throw new \UnexpectedValueException('Could not generate temporary file in safe location'); } unlink($archiveFile); $manager = new ArchiveManager(); $archive = $manager->createArchive(ArchiveManager::ZIP, $archiveFile); $manager->addFile($archive, __FILE__, 'äöü.txt'); $manager->closeArchive($archive); $this->assertFileExists($archiveFile); $this->assertTrue($manager->isArchive(ArchiveManager::ZIP, $archiveFile)); $testArchive = new \ZipArchive(); $this->assertTrue($testArchive->open($archiveFile)); $this->assertEquals(1, $testArchive->numFiles); $content = $testArchive->getFromName('äöü.txt'); $testArchive->close(); $this->assertNotFalse($content); // Message is easier readable in case of error $this->assertEquals(file_get_contents(__FILE__), $content); unlink($archiveFile); } catch (\Exception $e) { if ($archiveFile) { @unlink($archiveFile); throw $e; } } }