Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
AccountTest.php
1 <?php
2 /**
3  * Created by JetBrains PhpStorm.
4  * User: andrew
5  * Date: 7/16/12
6  * Time: 5:37 PM
7  * To change this template use File | Settings | File Templates.
8  */
9 class AccountTest extends CTestCase
10 {
11 
12  /**
13  * @dataProvider provider
14  */
15  public function testCreate($attributes)
16  {
17  $account = new Account();
18  $account->attributes = $attributes;
19  $this->assertTrue($account->save());
20  }
21 
22  /**
23  * @dataProvider provider
24  * @depends testCreate
25  */
26  public function testFind($attributes)
27  {
28  unset($attributes['data']);
29  $account = Account::model()->findByAttributes($attributes);
30  $this->assertNotNull($account);
31  $this->assertTrue(is_array($account->data));
32  }
33 
34  /**
35  * @dataProvider provider
36  * @depends testCreate
37  */
38  public function testDelete($attributes)
39  {
40  unset($attributes['data']);
41  $this->assertEquals(1, Account::model()->deleteAllByAttributes($attributes));
42  }
43 
44  public function testCreateFromService()
45  {
46  $service_id = '12451gsd';
47  $service = $this->getMock('GoogleService', array('getId', 'fetchAttributes'));
48  $service->expects($this->any())
49  ->method('getId')
50  ->will($this->returnValue($service_id));
51 
52  $account = Account::create($service);
53  $this->assertInstanceOf('Account', $account);
54  $this->assertEquals($service_id, $account->service_id);
55  $this->assertEquals($service->serviceName, $account->service);
56 
57  $account->delete();
58  }
59 
60  public function provider()
61  {
62  return array(
63  array(array(
64  'user_id' => 1,
65  'service' => 'google',
66  'service_id' => 'asd?d3rasd',
67  'data' => array('key' => 'val')
68  )),
69  array(array(
70  'user_id' => 1,
71  'service' => 'yandex',
72  'service_id' => 'asfafsfafasd?d3rasd',
73  'data' => array('key' => 'val')
74  )),
75  array(array(
76  'user_id' => 2,
77  'service' => 'google',
78  'service_id' => 'asd?d3r235235asd',
79  'data' => array('key' => 'val')
80  )),
81  array(array(
82  'service' => 'yandex',
83  'service_id' => 'asfewfqd?d3rasd',
84  'data' => array('key' => 'val')
85  )),
86  );
87  }
88 
89 }