forked from opencfp/opencfp
/
TalkTest.php
79 lines (70 loc) · 2.19 KB
/
TalkTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
use OpenCFP\Application;
use OpenCFP\Environment;
class TalkEntityTest extends \PHPUnit_Framework_TestCase
{
public $app;
public $mapper;
protected function setup()
{
$this->app = new Application(BASE_PATH, Environment::testing());
// Create an in-memory database
$cfg = new \Spot\Config;
$cfg->addConnection('sqlite', [
'dbname' => 'sqlite::memory',
'driver' => 'pdo_sqlite'
]);
$this->app['spot'] = new \Spot\Locator($cfg);
$this->mapper = $this->app['spot']->mapper('OpenCFP\Domain\Entity\Talk');
$this->mapper->migrate();
}
/**
* @test
*/
public function utf8CharactersCorrectlyEncoded()
{
$title = "Battle: Feature Branches VS Feature Switching (╯°□°)╯︵ ┻━┻ ︵ ╯(°□° ╯)";
$data = array(
'title' => $title,
'description' => 'Talk with UTF-8 characters in the title',
'user_id' => 1
);
$talk = $this->mapper->create($data);
$this->assertEquals(
$title,
$talk->title,
'UTF-8 characters were incorrectly encoded'
);
}
/**
* @test
*/
public function getRecentFindsMostRecentTalks()
{
// Create a favorites table, can be empty
$favorite_mapper = $this->app['spot']->mapper('OpenCFP\Domain\Entity\Favorite');
$favorite_mapper->migrate();
// Create users entity
$user_mapper = $this->app['spot']->mapper('OpenCFP\Domain\Entity\User');
$user_mapper->migrate();
// Create 11 talks
$this->bulkCreateTalks(11);
$recent_talks = $this->mapper->getRecent(1);
$this->assertTrue(
count($recent_talks) == 10,
"Talk::getRecent() did not grab 10 talks out of 11"
);
}
private function bulkCreateTalks($numTalks)
{
for ($x = 1; $x <= $numTalks; $x++) {
$title = uniqid();
$data = [
'title' => $title,
'description' => "Description for $title",
'user_id' => 1
];
$this->mapper->create($data);
}
}
}