public function testConstructWithRegex()
 {
     $regex = 'regex';
     $validator = new RegexValidator(array('regex' => $regex));
     $validatorRegex = Reflection::getProperty($validator, 'regex');
     $this->assertEquals($regex, $validatorRegex);
 }
 public function testAddDependency()
 {
     $for = 'foo';
     $className = 'className';
     $dependency = new Dependency($className);
     $container = new DependencyContainer();
     $container->addDependency($for, $dependency);
     $expected = array($for => array(0 => $dependency));
     $this->assertEquals($expected, Reflection::getProperty($container, 'dependencies'));
     $this->assertEquals(0, $dependency->getId());
     $id = 'id';
     $dependency->setId($id);
     $container->addDependency($for, $dependency);
     $expected[$for][$id] = $dependency;
     $this->assertEquals($expected, Reflection::getProperty($container, 'dependencies'));
     $for = "bar";
     $container->addDependency($for, $dependency);
     $expected[$for][$id] = $dependency;
     $this->assertEquals($expected, Reflection::getProperty($container, 'dependencies'));
     $for = "foo";
     $dependency->setId();
     $container->addDependency($for, $dependency);
     $expected[$for][1] = $dependency;
     $this->assertEquals($expected, Reflection::getProperty($container, 'dependencies'));
     $this->assertEquals(1, $dependency->getId());
 }
Exemplo n.º 3
0
 public function testConstruct()
 {
     $cache = $this->getMockForAbstractClass('zibo\\library\\cache\\AbstractCache');
     $io = Reflection::getProperty($cache, 'io');
     $this->assertNotNull($io);
     $this->assertTrue($io instanceof CacheIO);
 }
Exemplo n.º 4
0
 /**
  * @dataProvider providerGetLocalesSortsLocales
  */
 public function testSetOrderSortsLocales($order, $codeA, $codeB = null, $codeC = null, $codeD = null)
 {
     $this->manager->setOrder($order);
     $locales = Reflection::getProperty($this->manager, 'locales');
     $this->assertEquals(4, count($locales));
     $i = 0;
     foreach ($locales as $key => $locale) {
         switch ($i) {
             case 0:
                 $this->assertEquals($codeA, $key);
                 $this->assertEquals($codeA, $locale->getCode());
                 break;
             case 1:
                 if ($codeB) {
                     $this->assertEquals($codeB, $key);
                     $this->assertEquals($codeB, $locale->getCode());
                 }
                 break;
             case 2:
                 if ($codeC) {
                     $this->assertEquals($codeC, $key);
                     $this->assertEquals($codeC, $locale->getCode());
                 }
                 break;
             case 3:
                 if ($codeD) {
                     $this->assertEquals($codeD, $key);
                     $this->assertEquals($codeD, $locale->getCode());
                 }
                 break;
         }
         $i++;
     }
 }
Exemplo n.º 5
0
 /**
  * @dataProvider providerConstruct
  */
 public function testConstruct($expectedId, $url)
 {
     $youtube = new Youtube($url);
     $this->assertEquals(Youtube::DEFAULT_HEIGHT, Reflection::getProperty($youtube, 'height'));
     $this->assertEquals(Youtube::DEFAULT_WIDTH, Reflection::getProperty($youtube, 'width'));
     $this->assertEquals($expectedId, $youtube->getVideoId());
 }
 public function testConstruct()
 {
     $name = 'name';
     $options = array('option' => 'value');
     $fieldValidator = new FieldValidator($name, $options);
     $this->assertEquals($name, Reflection::getProperty($fieldValidator, 'name'));
     $this->assertEquals($options, Reflection::getProperty($fieldValidator, 'options'));
 }
Exemplo n.º 7
0
 public function testConstruct()
 {
     $name = 'index';
     $fields = array('id' => new Field('id', 'integer'), 'name' => new Field('name', 'string'));
     $index = new Index($name, $fields);
     $this->assertEquals($name, Reflection::getProperty($index, 'name'));
     $this->assertEquals($fields, Reflection::getProperty($index, 'fields'));
 }
Exemplo n.º 8
0
 public function testRegister()
 {
     $this->createEmptyIOMock();
     $this->factory->register($this->mockExtension, $this->mockIO);
     $io = Reflection::getProperty($this->factory, 'io');
     $this->assertArrayHasKey($this->mockExtension, $io);
     $this->assertEquals($this->mockIO, $io[$this->mockExtension]);
 }
