Esempio n. 1
0
 function testVideoMetaAboveAndBelow()
 {
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $messageService = $ioc->get(org_tubepress_api_message_MessageService::_);
     $messageService->shouldReceive('_')->atLeast()->once()->andReturnUsing(function ($msg) {
         return "##{$msg}##";
     });
     $metaNames = org_tubepress_impl_util_LangUtils::getDefinedConstants(org_tubepress_api_const_options_names_Meta::_);
     $shouldShow = array();
     $labels = array();
     $execContext = $ioc->get(org_tubepress_api_exec_ExecutionContext::_);
     $odr = $ioc->get(org_tubepress_api_options_OptionDescriptorReference::_);
     $odr->shouldReceive('findOneByName')->times(17)->andReturnUsing(function ($m) {
         $mock = \Mockery::mock(org_tubepress_api_options_OptionDescriptor::_);
         $mock->shouldReceive('getLabel')->once()->andReturn('video-' . $m);
         return $mock;
     });
     foreach ($metaNames as $metaName) {
         $shouldShow[$metaName] = "<<value of {$metaName}>>";
         $labels[$metaName] = '##video-' . $metaName . '##';
         $execContext->shouldReceive('get')->once()->with($metaName)->andReturnUsing(function ($m) {
             return "<<value of {$m}>>";
         });
     }
     $mockTemplate = \Mockery::mock(org_tubepress_api_template_Template::_);
     $mockTemplate->shouldReceive('setVariable')->once()->with(org_tubepress_api_const_template_Variable::META_SHOULD_SHOW, $shouldShow);
     $mockTemplate->shouldReceive('setVariable')->once()->with(org_tubepress_api_const_template_Variable::META_LABELS, $labels);
     $providerResult = \Mockery::mock('org_tubepress_api_provider_ProviderResult');
     $this->assertEquals($mockTemplate, $this->_sut->alter_galleryTemplate($mockTemplate, $providerResult, 1, org_tubepress_api_provider_Provider::YOUTUBE));
 }
 /**
  * Gets the failure message of a name/value pair that has failed validation.
  *
  * @param string       $optionName The option name
  * @param unknown_type $candidate  The candidate option value
  *
  * @return unknown Null if the option passes validation, otherwise a string failure message.
  */
 function getProblemMessage($optionName, $candidate)
 {
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $odr = $ioc->get(org_tubepress_api_options_OptionDescriptorReference::_);
     $descriptor = $odr->findOneByName($optionName);
     if ($descriptor === null) {
         return sprintf('No option with name %s', $optionName);
     }
     if ($descriptor->hasValidValueRegex()) {
         if (preg_match_all($descriptor->getValidValueRegex(), (string) $candidate, $matches) >= 1 && $matches[0][0] === (string) $candidate) {
             return null;
         }
         return sprintf('"%s" must match the regular expression %s. You supplied "%s".', $optionName, $descriptor->getValidValueRegex(), $candidate);
     }
     if ($descriptor->hasDiscreteAcceptableValues()) {
         $acceptableValues = $descriptor->getAcceptableValues();
         if (org_tubepress_impl_util_LangUtils::isAssociativeArray($acceptableValues)) {
             $values = array_keys($descriptor->getAcceptableValues());
         } else {
             $values = array_values($acceptableValues);
         }
         if (in_array($candidate, $values)) {
             return null;
         }
         return sprintf('"%s" must be one of {%s}. You supplied "%s".', $optionName, implode(', ', $values), $candidate);
     }
     if ($descriptor->isBoolean()) {
         if (is_bool($candidate)) {
             return null;
         }
         return sprintf('"%s" can only accept true/false values. You supplied "%s".', $optionName, $candidate);
     }
     return null;
 }
Esempio n. 3
0
 function testAssocArray()
 {
     $this->assertFalse(org_tubepress_impl_util_LangUtils::isAssociativeArray(array(1, 2)));
     $this->assertFalse(org_tubepress_impl_util_LangUtils::isAssociativeArray(array()));
     $this->assertFalse(org_tubepress_impl_util_LangUtils::isAssociativeArray(array('foo' => 'bar', 3)));
     $this->assertTrue(org_tubepress_impl_util_LangUtils::isAssociativeArray(array('foo' => 'bar', 'smack' => 'crack')));
 }
 protected function populateTemplate($template, $currentValue)
 {
     $values = array();
     $map = $this->getOptionDescriptor()->getAcceptableValues();
     if (!org_tubepress_impl_util_LangUtils::isAssociativeArray($map)) {
         throw new Exception(sprintf('"%s" has a non-associative array set for its value map', $this->getOptionDescriptor()->getName()));
     }
     foreach ($map as $key => $value) {
         $values[$key] = $this->getMessageService()->_($value);
     }
     $template->setVariable(self::TEMPLATE_VAR_ACCEPTABLE_VALUES, $values);
 }
Esempio n. 5
0
 public function alter_singleVideoTemplate(org_tubepress_api_template_Template $template, org_tubepress_api_video_Video $video, $providerName)
 {
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $context = $ioc->get(org_tubepress_api_exec_ExecutionContext::_);
     $messageService = $ioc->get(org_tubepress_api_message_MessageService::_);
     $optionDescriptorReference = $ioc->get(org_tubepress_api_options_OptionDescriptorReference::_);
     $metaNames = org_tubepress_impl_util_LangUtils::getDefinedConstants(org_tubepress_api_const_options_names_Meta::_);
     $shouldShow = array();
     $labels = array();
     foreach ($metaNames as $metaName) {
         $optionDescriptor = $optionDescriptorReference->findOneByName($metaName);
         $shouldShow[$metaName] = $context->get($metaName);
         $labels[$metaName] = $messageService->_($optionDescriptor->getLabel());
     }
     $template->setVariable(org_tubepress_api_const_template_Variable::META_SHOULD_SHOW, $shouldShow);
     $template->setVariable(org_tubepress_api_const_template_Variable::META_LABELS, $labels);
     return $template;
 }
Esempio n. 6
0
 public static function assertClassHasConstants($className, array $expected)
 {
     $actual = org_tubepress_impl_util_LangUtils::getDefinedConstants($className);
     TubePressUnitTest::assertArrayEquality($expected, $actual);
 }