SessionTest.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. namespace Transmission\Tests\Model;
  3. use Transmission\Model\Session;
  4. use Transmission\Util\PropertyMapper;
  5. use Symfony\Component\PropertyAccess\PropertyAccess;
  6. class SessionTest extends \PHPUnit_Framework_TestCase
  7. {
  8. protected $session;
  9. /**
  10. * @test
  11. */
  12. public function shouldImplementModelInterface()
  13. {
  14. $this->assertInstanceOf('Transmission\Model\ModelInterface', $this->getSession());
  15. }
  16. /**
  17. * @test
  18. */
  19. public function shouldHaveNonEmptyMapping()
  20. {
  21. $this->assertNotEmpty($this->getSession()->getMapping());
  22. }
  23. /**
  24. * @test
  25. */
  26. public function shouldBeCreatedFromMapping()
  27. {
  28. $source = (object) array(
  29. 'alt-speed-down' => 1,
  30. 'alt-speed-enabled' => true,
  31. 'download-dir' => 'foo',
  32. 'download-queue-enabled' => true,
  33. 'download-queue-size' => 5,
  34. 'incomplete-dir' => 'bar',
  35. 'incomplete-dir-enabled' => true,
  36. 'script-torrent-done-filename' => 'baz',
  37. 'script-torrent-done-enabled' => true,
  38. 'seedRatioLimit' => 3.14,
  39. 'seedRatioLimited' => true,
  40. 'seed-queue-size' => 5,
  41. 'seed-queue-enabled' => true,
  42. 'speed-limit-down' => 100,
  43. 'speed-limit-down-enabled' => true,
  44. );
  45. PropertyMapper::map($this->getSession(), $source);
  46. $this->assertEquals(1, $this->getSession()->getAltSpeedDown());
  47. $this->assertTrue($this->getSession()->isAltSpeedEnabled());
  48. $this->assertEquals('foo', $this->getSession()->getDownloadDir());
  49. $this->assertEquals(5, $this->getSession()->getDownloadQueueSize());
  50. $this->assertTrue($this->getSession()->isDownloadQueueEnabled());
  51. $this->assertEquals('bar', $this->getSession()->getIncompleteDir());
  52. $this->assertTrue($this->getSession()->isIncompleteDirEnabled());
  53. $this->assertEquals('baz', $this->getSession()->getTorrentDoneScript());
  54. $this->assertTrue($this->getSession()->isTorrentDoneScriptEnabled());
  55. $this->assertEquals(3.14, $this->getSession()->getSeedRatioLimit());
  56. $this->assertTrue($this->getSession()->isSeedRatioLimited());
  57. $this->assertEquals(5, $this->getSession()->getSeedQueueSize());
  58. $this->assertTrue($this->getSession()->isSeedQueueEnabled());
  59. $this->assertEquals(100, $this->getSession()->getDownloadSpeedLimit());
  60. $this->assertTrue($this->getSession()->isDownloadSpeedLimitEnabled());
  61. }
  62. /**
  63. * @test
  64. */
  65. public function shouldSave()
  66. {
  67. $expected = array(
  68. 'alt-speed-down' => 1,
  69. 'alt-speed-enabled' => true,
  70. 'download-dir' => 'foo',
  71. 'download-queue-enabled' => true,
  72. 'download-queue-size' => 5,
  73. 'incomplete-dir' => 'bar',
  74. 'incomplete-dir-enabled' => true,
  75. 'script-torrent-done-filename' => 'baz',
  76. 'script-torrent-done-enabled' => true,
  77. 'seedRatioLimit' => 3.14,
  78. 'seedRatioLimited' => true,
  79. 'seed-queue-size' => 5,
  80. 'seed-queue-enabled' => true,
  81. 'speed-limit-down' => 100,
  82. 'speed-limit-down-enabled' => true
  83. );
  84. PropertyMapper::map($this->getSession(), (object) $expected);
  85. $client = $this->getMock('Transmission\Client');
  86. $client->expects($this->once())
  87. ->method('call')
  88. ->with('session-set', $expected)
  89. ->will($this->returnCallback(function () {
  90. return (object) array(
  91. 'result' => 'success',
  92. );
  93. }));
  94. $this->getSession()->setClient($client);
  95. $this->getSession()->save();
  96. }
  97. /**
  98. * @test
  99. */
  100. public function shouldNotSaveWithNoClient()
  101. {
  102. $this->getSession()->save();
  103. }
  104. public function setup()
  105. {
  106. $this->session = new Session();
  107. }
  108. protected function getSession()
  109. {
  110. return $this->session;
  111. }
  112. }