public function testBundle()
 {
     $bundle = Yii::$app->getAssetManager()->getBundle(TimePickerAsset::className());
     $this->assertInstanceOf('yii\\jui\\timepicker\\TimePickerAsset', $bundle);
     $this->assertArrayHasKey(0, $bundle->depends);
     $this->assertEquals('yii\\jui\\datepicker\\DatePickerAsset', $bundle->depends[0]);
     $this->assertArrayHasKey(0, $bundle->js);
     $this->assertFileExists($bundle->basePath . DIRECTORY_SEPARATOR . $bundle->js[0]);
     $this->assertArrayHasKey(0, $bundle->css);
     $this->assertFileExists($bundle->basePath . DIRECTORY_SEPARATOR . $bundle->css[0]);
 }
예제 #2
0
 /**
  * @inheritdoc
  */
 public function run()
 {
     $hasModel = $this->hasModel();
     if ($hasModel) {
         if (array_key_exists('value', $this->options)) {
             $value = $this->options['value'];
         } else {
             $value = Html::getAttributeValue($this->model, $this->attribute);
         }
     } else {
         $value = $this->value;
     }
     if (is_int($value) || is_string($value) && strlen($value) || $value instanceof DateTime || $value instanceof DateTimeInterface) {
         $formatter = Yii::$app->getFormatter();
         try {
             $altValue = $formatter->asTime($value, $this->altTimeFormat);
             $value = $formatter->asTime($value, $this->timeFormat);
         } catch (InvalidParamException $e) {
             $altValue = $value;
         }
     } else {
         $altValue = $value;
     }
     if ($hasModel) {
         $this->options = array_merge($this->options, ['name' => false, 'value' => $value]);
         $this->altOptions['value'] = $altValue;
         $output = Html::activeTextInput($this->model, $this->attribute, $this->options);
         $output .= Html::activeHiddenInput($this->model, $this->attribute, $this->altOptions);
     } else {
         $output = Html::textInput(false, $value, $this->options);
         $output .= Html::hiddenInput($this->name, $altValue, $this->altOptions);
     }
     $js = 'jQuery(\'#' . $this->options['id'] . '\').timepicker(' . Json::htmlEncode($this->clientOptions) . ');';
     if (Yii::$app->getRequest()->getIsAjax()) {
         $output .= Html::script($js);
     } else {
         $view = $this->getView();
         TimePickerAsset::register($view);
         TimePickerLanguageAsset::register($view);
         $view->registerJs($js);
     }
     return $output;
 }
 /**
  * @param int $mode
  * @param string $actual
  * @param string $expectedHtml
  * @param string $expectedJs
  */
 protected function checkExpected($mode, $actual, $expectedHtml, $expectedJs)
 {
     switch ($mode) {
         case static::MODE_MODEL_ATTRIBUTE:
         case static::MODE_MODEL_ATTRIBUTE_VALUE:
             $expectedHtml = '<div class="form-group field-testform-datetime">' . "\n" . $expectedHtml . "\n" . '</div>';
         case static::MODE_NAME_VALUE:
             $this->assertEquals($expectedHtml, $actual);
             $view = Yii::$app->getView();
             $this->assertArrayHasKey(TimePickerAsset::className(), $view->assetBundles);
             $this->assertArrayHasKey(TimePickerLanguageAsset::className(), $view->assetBundles);
             $this->assertArrayHasKey(View::POS_READY, $view->js);
             $jsKey = md5($expectedJs);
             $this->assertArrayHasKey($jsKey, $view->js[View::POS_READY]);
             $this->assertEquals($expectedJs, $view->js[View::POS_READY][$jsKey]);
             return;
         case static::MODE_NAME_VALUE_AJAX:
             $expectedHtml .= '<script>' . $expectedJs . '</script>';
             $this->assertEquals($expectedHtml, $actual);
             return;
         case static::MODE_MODEL_ATTRIBUTE_AJAX:
         case static::MODE_MODEL_ATTRIBUTE_VALUE_AJAX:
             $expectedHtml .= '<script>' . $expectedJs . '</script>';
             $expectedHtml = '<div class="form-group field-testform-datetime">' . "\n" . $expectedHtml . "\n" . '</div>';
             $this->assertEquals($expectedHtml, $actual);
             return;
     }
     throw new Exception();
 }