From a806e77cb611342c1b5ccd266c9efa79ab2974b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Thu, 3 Oct 2019 07:14:03 +0200 Subject: [PATCH] Implement our own initialStateService for 15 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- lib/Controller/PageController.php | 15 ++++++++------- templates/main.php | 5 ++++- tests/unit/Controller/PageControllerTest.php | 10 +++++----- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 4f4c722e7..eebfccf8f 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -25,7 +25,7 @@ use OCP\AppFramework\Controller; use OCP\AppFramework\Http\TemplateResponse; -use OCP\IInitialStateService; +// use OCP\IInitialStateService; use OCP\L10N\IFactory; use OCP\IRequest; @@ -33,20 +33,20 @@ class PageController extends Controller { protected $appName; - /** @var IInitialStateService */ - private $initialStateService; + // /** @var IInitialStateService */ + // private $initialStateService; /** @var IFactory */ private $languageFactory; public function __construct(string $AppName, IRequest $request, - IInitialStateService $initialStateService, + // IInitialStateService $initialStateService, IFactory $languageFactory) { parent::__construct($AppName, $request); $this->appName = $AppName; - $this->initialStateService = $initialStateService; + // $this->initialStateService = $initialStateService; $this->languageFactory = $languageFactory; } @@ -58,7 +58,8 @@ public function __construct(string $AppName, */ public function index(): TemplateResponse { $locales = $this->languageFactory->findAvailableLocales(); - $this->initialStateService->provideInitialState($this->appName, 'locales', $locales); - return new TemplateResponse('contacts', 'main'); // templates/main.php + // TODO: use initialStateService once min-version is 16! + // $this->initialStateService->provideInitialState($this->appName, 'locales', $locales); + return new TemplateResponse('contacts', 'main', ['locales' => json_encode($locales)]); // templates/main.php } } diff --git a/templates/main.php b/templates/main.php index 9fa58fc69..365cf629f 100644 --- a/templates/main.php +++ b/templates/main.php @@ -2,8 +2,11 @@ if (!\OCP\Util::isIe()) { script('contacts', 'contacts'); style('contacts', 'contacts'); -} else { ?> + + + +
diff --git a/tests/unit/Controller/PageControllerTest.php b/tests/unit/Controller/PageControllerTest.php index f23ef441c..6090af176 100644 --- a/tests/unit/Controller/PageControllerTest.php +++ b/tests/unit/Controller/PageControllerTest.php @@ -25,7 +25,7 @@ use OCP\AppFramework\Http\TemplateResponse; use PHPUnit\Framework\MockObject\MockObject; -use OCP\IInitialStateService; +// use OCP\IInitialStateService; use OCP\IRequest; use OCP\L10N\IFactory; use ChristophWurst\Nextcloud\Testing\TestCase; @@ -38,8 +38,8 @@ class PageControllerTest extends TestCase { /** @var IRequest|MockObject */ private $request; - /** @var IInitialStateService|MockObject */ - private $initialStateService; + // /** @var IInitialStateService|MockObject */ + // private $initialStateService; /** @var IFactory|MockObject */ private $languageFactory; @@ -48,13 +48,13 @@ public function setUp() { parent::setUp(); $this->request = $this->createMock(IRequest::class); - $this->initialStateService = $this->createMock(IInitialStateService::class); + // $this->initialStateService = $this->createMock(IInitialStateService::class); $this->languageFactory = $this->createMock(IFactory::class); $this->controller = new PageController( 'contacts', $this->request, - $this->initialStateService, + // $this->initialStateService, $this->languageFactory ); }