Exemplo n.º 9
0
 public function testSetAllowedNames()
 {
     $name = 'name';
     $name2 = 'name2';
     $expected = array($name, $name2);
     $this->filter->setAllowedNames($expected);
     $this->assertEquals($expected, Reflection::getProperty($this->filter, 'names'));
 }
 public function testAddErrors()
 {
     $name = 'field';
     $errors = array(new ValidationError('code1', 'message1'), new ValidationError('code2', 'message2'));
     $this->exception->addErrors($name, $errors);
     $exceptionErrors = Reflection::getProperty($this->exception, 'errors');
     $this->assertEquals(array($name => $errors), $exceptionErrors);
 }
 public function testRegister()
 {
     $this->createEmptyThumbnailerMock();
     $this->factory->register($this->mockName, $this->mockThumbnailer);
     $thumbnailers = Reflection::getProperty($this->factory, 'thumbnailers');
     $this->assertArrayHasKey($this->mockName, $thumbnailers);
     $this->assertEquals($this->mockThumbnailer, $thumbnailers[$this->mockName]);
 }
Exemplo n.º 12
0
 public function testConstruct()
 {
     $name = 'name';
     $format = 'format';
     $dataFormat = new DataFormat($name, $format);
     $this->assertEquals($name, Reflection::getProperty($dataFormat, 'name'));
     $this->assertEquals($format, Reflection::getProperty($dataFormat, 'format'));
 }
Exemplo n.º 13
0
 public function testGetInstanceLoadsCaptchas()
 {
     $config = array('mock' => self::CAPTCHA_MOCK);
     $this->configIOMock->setValues('captcha', $config);
     $manager = CaptchaManager::getInstance();
     $captchas = Reflection::getProperty($manager, 'captchas');
     $this->assertTrue(is_array($captchas));
     $this->assertTrue(array_key_exists('mock', $captchas));
 }
Exemplo n.º 14
0
 public function testConnect()
 {
     $connection = new Connection($this->host);
     $this->assertNull(Reflection::getProperty($connection, 'socket'));
     $connection->connect();
     $this->assertNotNull(Reflection::getProperty($connection, 'socket'));
     $connection->disconnect();
     $this->assertNull(Reflection::getProperty($connection, 'socket'));
 }
 public function testRegisterFilter()
 {
     $filterName = 'trim';
     $filterClass = 'zibo\\library\\validation\\filter\\TrimFilter';
     $this->factory->registerFilter($filterName, $filterClass);
     $filters = Reflection::getProperty($this->factory, 'filters');
     $this->assertArrayHasKey($filterName, $filters);
     $this->assertContains($filterClass, $filters);
 }
Exemplo n.º 16
0
 public function testSetDateFormat()
 {
     $identifier = 'id';
     $format = 'd-m-Y';
     $locale = new Locale('en', 'en');
     $locale->setDateFormat($identifier, $format);
     $expected = array($identifier => $format);
     $this->assertEquals($expected, Reflection::getProperty($locale, 'dateFormats'));
 }
Exemplo n.º 17
0
 public function testConstruct()
 {
     $client = new Client('http://time.xmlrpc.com:80/RPC2');
     $host = Reflection::getProperty($client, 'host');
     $this->assertEquals('time.xmlrpc.com', $host, 'host is not the expected host');
     $port = Reflection::getProperty($client, 'port');
     $this->assertEquals(80, $port, 'port is not the expected port');
     $path = Reflection::getProperty($client, 'path');
     $this->assertEquals('/RPC2', $path, 'path is not the expected path');
 }
Exemplo n.º 18
0
 public function testSetEmoticonImage()
 {
     $emoticonParser = new EmoticonParser($this->emoticons);
     $emoticon = ':-(';
     $image = 'web/images/sad.png';
     $this->emoticons[$emoticon] = $image;
     $emoticonParser->setEmoticonImage($emoticon, $image);
     $parserEmoticons = Reflection::getProperty($emoticonParser, 'emoticons');
     $this->assertEquals($this->emoticons, $parserEmoticons);
 }
Exemplo n.º 19
0
 public function testConstructWithMinimumAndMaximum()
 {
     $minimum = 4;
     $maximum = 8;
     $validator = new SizeValidator(array('minimum' => $minimum, 'maximum' => $maximum));
     $validatorMinimum = Reflection::getProperty($validator, 'minimum');
     $validatorMaximum = Reflection::getProperty($validator, 'maximum');
     $this->assertEquals($minimum, $validatorMinimum);
     $this->assertEquals($maximum, $validatorMaximum);
 }
