From 17e73b3a338ac91e3ec16206314f641bdf5507d2 Mon Sep 17 00:00:00 2001
From: Mantas <marc.mantas@gmail.com>
Date: Tue, 12 Jul 2016 16:24:28 +0300
Subject: [PATCH] added template query test

---
 tests/Query/TemplateQueryTest.php | 67 +++++++++++++++++++++++++++++++
 1 file changed, 67 insertions(+)
 create mode 100644 tests/Query/TemplateQueryTest.php

diff --git a/tests/Query/TemplateQueryTest.php b/tests/Query/TemplateQueryTest.php
new file mode 100644
index 0000000..1926562
--- /dev/null
+++ b/tests/Query/TemplateQueryTest.php
@@ -0,0 +1,67 @@
+<?php
+
+/*
+ * This file is part of the ONGR package.
+ *
+ * (c) NFQ Technologies UAB <info@nfq.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace ONGR\ElasticsearchDSL\Tests\Query;
+
+use ONGR\ElasticsearchDSL\Query\TemplateQuery;
+
+/**
+ * Unit test for Template.
+ */
+class TemplateQueryTest extends \PHPUnit_Framework_TestCase
+{
+    /**
+     * Tests toArray() method with inline.
+     */
+    public function testToArrayInline()
+    {
+        $inline = '"term": {"field": "{{query_string}}"}';
+        $params = ['query_string' => 'all about search'];
+        $query = new TemplateQuery(null, $inline, $params);
+        $expected = [
+            'template' => [
+                'inline' => $inline,
+                'params' => $params
+            ],
+        ];
+        $this->assertEquals($expected, $query->toArray());
+    }
+
+    /**
+     * Tests toArray() method with file
+     */
+    public function testToArrayFile()
+    {
+        $file = 'my_template';
+        $params = ['query_string' => 'all about search'];
+        $query = new TemplateQuery();
+        $query->setFile($file);
+        $query->setParams($params);
+        $expected = [
+            'template' => [
+                'file' => $file,
+                'params' => $params,
+            ],
+        ];
+        $this->assertEquals($expected, $query->toArray());
+    }
+
+    /**
+     * Tests toArray() exception
+     *
+     * @expectedException \InvalidArgumentException
+     */
+    public function testToArrayException()
+    {
+        $query = new TemplateQuery();
+        $query->toArray();
+    }
+}
-- 
GitLab