/** * @param string $language * @dataProvider languageDataProvider */ public function testBundleHasFile($language) { Yii::$app->language = $language; $bundle = Yii::$app->getAssetManager()->getBundle(DatePickerLanguageFixAsset::className()); $this->assertInstanceOf('yii\\jui\\datepicker\\DatePickerLanguageFixAsset', $bundle); $this->assertArrayHasKey(0, $bundle->depends); $this->assertEquals('yii\\jui\\datepicker\\DatePickerLanguageAsset', $bundle->depends[0]); $this->assertArrayHasKey(0, $bundle->js); $this->assertFileExists($bundle->basePath . DIRECTORY_SEPARATOR . $bundle->js[0]); }
/** * @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-date">' . "\n" . $expectedHtml . "\n" . '</div>'; case static::MODE_NAME_VALUE: $this->assertEquals($expectedHtml, $actual); $view = Yii::$app->getView(); $this->assertArrayHasKey(DatePickerAsset::className(), $view->assetBundles); $this->assertArrayHasKey(DatePickerLanguageAsset::className(), $view->assetBundles); $this->assertArrayHasKey(DatePickerLanguageFixAsset::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-date">' . "\n" . $expectedHtml . "\n" . '</div>'; $this->assertEquals($expectedHtml, $actual); return; } throw new Exception(); }
/** * @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->asDate($value, $this->altDateFormat); $value = $formatter->asDate($value, $this->dateFormat); } 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'] . '\').datepicker(' . Json::htmlEncode($this->clientOptions) . ');'; if (Yii::$app->getRequest()->getIsAjax()) { $output .= Html::script($js); } else { $view = $this->getView(); DatePickerAsset::register($view); DatePickerLanguageAsset::register($view); DatePickerLanguageFixAsset::register($view); $view->registerJs($js); } return $output; }