Exemplo n.º 20
0
 public function testRegisterServiceWithoutParameters()
 {
     $expected = array('callback' => new Callback($this->callback), 'return' => $this->resultType, 'parameters' => array(), 'description' => null);
     $this->server->registerService($this->serviceName, $this->callback, $this->resultType);
     $services = Reflection::getProperty($this->server, 'services');
     $this->assertNotNull($services, 'services is null');
     $this->assertTrue(is_array($services), 'services is no array');
     $this->assertEquals(1, count($services), 'services has unexpected count');
     $this->assertTrue(isset($services[$this->serviceName]), 'registered service is not set');
     $this->assertEquals($expected, $services[$this->serviceName]);
 }
 /**
  * @dataProvider providerIsValid
  */
 public function testIsValid($expected, $value)
 {
     $validator = new WebsiteValidator();
     $result = $validator->isValid($value);
     $this->assertEquals($expected, $result, $value);
     if (!$expected) {
         $regex = Reflection::getProperty($validator, 'regex');
         $expectedParameters = array('value' => $value, 'regex' => $regex);
         $expectedError = new ValidationError(WebsiteValidator::CODE, WebsiteValidator::MESSAGE, $expectedParameters);
         $resultErrors = $validator->getErrors();
         $this->assertEquals(array($expectedError), $resultErrors);
     }
 }
Exemplo n.º 22
0
 /**
  * @dataProvider providerIsValid
  */
 public function testIsValid($expected, $test)
 {
     $validator = new DsnValidator();
     $result = $validator->isValid($test);
     $this->assertEquals($expected, $result);
     if (!$expected) {
         $resultErrors = $validator->getErrors();
         $regex = Reflection::getProperty($validator, 'regex');
         $expectedParameters = array('value' => $test, 'regex' => $regex);
         $expectedErrors = array(new ValidationError(DsnValidator::CODE, DsnValidator::MESSAGE, $expectedParameters));
         $this->assertEquals($expectedErrors, $resultErrors);
     }
 }
Exemplo n.º 23
0
 public function testGetArchive()
 {
     if (!class_exists('ZipArchive')) {
         $this->markTestSkipped('Zip is unsupported on this system.');
     }
     $typeName = 'zip';
     $typeClass = 'zibo\\library\\archive\\Zip';
     $factory = ArchiveFactory::getInstance();
     $factory->register($typeName, $typeClass);
     $file = new File('test.zip');
     $archive = $factory->getArchive($file);
     $archiveFile = Reflection::getProperty($archive, 'file');
     $this->assertEquals($file, $archiveFile);
 }
Exemplo n.º 24
0
 public function testRegisterModel()
 {
     $field = new PropertyField('field', 'type');
     $model = $this->createModel('table', array($field));
     $model2 = $this->createModel('table2', array($field));
     $this->register->registerModel($model);
     $this->register->registerModel($model2);
     $models = Reflection::getProperty($this->register, 'models');
     $this->assertTrue(is_array($models), 'models is not an array');
     $this->assertTrue(isset($models[$model2->getName()]), $model2->getName() . ' is not set');
     $this->assertEquals($model2, $models[$model2->getName()]);
     $this->assertTrue(isset($models[$model->getName()]), $model->getName() . ' is not set');
     $this->assertEquals($model, $models[$model->getName()]);
 }
Exemplo n.º 25
0
 /**
  * @dataProvider providerConstruct
  */
 public function testConstruct($minimum, $maximum)
 {
     $options = array();
     if ($minimum !== null) {
         $options[MinMaxValidator::OPTION_MINIMUM] = $minimum;
     }
     if ($maximum !== null) {
         $options[MinMaxValidator::OPTION_MAXIMUM] = $maximum;
     }
     $validator = new MinMaxValidator($options);
     $validatorMinimum = Reflection::getProperty($validator, 'minimum');
     $validatorMaximum = Reflection::getProperty($validator, 'maximum');
     $this->assertEquals($minimum, $validatorMinimum);
     $this->assertEquals($maximum, $validatorMaximum);
 }
