server/src/tests/Controllers/DiscourseControllerTest.php
author ymh <ymh.work@gmail.com>
Mon, 12 Jun 2017 14:53:59 +0200
changeset 537 d2e6ee099125
parent 407 2dba812c7ef2
permissions -rw-r--r--
upgrade ember + laravel + make everything work
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
160
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
use Mockery as m;
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
/**
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 *
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 */
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
class DiscourseControllerTest extends TestCase {
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
407
2dba812c7ef2 add a way to build rpm for puppet files, correct elasticsearch provisioning, correct error on elasticsearch queries + tests
ymh <ymh.work@gmail.com>
parents: 377
diff changeset
    10
    private $ES_QUERY;
2dba812c7ef2 add a way to build rpm for puppet files, correct elasticsearch provisioning, correct error on elasticsearch queries + tests
ymh <ymh.work@gmail.com>
parents: 377
diff changeset
    11
2dba812c7ef2 add a way to build rpm for puppet files, correct elasticsearch provisioning, correct error on elasticsearch queries + tests
ymh <ymh.work@gmail.com>
parents: 377
diff changeset
    12
    public function setUp() {
2dba812c7ef2 add a way to build rpm for puppet files, correct elasticsearch provisioning, correct error on elasticsearch queries + tests
ymh <ymh.work@gmail.com>
parents: 377
diff changeset
    13
        $this->ES_QUERY = [
2dba812c7ef2 add a way to build rpm for puppet files, correct elasticsearch provisioning, correct error on elasticsearch queries + tests
ymh <ymh.work@gmail.com>
parents: 377
diff changeset
    14
            'index' => 'corpus',
2dba812c7ef2 add a way to build rpm for puppet files, correct elasticsearch provisioning, correct error on elasticsearch queries + tests
ymh <ymh.work@gmail.com>
parents: 377
diff changeset
    15
            'body' => [
2dba812c7ef2 add a way to build rpm for puppet files, correct elasticsearch provisioning, correct error on elasticsearch queries + tests
ymh <ymh.work@gmail.com>
parents: 377
diff changeset
    16
                "size" => 0,
2dba812c7ef2 add a way to build rpm for puppet files, correct elasticsearch provisioning, correct error on elasticsearch queries + tests
ymh <ymh.work@gmail.com>
parents: 377
diff changeset
    17
                "query" => [ "match_all" => (object) null ],
2dba812c7ef2 add a way to build rpm for puppet files, correct elasticsearch provisioning, correct error on elasticsearch queries + tests
ymh <ymh.work@gmail.com>
parents: 377
diff changeset
    18
                "aggs" => [
2dba812c7ef2 add a way to build rpm for puppet files, correct elasticsearch provisioning, correct error on elasticsearch queries + tests
ymh <ymh.work@gmail.com>
parents: 377
diff changeset
    19
                    "discourses" => [
2dba812c7ef2 add a way to build rpm for puppet files, correct elasticsearch provisioning, correct error on elasticsearch queries + tests
ymh <ymh.work@gmail.com>
parents: 377
diff changeset
    20
                        "terms" => [ "field" => "discourse_types", "order" => [ "_count" => "desc" ], "size" => 2147483647 ]
2dba812c7ef2 add a way to build rpm for puppet files, correct elasticsearch provisioning, correct error on elasticsearch queries + tests
ymh <ymh.work@gmail.com>
parents: 377
diff changeset
    21
                    ]
377
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    22
                ]
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    23
            ]
407
2dba812c7ef2 add a way to build rpm for puppet files, correct elasticsearch provisioning, correct error on elasticsearch queries + tests
ymh <ymh.work@gmail.com>
parents: 377
diff changeset
    24
        ];
160
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
        parent::setup();
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
    }
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
    public function tearDown() {
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
        m::close();
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
        parent::tearDown();
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
    }
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
    public function testIndex() {
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
377
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    36
        Es::shouldReceive('search')
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    37
                ->once()
407
2dba812c7ef2 add a way to build rpm for puppet files, correct elasticsearch provisioning, correct error on elasticsearch queries + tests
ymh <ymh.work@gmail.com>
parents: 377
diff changeset
    38
                ->with($this->ES_QUERY)
377
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    39
                ->andReturn(json_decode('{
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    40
  "took" : 116,
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    41
  "timed_out" : false,
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    42
  "_shards" : {
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    43
    "total" : 1,
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    44
    "successful" : 1,
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    45
    "failed" : 0
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    46
  },
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    47
  "hits" : {
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    48
    "total" : 3373,
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    49
    "max_score" : 0.0,
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    50
    "hits" : [ ]
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    51
  },
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    52
  "aggregations" : {
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    53
    "discourses" : {
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    54
      "doc_count_error_upper_bound" : 0,
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    55
      "sum_other_doc_count" : 0,
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    56
      "buckets" : [ {
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    57
        "key" : "http://ark.bnf.fr/ark:/12148/cb12083158d",
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    58
        "doc_count" : 44
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    59
      }, {
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    60
        "key" : "http://ark.bnf.fr/ark:/12148/cb119783362",
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    61
        "doc_count" : 33
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    62
      }, {
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    63
        "key" : "http://ark.bnf.fr/ark:/12148/cb13319048g",
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    64
        "doc_count" : 22
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    65
      } ]
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    66
    }
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    67
  }
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    68
}', true));
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    69
537
d2e6ee099125 upgrade ember + laravel + make everything work
ymh <ymh.work@gmail.com>
parents: 407
diff changeset
    70
        $response = $this->get('/api/v1/stats/discourses/');
377
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    71
537
d2e6ee099125 upgrade ember + laravel + make everything work
ymh <ymh.work@gmail.com>
parents: 407
diff changeset
    72
        $response
d2e6ee099125 upgrade ember + laravel + make everything work
ymh <ymh.work@gmail.com>
parents: 407
diff changeset
    73
            ->assertStatus(200)
d2e6ee099125 upgrade ember + laravel + make everything work
ymh <ymh.work@gmail.com>
parents: 407
diff changeset
    74
            ->assertJson(["discourses" => [
160
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
            "http://ark.bnf.fr/ark:/12148/cb12083158d" => ["label" => "argumentation", "count" => 44],
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
            "http://ark.bnf.fr/ark:/12148/cb119783362" => ["label" => "bavardage", "count" => 33],
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
            "http://ark.bnf.fr/ark:/12148/cb13319048g" => ["label" => "chansons", "count" => 22],
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
        ]]);
377
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    79
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    80
    }
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    81
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    82
    public function testIndexQuery() {
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    83
        Es::shouldReceive('search')
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    84
                ->once()
407
2dba812c7ef2 add a way to build rpm for puppet files, correct elasticsearch provisioning, correct error on elasticsearch queries + tests
ymh <ymh.work@gmail.com>
parents: 377
diff changeset
    85
                ->with($this->ES_QUERY)
377
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    86
                ->andReturn(json_decode('{
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    87
  "took" : 116,
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    88
  "timed_out" : false,
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    89
  "_shards" : {
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    90
    "total" : 1,
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    91
    "successful" : 1,
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    92
    "failed" : 0
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    93
  },
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    94
  "hits" : {
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    95
    "total" : 3373,
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    96
    "max_score" : 0.0,
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    97
    "hits" : [ ]
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    98
  },
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    99
  "aggregations" : {
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
   100
    "discourses" : {
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
   101
      "doc_count_error_upper_bound" : 0,
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
   102
      "sum_other_doc_count" : 0,
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
   103
      "buckets" : [ ]
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
   104
    }
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
   105
  }
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
   106
}', true));
537
d2e6ee099125 upgrade ember + laravel + make everything work
ymh <ymh.work@gmail.com>
parents: 407
diff changeset
   107
        $response = $this->get('/api/v1/stats/discourses/');
d2e6ee099125 upgrade ember + laravel + make everything work
ymh <ymh.work@gmail.com>
parents: 407
diff changeset
   108
        $response
d2e6ee099125 upgrade ember + laravel + make everything work
ymh <ymh.work@gmail.com>
parents: 407
diff changeset
   109
            ->assertStatus(200)
d2e6ee099125 upgrade ember + laravel + make everything work
ymh <ymh.work@gmail.com>
parents: 407
diff changeset
   110
            ->assertJson(["discourses" => [
377
52169c718513 make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
   111
        ]]);
160
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
    }
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
}