Exemplo n.º 26
0
 public function testConstruct()
 {
     $baseUrl = 'baseUrl';
     $basePath = 'baseUrl/basePath';
     $controllerName = 'controllerName';
     $actionName = 'actionName';
     $parameters = array('Value');
     $route = '/basePath';
     $request = new Request($baseUrl, $basePath, $controllerName, $actionName, $parameters);
     $this->assertEquals($baseUrl, Reflection::getProperty($request, 'baseUrl'));
     $this->assertEquals($basePath, Reflection::getProperty($request, 'basePath'));
     $this->assertEquals($controllerName, Reflection::getProperty($request, 'controllerName'));
     $this->assertEquals($actionName, Reflection::getProperty($request, 'actionName'));
     $this->assertEquals($parameters, Reflection::getProperty($request, 'parameters'));
     $this->assertEquals($route, Reflection::getProperty($request, 'route'));
 }
Exemplo n.º 27
0
 public function testConstruct()
 {
     $title = 'title';
     $message = 'message';
     $type = LogItem::INFORMATION;
     $name = 'test';
     $date = time();
     $ip = $_SERVER['REMOTE_ADDR'];
     $logItem = new LogItem($title, $message, $type, $name);
     $this->assertEquals($title, Reflection::getProperty($logItem, 'title'));
     $this->assertEquals($message, Reflection::getProperty($logItem, 'message'));
     $this->assertEquals($type, Reflection::getProperty($logItem, 'type'));
     $this->assertEquals($name, Reflection::getProperty($logItem, 'name'));
     $this->assertEquals($date, Reflection::getProperty($logItem, 'date'));
     $this->assertEquals($ip, Reflection::getProperty($logItem, 'ip'));
 }
Exemplo n.º 28
0
 public function testAddLogItem()
 {
     $listener = new TestLogListener();
     $this->log->addLogListener($listener);
     $title = 'Test log title';
     $message = 'Test log message';
     $type = LogItem::WARNING;
     $name = 'test';
     $item = new LogItem($title, $message, $type, $name);
     $this->log->addLogItem($item);
     $listener_item = Reflection::getProperty($listener, 'item');
     $this->assertTrue($listener_item == $item, 'Item not added');
     $this->assertTrue($listener_item->getTitle() == $title, 'Title is not the initial title');
     $this->assertTrue($listener_item->getMessage() == $message, 'Message is not the initial message');
     $this->assertTrue($listener_item->getType() == $type, 'Type is not the initial type');
     $this->assertTrue($listener_item->getName() == $name, 'Name is not the initial name');
     $this->assertFalse(String::isEmpty($listener_item->getDate()), 'Date is empty');
     $this->assertFalse(String::isEmpty($listener_item->getMicrotime()), 'Microtime is empty');
     $this->assertFalse(String::isEmpty($listener_item->getIP()), 'IP is empty');
 }
Exemplo n.º 29
0
 public function testAddAndRemoveModel()
 {
     $field = new PropertyField('name', 'type');
     $name = 'model';
     $name2 = 'model2';
     $model = $this->createModel($name, array($field));
     $model2 = $this->createModel($name2, array($field));
     $this->manager->addModel($model);
     $this->manager->addModel($model2);
     $models = Reflection::getProperty($this->manager, 'models');
     $this->assertTrue(is_array($models), 'models is not an array');
     $this->assertTrue(count($models) == 2, 'unexpected number of models');
     $this->assertTrue(isset($models[$name]), 'added model not set');
     $this->assertTrue(isset($models[$name2]), 'added model2 not set');
     $this->assertEquals($model, $models[$name], 'model in the manager is not the added model');
     $this->assertEquals($model2, $models[$name2], 'model2 in the manager is not the added model2');
     $this->manager->removeModel($name);
     $models = Reflection::getProperty($this->manager, 'models');
     $this->assertTrue(is_array($models), 'models is not an array');
     $this->assertTrue(count($models) == 1, 'unexpected number of models');
     $this->assertFalse(isset($models[$name]), 'added model still set');
     $this->assertTrue(isset($models[$name2]), 'added model2 not set');
 }
Exemplo n.º 30
0
 public function testClearEventListenersForEvent()
 {
     $event = 'event';
     $callback = array($this, 'testClearEventListeners');
     $this->eventManager->registerEventListener($event, $callback);
     $events = Reflection::getProperty($this->eventManager, 'events');
     $this->assertTrue(in_array(new Callback($callback), $events[$event]));
     $this->eventManager->clearEventListeners($event);
     $events = Reflection::getProperty($this->eventManager, 'events');
     $this->assertFalse(isset($events[$event]));
 }